3 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
19 class MixcloudBaseIE(InfoExtractor
):
20 def _call_api(self
, object_type
, object_fields
, display_id
, username
, slug
=None):
21 lookup_key
= object_type
+ 'Lookup'
22 return self
._download
_json
(
23 'https://app.mixcloud.com/graphql', display_id
, query
={
25 %s(lookup: {username: "%s"%s}) {
28 }''' % (lookup_key
, username
, ', slug: "%s"' % slug
if slug
else '', object_fields
)
29 })['data'][lookup_key
]
32 class MixcloudIE(MixcloudBaseIE
):
33 _VALID_URL
= r
'https?://(?:(?:www|beta|m)\.)?mixcloud\.com/([^/]+)/(?!stream|uploads|favorites|listens|playlists)([^/]+)'
37 'url': 'http://www.mixcloud.com/dholbach/cryptkeeper/',
39 'id': 'dholbach_cryptkeeper',
41 'title': 'Cryptkeeper',
42 'description': 'After quite a long silence from myself, finally another Drum\'n\'Bass mix with my favourite current dance floor bangers.',
43 'uploader': 'Daniel Holbach',
44 'uploader_id': 'dholbach',
45 'thumbnail': r
're:https?://.*\.jpg',
47 'timestamp': 1321359578,
48 'upload_date': '20111115',
49 'uploader_url': 'https://www.mixcloud.com/dholbach/',
50 'artist': 'Submorphics & Chino , Telekinesis, Porter Robinson, Enei, Breakage ft Jess Mills',
57 'params': {'skip_download': 'm3u8'}
,
59 'url': 'http://www.mixcloud.com/gillespeterson/caribou-7-inch-vinyl-mix-chat/',
61 'id': 'gillespeterson_caribou-7-inch-vinyl-mix-chat',
63 'title': 'Caribou 7 inch Vinyl Mix & Chat',
64 'description': 'md5:2b8aec6adce69f9d41724647c65875e8',
65 'uploader': 'Gilles Peterson Worldwide',
66 'uploader_id': 'gillespeterson',
67 'thumbnail': 're:https?://.*',
69 'timestamp': 1422987057,
70 'upload_date': '20150203',
71 'uploader_url': 'https://www.mixcloud.com/gillespeterson/',
78 'params': {'skip_download': '404 playback error on site'}
,
80 'url': 'https://beta.mixcloud.com/RedLightRadio/nosedrip-15-red-light-radio-01-18-2016/',
81 'only_matching': True,
83 _DECRYPTION_KEY
= 'IFYOUWANTTHEARTISTSTOGETPAIDDONOTDOWNLOADFROMMIXCLOUD'
86 def _decrypt_xor_cipher(key
, ciphertext
):
87 """Encrypt/Decrypt XOR cipher. Both ways are possible because it's XOR."""
89 chr(compat_ord(ch
) ^
compat_ord(k
))
90 for ch
, k
in zip(ciphertext
, itertools
.cycle(key
))])
92 def _real_extract(self
, url
):
93 username
, slug
= self
._match
_valid
_url
(url
).groups()
94 username
, slug
= compat_urllib_parse_unquote(username
), compat_urllib_parse_unquote(slug
)
95 track_id
= '%s_%s' % (username
, slug
)
97 cloudcast
= self
._call
_api
('cloudcast', '''audioLength
98 comments(first: 100) {
123 picture(width: 1024, height: 1024) {
142 id''', track_id
, username
, slug
)
145 raise ExtractorError('Track not found', expected
=True)
147 reason
= cloudcast
.get('restrictedReason')
148 if reason
== 'tracklist':
149 raise ExtractorError('Track unavailable in your country due to licensing restrictions', expected
=True)
150 elif reason
== 'repeat_play':
151 raise ExtractorError('You have reached your play limit for this track', expected
=True)
153 raise ExtractorError('Track is restricted', expected
=True)
155 title
= cloudcast
['name']
157 stream_info
= cloudcast
['streamInfo']
160 for url_key
in ('url', 'hlsUrl', 'dashUrl'):
161 format_url
= stream_info
.get(url_key
)
164 decrypted
= self
._decrypt
_xor
_cipher
(
165 self
._DECRYPTION
_KEY
, compat_b64decode(format_url
))
166 if url_key
== 'hlsUrl':
167 formats
.extend(self
._extract
_m
3u8_formats
(
168 decrypted
, track_id
, 'mp4', entry_protocol
='m3u8_native',
169 m3u8_id
='hls', fatal
=False))
170 elif url_key
== 'dashUrl':
171 formats
.extend(self
._extract
_mpd
_formats
(
172 decrypted
, track_id
, mpd_id
='dash', fatal
=False))
178 'downloader_options': {
179 # Mixcloud starts throttling at >~5M
180 'http_chunk_size': 5242880,
184 if not formats
and cloudcast
.get('isExclusive'):
185 self
.raise_login_required(metadata_available
=True)
188 for edge
in (try_get(cloudcast
, lambda x
: x
['comments']['edges']) or []):
189 node
= edge
.get('node') or {}
190 text
= strip_or_none(node
.get('comment'))
193 user
= node
.get('user') or {}
195 'author': user
.get('displayName'),
196 'author_id': user
.get('username'),
198 'timestamp': parse_iso8601(node
.get('created')),
202 for t
in cloudcast
.get('tags'):
203 tag
= try_get(t
, lambda x
: x
['tag']['name'], compat_str
)
207 get_count
= lambda x
: int_or_none(try_get(cloudcast
, lambda y
: y
[x
]['totalCount']))
209 owner
= cloudcast
.get('owner') or {}
215 'description': cloudcast
.get('description'),
216 'thumbnail': try_get(cloudcast
, lambda x
: x
['picture']['url'], compat_str
),
217 'uploader': owner
.get('displayName'),
218 'timestamp': parse_iso8601(cloudcast
.get('publishDate')),
219 'uploader_id': owner
.get('username'),
220 'uploader_url': owner
.get('url'),
221 'duration': int_or_none(cloudcast
.get('audioLength')),
222 'view_count': int_or_none(cloudcast
.get('plays')),
223 'like_count': get_count('favorites'),
224 'repost_count': get_count('reposts'),
225 'comment_count': get_count('comments'),
226 'comments': comments
,
228 'artist': ', '.join(cloudcast
.get('featuringArtistList') or []) or None,
232 class MixcloudPlaylistBaseIE(MixcloudBaseIE
):
233 def _get_cloudcast(self
, node
):
236 def _get_playlist_title(self
, title
, slug
):
239 def _real_extract(self
, url
):
240 username
, slug
= self
._match
_valid
_url
(url
).groups()
241 username
= compat_urllib_parse_unquote(username
)
245 slug
= compat_urllib_parse_unquote(slug
)
246 playlist_id
= '%s_%s' % (username
, slug
)
248 is_playlist_type
= self
._ROOT
_TYPE
== 'playlist'
249 playlist_type
= 'items' if is_playlist_type
else slug
255 playlist
= self
._call
_api
(
256 self
._ROOT
_TYPE
, '''%s
268 }''' % (self
._TITLE
_KEY
, self
._DESCRIPTION
_KEY
, playlist_type
, list_filter
, self
._NODE
_TEMPLATE
),
269 playlist_id
, username
, slug
if is_playlist_type
else None)
271 items
= playlist
.get(playlist_type
) or {}
272 for edge
in items
.get('edges', []):
273 cloudcast
= self
._get
_cloudcast
(edge
.get('node') or {})
274 cloudcast_url
= cloudcast
.get('url')
275 if not cloudcast_url
:
277 item_slug
= try_get(cloudcast
, lambda x
: x
['slug'], compat_str
)
278 owner_username
= try_get(cloudcast
, lambda x
: x
['owner']['username'], compat_str
)
279 video_id
= f
'{owner_username}_{item_slug}' if item_slug
and owner_username
else None
280 entries
.append(self
.url_result(
281 cloudcast_url
, MixcloudIE
.ie_key(), video_id
))
283 page_info
= items
['pageInfo']
284 has_next_page
= page_info
['hasNextPage']
285 list_filter
= ', after: "%s"' % page_info
['endCursor']
287 return self
.playlist_result(
288 entries
, playlist_id
,
289 self
._get
_playlist
_title
(playlist
[self
._TITLE
_KEY
], slug
),
290 playlist
.get(self
._DESCRIPTION
_KEY
))
293 class MixcloudUserIE(MixcloudPlaylistBaseIE
):
294 _VALID_URL
= r
'https?://(?:www\.)?mixcloud\.com/(?P<id>[^/]+)/(?P<type>uploads|favorites|listens|stream)?/?$'
295 IE_NAME
= 'mixcloud:user'
298 'url': 'http://www.mixcloud.com/dholbach/',
300 'id': 'dholbach_uploads',
301 'title': 'Daniel Holbach (uploads)',
302 'description': 'md5:a3f468a60ac8c3e1f8616380fc469b2b',
304 'playlist_mincount': 36,
306 'url': 'http://www.mixcloud.com/dholbach/uploads/',
308 'id': 'dholbach_uploads',
309 'title': 'Daniel Holbach (uploads)',
310 'description': 'md5:a3f468a60ac8c3e1f8616380fc469b2b',
312 'playlist_mincount': 36,
314 'url': 'http://www.mixcloud.com/dholbach/favorites/',
316 'id': 'dholbach_favorites',
317 'title': 'Daniel Holbach (favorites)',
318 'description': 'md5:a3f468a60ac8c3e1f8616380fc469b2b',
321 # 'playlist_items': '1-100',
323 'playlist_mincount': 396,
325 'url': 'http://www.mixcloud.com/dholbach/listens/',
327 'id': 'dholbach_listens',
328 'title': 'Daniel Holbach (listens)',
329 'description': 'md5:b60d776f0bab534c5dabe0a34e47a789',
332 # 'playlist_items': '1-100',
334 'playlist_mincount': 1623,
335 'skip': 'Large list',
337 'url': 'https://www.mixcloud.com/FirstEar/stream/',
339 'id': 'FirstEar_stream',
340 'title': 'First Ear (stream)',
341 'description': 'we maraud for ears',
343 'playlist_mincount': 269,
346 _TITLE_KEY
= 'displayName'
347 _DESCRIPTION_KEY
= 'biog'
349 _NODE_TEMPLATE
= '''slug
351 owner { username }'''
353 def _get_playlist_title(self
, title
, slug
):
354 return '%s (%s)' % (title
, slug
)
357 class MixcloudPlaylistIE(MixcloudPlaylistBaseIE
):
358 _VALID_URL
= r
'https?://(?:www\.)?mixcloud\.com/(?P<user>[^/]+)/playlists/(?P<playlist>[^/]+)/?$'
359 IE_NAME
= 'mixcloud:playlist'
362 'url': 'https://www.mixcloud.com/maxvibes/playlists/jazzcat-on-ness-radio/',
364 'id': 'maxvibes_jazzcat-on-ness-radio',
365 'title': 'Ness Radio sessions',
367 'playlist_mincount': 59,
370 _DESCRIPTION_KEY
= 'description'
371 _ROOT_TYPE
= 'playlist'
372 _NODE_TEMPLATE
= '''cloudcast {
378 def _get_cloudcast(self
, node
):
379 return node
.get('cloudcast') or {}