1 from __future__ import unicode_literals
5 from .common import InfoExtractor
18 class MixcloudIE(InfoExtractor):
19 _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/([^/]+)/([^/]+)'
23 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
25 'id': 'dholbach-cryptkeeper',
27 'title': 'Cryptkeeper',
28 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
29 'uploader': 'Daniel Holbach',
30 'uploader_id': 'dholbach',
31 'upload_date': '20111115',
32 'timestamp': 1321359578,
33 'thumbnail': 're:https?://.*\.jpg',
39 def _get_url(self, track_id, template_url):
41 for i in range(server_count):
42 url = template_url % i
44 # We only want to know if the request succeed
45 # don't download the whole file
46 self._request_webpage(
47 HEADRequest(url), track_id,
48 'Checking URL %d/%d ...' % (i + 1, server_count + 1))
50 except ExtractorError:
55 def _real_extract(self, url):
56 mobj = re.match(self._VALID_URL, url)
57 uploader = mobj.group(1)
58 cloudcast_name = mobj.group(2)
59 track_id = compat_urllib_parse.unquote('-'.join((uploader, cloudcast_name)))
61 webpage = self._download_webpage(url, track_id)
63 preview_url = self._search_regex(
64 r'\s(?:data-preview-url|m-preview)="(.+?)"', webpage, 'preview url')
65 song_url = preview_url.replace('/previews/', '/c/originals/')
66 template_url = re.sub(r'(stream\d*)', 'stream%d', song_url)
67 final_song_url = self._get_url(track_id, template_url)
68 if final_song_url is None:
69 self.to_screen('Trying with m4a extension')
70 template_url = template_url.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
71 final_song_url = self._get_url(track_id, template_url)
72 if final_song_url is None:
73 raise ExtractorError('Unable to extract track url')
76 r'<span class="play-button[^"]*?"'
77 r'(?:\s+[a-zA-Z0-9-]+(?:="[^"]+")?)*?\s+')
78 title = self._html_search_regex(
79 PREFIX + r'm-title="([^"]+)"', webpage, 'title')
80 thumbnail = self._proto_relative_url(self._html_search_regex(
81 PREFIX + r'm-thumbnail-url="([^"]+)"', webpage, 'thumbnail',
83 uploader = self._html_search_regex(
84 PREFIX + r'm-owner-name="([^"]+)"',
85 webpage, 'uploader', fatal=False)
86 uploader_id = self._search_regex(
87 r'\s+"profile": "([^"]+)",', webpage, 'uploader id', fatal=False)
88 description = self._og_search_description(webpage)
89 like_count = str_to_int(self._search_regex(
90 [r'<meta itemprop="interactionCount" content="UserLikes:([0-9]+)"',
91 r'/favorites/?">([0-9]+)<'],
92 webpage, 'like count', fatal=False))
93 view_count = str_to_int(self._search_regex(
94 [r'<meta itemprop="interactionCount" content="UserPlays:([0-9]+)"',
95 r'/listeners/?">([0-9,.]+)</a>'],
96 webpage, 'play count', fatal=False))
97 timestamp = parse_iso8601(self._search_regex(
98 r'<time itemprop="dateCreated" datetime="([^"]+)">',
99 webpage, 'upload date', default=None))
104 'url': final_song_url,
105 'description': description,
106 'thumbnail': thumbnail,
107 'uploader': uploader,
108 'uploader_id': uploader_id,
109 'timestamp': timestamp,
110 'view_count': view_count,
111 'like_count': like_count,