1 from __future__ import unicode_literals
6 from .common import InfoExtractor
8 compat_urllib_parse_unquote,
22 class MixcloudIE(InfoExtractor):
23 _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/([^/]+)/(?!stream|uploads|favorites|listens|playlists)([^/]+)'
27 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
29 'id': 'dholbach-cryptkeeper',
31 'title': 'Cryptkeeper',
32 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
33 'uploader': 'Daniel Holbach',
34 'uploader_id': 'dholbach',
35 'thumbnail': 're:https?://.*\.jpg',
40 'url': 'http://www.mixcloud.com/gillespeterson/caribou-7-inch-vinyl-mix-chat/',
42 'id': 'gillespeterson-caribou-7-inch-vinyl-mix-chat',
44 'title': 'Caribou 7 inch Vinyl Mix & Chat',
45 'description': 'md5:2b8aec6adce69f9d41724647c65875e8',
46 'uploader': 'Gilles Peterson Worldwide',
47 'uploader_id': 'gillespeterson',
48 'thumbnail': 're:https?://.*/images/',
54 def _check_url(self, url, track_id, ext):
56 # We only want to know if the request succeed
57 # don't download the whole file
58 self._request_webpage(
59 HEADRequest(url), track_id,
60 'Trying %s URL' % ext)
62 except ExtractorError:
65 def _real_extract(self, url):
66 mobj = re.match(self._VALID_URL, url)
67 uploader = mobj.group(1)
68 cloudcast_name = mobj.group(2)
69 track_id = compat_urllib_parse_unquote('-'.join((uploader, cloudcast_name)))
71 webpage = self._download_webpage(url, track_id)
73 message = self._html_search_regex(
74 r'(?s)<div[^>]+class="global-message cloudcast-disabled-notice-light"[^>]*>(.+?)<(?:a|/div)',
75 webpage, 'error message', default=None)
77 preview_url = self._search_regex(
78 r'\s(?:data-preview-url|m-preview)="([^"]+)"',
79 webpage, 'preview url', default=None if message else NO_DEFAULT)
82 raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
84 song_url = re.sub(r'audiocdn(\d+)', r'stream\1', preview_url)
85 song_url = song_url.replace('/previews/', '/c/originals/')
86 if not self._check_url(song_url, track_id, 'mp3'):
87 song_url = song_url.replace('.mp3', '.m4a').replace('originals/', 'm4a/64/')
88 if not self._check_url(song_url, track_id, 'm4a'):
89 raise ExtractorError('Unable to extract track url')
92 r'm-play-on-spacebar[^>]+'
93 r'(?:\s+[a-zA-Z0-9-]+(?:="[^"]+")?)*?\s+')
94 title = self._html_search_regex(
95 PREFIX + r'm-title="([^"]+)"', webpage, 'title')
96 thumbnail = self._proto_relative_url(self._html_search_regex(
97 PREFIX + r'm-thumbnail-url="([^"]+)"', webpage, 'thumbnail',
99 uploader = self._html_search_regex(
100 PREFIX + r'm-owner-name="([^"]+)"',
101 webpage, 'uploader', fatal=False)
102 uploader_id = self._search_regex(
103 r'\s+"profile": "([^"]+)",', webpage, 'uploader id', fatal=False)
104 description = self._og_search_description(webpage)
105 like_count = parse_count(self._search_regex(
106 r'\bbutton-favorite[^>]+>.*?<span[^>]+class=["\']toggle-number[^>]+>\s*([^<]+)',
107 webpage, 'like count', fatal=False))
108 view_count = str_to_int(self._search_regex(
109 [r'<meta itemprop="interactionCount" content="UserPlays:([0-9]+)"',
110 r'/listeners/?">([0-9,.]+)</a>'],
111 webpage, 'play count', fatal=False))
117 'description': description,
118 'thumbnail': thumbnail,
119 'uploader': uploader,
120 'uploader_id': uploader_id,
121 'view_count': view_count,
122 'like_count': like_count,
126 class MixcloudPlaylistBaseIE(InfoExtractor):
129 def _fetch_tracks_page(self, path, video_id, page_name, current_page):
130 resp = self._download_webpage(
131 'https://www.mixcloud.com/%s/' % path, video_id,
132 note='Download %s (page %d)' % (page_name, current_page + 1),
133 errnote='Unable to download %s' % page_name,
134 query={'page': (current_page + 1), 'list': 'main', '_ajax': '1'},
135 headers={'X-Requested-With': 'XMLHttpRequest'})
137 for url in re.findall(r'm-play-button m-url="(?P<url>[^"]+)"', resp):
138 yield self.url_result(
139 compat_urlparse.urljoin('https://www.mixcloud.com', clean_html(url)),
142 def _get_user_description(self, page_content):
143 return self._html_search_regex(
144 r'<div[^>]+class="description-text"[^>]*>(.+?)</div>',
145 page_content, 'user description', fatal=False)
148 class MixcloudUserIE(MixcloudPlaylistBaseIE):
149 _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/(?P<user>[^/]+)/(?P<type>uploads|favorites|listens)?/?$'
150 IE_NAME = 'mixcloud:user'
153 'url': 'http://www.mixcloud.com/dholbach/',
155 'id': 'dholbach_uploads',
156 'title': 'Daniel Holbach (uploads)',
157 'description': 'md5:327af72d1efeb404a8216c27240d1370',
159 'playlist_mincount': 11,
161 'url': 'http://www.mixcloud.com/dholbach/uploads/',
163 'id': 'dholbach_uploads',
164 'title': 'Daniel Holbach (uploads)',
165 'description': 'md5:327af72d1efeb404a8216c27240d1370',
167 'playlist_mincount': 11,
169 'url': 'http://www.mixcloud.com/dholbach/favorites/',
171 'id': 'dholbach_favorites',
172 'title': 'Daniel Holbach (favorites)',
173 'description': 'md5:327af72d1efeb404a8216c27240d1370',
176 'playlist_items': '1-100',
178 'playlist_mincount': 100,
180 'url': 'http://www.mixcloud.com/dholbach/listens/',
182 'id': 'dholbach_listens',
183 'title': 'Daniel Holbach (listens)',
184 'description': 'md5:327af72d1efeb404a8216c27240d1370',
187 'playlist_items': '1-100',
189 'playlist_mincount': 100,
192 def _real_extract(self, url):
193 mobj = re.match(self._VALID_URL, url)
194 user_id = mobj.group('user')
195 list_type = mobj.group('type')
197 # if only a profile URL was supplied, default to download all uploads
198 if list_type is None:
199 list_type = 'uploads'
201 video_id = '%s_%s' % (user_id, list_type)
203 profile = self._download_webpage(
204 'https://www.mixcloud.com/%s/' % user_id, video_id,
205 note='Downloading user profile',
206 errnote='Unable to download user profile')
208 username = self._og_search_title(profile)
209 description = self._get_user_description(profile)
211 entries = OnDemandPagedList(
213 self._fetch_tracks_page,
214 '%s/%s' % (user_id, list_type), video_id, 'list of %s' % list_type),
215 self._PAGE_SIZE, use_cache=True)
217 return self.playlist_result(
218 entries, video_id, '%s (%s)' % (username, list_type), description)
221 class MixcloudPlaylistIE(MixcloudPlaylistBaseIE):
222 _VALID_URL = r'^(?:https?://)?(?:www\.)?mixcloud\.com/(?P<user>[^/]+)/playlists/(?P<playlist>[^/]+)/?$'
223 IE_NAME = 'mixcloud:playlist'
226 'url': 'https://www.mixcloud.com/RedBullThre3style/playlists/tokyo-finalists-2015/',
228 'id': 'RedBullThre3style_tokyo-finalists-2015',
229 'title': 'National Champions 2015',
230 'description': 'md5:6ff5fb01ac76a31abc9b3939c16243a3',
232 'playlist_mincount': 16,
234 'url': 'https://www.mixcloud.com/maxvibes/playlists/jazzcat-on-ness-radio/',
236 'id': 'maxvibes_jazzcat-on-ness-radio',
237 'title': 'Jazzcat on Ness Radio',
238 'description': 'md5:7bbbf0d6359a0b8cda85224be0f8f263',
240 'playlist_mincount': 23
243 def _real_extract(self, url):
244 mobj = re.match(self._VALID_URL, url)
245 user_id = mobj.group('user')
246 playlist_id = mobj.group('playlist')
247 video_id = '%s_%s' % (user_id, playlist_id)
249 profile = self._download_webpage(
251 note='Downloading playlist page',
252 errnote='Unable to download playlist page')
254 description = self._get_user_description(profile)
255 playlist_title = self._html_search_regex(
256 r'<span[^>]+class="[^"]*list-playlist-title[^"]*"[^>]*>(.*?)</span>',
257 profile, 'playlist title')
259 entries = OnDemandPagedList(
261 self._fetch_tracks_page,
262 '%s/playlists/%s' % (user_id, playlist_id), video_id, 'tracklist'),
265 return self.playlist_result(entries, video_id, playlist_title, description)