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