2 from __future__
import unicode_literals
13 from ..compat
import (
37 class SoundcloudEmbedIE(InfoExtractor
):
38 _VALID_URL
= r
'https?://(?:w|player|p)\.soundcloud\.com/player/?.*?\burl=(?P<id>.+)'
40 # from https://www.soundi.fi/uutiset/ennakkokuuntelussa-timo-kaukolammen-station-to-station-to-station-julkaisua-juhlitaan-tanaan-g-livelabissa/
41 'url': 'https://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F922213810&show_artwork=true&maxwidth=640&maxheight=960&dnt=1&secret_token=s-ziYey',
42 'only_matching': True,
46 def _extract_urls(webpage
):
47 return [m
.group('url') for m
in re
.finditer(
48 r
'<iframe[^>]+src=(["\'])(?P
<url
>(?
:https?
://)?
(?
:w\
.)?soundcloud\
.com
/player
.+?
)\
1',
51 def _real_extract(self, url):
52 query = compat_urlparse.parse_qs(
53 compat_urlparse.urlparse(url).query)
54 api_url = query['url
'][0]
55 secret_token = query.get('secret_token
')
57 api_url = update_url_query(api_url, {'secret_token': secret_token[0]})
58 return self.url_result(api_url)
61 class SoundcloudIE(InfoExtractor):
62 """Information extractor for soundcloud.com
63 To access the media, the uid of the song and a stream token
64 must be extracted from the page source and the script must make
65 a request to media.soundcloud.com/crossdomain.xml. Then
66 the media can be grabbed by requesting from an url composed
67 of the stream token and uid
70 _VALID_URL = r'''(?x)^(?:https?://)?
71 (?:(?:(?:www\.|m\.)?soundcloud\.com/
73 (?P<uploader>[\w\d-]+)/
74 (?!(?:tracks|albums|sets(?:/.+?)?|reposts|likes|spotlight)/?(?:$|[?#]))
76 (?P<token>[^?]+?)?(?:[?].*)?$)
77 |(?:api(?:-v2)?\.soundcloud\.com/tracks/(?P<track_id>\d+)
78 (?:/?\?secret_token=(?P<secret_token>[^&]+))?)
81 IE_NAME = 'soundcloud
'
84 'url
': 'http
://soundcloud
.com
/ethmusic
/lostin
-powers
-she
-so
-heavy
',
85 'md5
': 'ebef0a451b909710ed1d7787dddbf0d7
',
89 'title
': 'Lostin Powers
- She so
Heavy (SneakPreview
) Adrian Ackers Blueprint
1',
90 'description
': 'No Downloads untill we record the finished version this weekend
, i was too pumped n i had to post it
, earl
is prolly gonna b hella p
.o
\'d
',
91 'uploader
': 'E
.T
. ExTerrestrial Music
',
92 'uploader_id
': '1571244',
93 'timestamp
': 1349920598,
94 'upload_date
': '20121011',
96 'license
': 'all
-rights
-reserved
',
105 'url
': 'https
://soundcloud
.com
/the
-concept
-band
/goldrushed
-mastered?
in=the
-concept
-band
/sets
/the
-royal
-concept
-ep
',
109 'title
': 'Goldrushed
',
110 'description
': 'From Stockholm Sweden
\r\nPovel
/ Magnus
/ Filip
/ David
\r\nwww
.theroyalconcept
.com
',
111 'uploader
': 'The Royal Concept
',
112 'uploader_id
': '9615865',
113 'timestamp
': 1337635207,
114 'upload_date
': '20120521',
116 'license
': 'all
-rights
-reserved
',
119 'comment_count
': int,
125 'url
': 'https
://soundcloud
.com
/jaimemf
/youtube
-dl
-test
-video
-a
-y
-baw
/s
-8Pjrp
',
126 'md5
': 'aa0dd32bfea9b0c5ef4f02aacd080604
',
130 'title
': 'Youtube
- Dl Test Video
\'\' Ä↭
',
131 'description
': 'test chars
: \"\'/\\ä↭
',
132 'uploader
': 'jaimeMF
',
133 'uploader_id
': '69767071',
134 'timestamp
': 1386604920,
135 'upload_date
': '20131209',
137 'license
': 'all
-rights
-reserved
',
140 'comment_count
': int,
144 # private link (alt format)
146 'url
': 'https
://api
.soundcloud
.com
/tracks
/123998367?secret_token
=s
-8Pjrp
',
147 'md5
': 'aa0dd32bfea9b0c5ef4f02aacd080604
',
151 'title
': 'Youtube
- Dl Test Video
\'\' Ä↭
',
152 'description
': 'test chars
: \"\'/\\ä↭
',
153 'uploader
': 'jaimeMF
',
154 'uploader_id
': '69767071',
155 'timestamp
': 1386604920,
156 'upload_date
': '20131209',
158 'license
': 'all
-rights
-reserved
',
161 'comment_count
': int,
167 'url
': 'https
://soundcloud
.com
/the80m
/the
-following
',
168 'md5
': '9ffcddb08c87d74fb5808a3c183a1d04
',
174 # private link, downloadable format
176 'url
': 'https
://soundcloud
.com
/oriuplift
/uponly
-238-no
-talking
-wav
/s
-AyZUd
',
177 'md5
': '64a60b16e617d41d0bef032b7f55441e
',
181 'title
': 'Uplifting Only
238 [No Talking
] (incl
. Alex Feed Guestmix
) (Aug
31, 2017) [wav
]',
182 'description
': 'md5
:fa20ee0fca76a3d6df8c7e57f3715366
',
183 'uploader
': 'Ori Uplift Music
',
184 'uploader_id
': '12563093',
185 'timestamp
': 1504206263,
186 'upload_date
': '20170831',
187 'duration
': 7449.096,
188 'license
': 'all
-rights
-reserved
',
191 'comment_count
': int,
195 # no album art, use avatar pic for thumbnail
197 'url
': 'https
://soundcloud
.com
/garyvee
/sideways
-prod
-mad
-real
',
198 'md5
': '59c7872bc44e5d99b7211891664760c2
',
202 'title
': 'Sideways (Prod
. Mad Real
)',
203 'description
': 'md5
:d41d8cd98f00b204e9800998ecf8427e
',
204 'uploader
': 'garyvee
',
205 'uploader_id
': '2366352',
206 'timestamp
': 1488152409,
207 'upload_date
': '20170226',
209 'thumbnail
': r're
:https?
://.*\
.jpg
',
210 'license
': 'all
-rights
-reserved
',
213 'comment_count
': int,
217 'skip_download
': True,
221 'url
': 'https
://soundcloud
.com
/giovannisarani
/mezzo
-valzer
',
222 'md5
': 'e22aecd2bc88e0e4e432d7dcc0a1abf7
',
226 'title
': 'Mezzo Valzer
',
227 'description
': 'md5
:4138d582f81866a530317bae316e8b61
',
228 'uploader
': 'Micronie
',
229 'uploader_id
': '3352531',
230 'timestamp
': 1551394171,
231 'upload_date
': '20190228',
233 'thumbnail
': r're
:https?
://.*\
.jpg
',
234 'license
': 'all
-rights
-reserved
',
237 'comment_count
': int,
242 # AAC HQ format available (account with active subscription needed)
243 'url
': 'https
://soundcloud
.com
/wandw
/the
-chainsmokers
-ft
-daya
-dont
-let
-me
-down
-ww
-remix
-1',
244 'only_matching
': True,
247 # Go+ (account with active subscription needed)
248 'url
': 'https
://soundcloud
.com
/taylorswiftofficial
/look
-what
-you
-made
-me
-do
',
249 'only_matching
': True,
253 _API_V2_BASE = 'https
://api
-v2
.soundcloud
.com
/'
254 _BASE_URL = 'https
://soundcloud
.com
/'
255 _IMAGE_REPL_RE = r'-([0-9a
-z
]+)\
.jpg
'
270 def _store_client_id(self, client_id):
271 self._downloader.cache.store('soundcloud
', 'client_id
', client_id)
273 def _update_client_id(self):
274 webpage = self._download_webpage('https
://soundcloud
.com
/', None)
275 for src in reversed(re.findall(r'<script
[^
>]+src
="([^"]+)"', webpage)):
276 script = self._download_webpage(src, None, fatal=False)
278 client_id = self._search_regex(
279 r'client_id\s*:\s*"([0-9a
-zA
-Z
]{32}
)"',
280 script, 'client id', default=None)
282 self._CLIENT_ID = client_id
283 self._store_client_id(client_id)
285 raise ExtractorError('Unable to extract client id')
287 def _download_json(self, *args, **kwargs):
288 non_fatal = kwargs.get('fatal') is False
291 query = kwargs.get('query', {}).copy()
293 query['client_id'] = self._CLIENT_ID
294 kwargs['query'] = query
296 return super(SoundcloudIE, self)._download_json(*args, **compat_kwargs(kwargs))
297 except ExtractorError as e:
298 if isinstance(e.cause, compat_HTTPError) and e.cause.code in (401, 403):
299 self._store_client_id(None)
300 self._update_client_id()
303 self.report_warning(error_to_compat_str(e))
307 def _real_initialize(self):
308 self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'fSSdm5yTnDka1g0Fz1CO5Yx6z0NbeHAj'
311 _USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
312 _API_AUTH_QUERY_TEMPLATE = '?client_id=%s'
313 _API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s'
314 _API_VERIFY_AUTH_TOKEN = 'https://api-auth.soundcloud.com/connect/session%s'
317 _NETRC_MACHINE = 'soundcloud'
320 username, password = self._get_login_info()
324 if username == 'oauth' and password is not None:
325 self._access_token = password
326 query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
327 payload = {'session': {'access_token': self._access_token}}
328 token_verification = sanitized_Request(self._API_VERIFY_AUTH_TOKEN % query, json.dumps(payload).encode('utf-8'))
329 response = self._download_json(token_verification, None, note='Verifying login token...', fatal=False)
330 if response is not False:
331 self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
334 self.report_warning('Provided authorization token seems to be invalid. Continue as guest')
335 elif username is not None:
337 'Login using username and password is not currently supported. '
338 'Use "--user oauth
--password
<oauth_token
>" to login using an oauth token')
343 return ''.join([str(random.randrange(10)) for i in range(6)])
344 return '-'.join([genNumBlock() for i in range(4)])
347 'client_id': self._CLIENT_ID,
348 'recaptcha_pubkey': 'null',
349 'recaptcha_response': 'null',
351 'identifier': username,
354 'signature': self.sign(username, password, self._CLIENT_ID),
355 'device_id': genDevId(),
356 'user_agent': self._USER_AGENT
359 query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID
360 login = sanitized_Request(self._API_AUTH_URL_PW % query, json.dumps(payload).encode('utf-8'))
361 response = self._download_json(login, None)
362 self._access_token = response.get('session').get('access_token')
363 if not self._access_token:
364 self.report_warning('Unable to get access token, login may has failed')
366 self._HEADERS = {'Authorization': 'OAuth ' + self._access_token}
369 # signature generation
370 def sign(self, user, pw, clid):
380 n = '0763ed7314c69015fd4a0dc16bbf4b90' # _KEY
382 r = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' # _USER_AGENT
384 t = clid # _CLIENT_ID
386 d = '-'.join([str(mInt) for mInt in [a, i, s, w, u, l, b, k]])
387 p = n + y + d + r + e + t + d + n
393 for f in range(f, len(h)):
394 m = (m >> 1) + ((1 & m) << 23)
398 # c is not even needed
399 out = str(y) + ':' + str(d) + ':' + format(m, 'x') + ':' + str(c)
404 def _resolv_url(cls, url):
405 return SoundcloudIE._API_V2_BASE + 'resolve?url=' + url
407 def _extract_info_dict(self, info, full_title=None, secret_token=None):
408 track_id = compat_str(info['id'])
409 title = info['title']
413 query = {'client_id': self._CLIENT_ID}
415 query['secret_token'] = secret_token
417 if info.get('downloadable') and info.get('has_downloads_left'):
418 download_url = update_url_query(
419 self._API_V2_BASE + 'tracks/' + track_id + '/download', query)
420 redirect_url = (self._download_json(download_url, track_id, fatal=False) or {}).get('redirectUri')
422 urlh = self._request_webpage(
423 HEADRequest(redirect_url), track_id, fatal=False)
425 format_url = urlh.geturl()
426 format_urls.add(format_url)
428 'format_id': 'download',
429 'ext': urlhandle_detect_ext(urlh) or 'mp3',
430 'filesize': int_or_none(urlh.headers.get('Content-Length')),
435 def invalid_url(url):
436 return not url or url in format_urls
438 def add_format(f, protocol, is_preview=False):
439 mobj = re.search(r'\.(?P<abr>\d+)\.(?P<ext>[0-9a-z]{3,4})(?=[/?])', stream_url)
441 for k, v in mobj.groupdict().items():
446 format_id_list.append(protocol)
450 for k in ('ext', 'abr'):
453 format_id_list.append(v)
454 preview = is_preview or re.search(r'/(?:preview|playlist)/0/30/', f['url'])
456 format_id_list.append('preview')
460 if protocol == 'hls':
461 protocol = 'm3u8' if ext == 'aac' else 'm3u8_native'
465 'format_id': '_'.join(format_id_list),
466 'protocol': protocol,
467 'preference': -10 if preview else None,
472 transcodings = try_get(
473 info, lambda x: x['media']['transcodings'], list) or []
474 for t in transcodings:
475 if not isinstance(t, dict):
477 format_url = url_or_none(t.get('url'))
480 stream = self._download_json(
481 format_url, track_id, query=query, fatal=False, headers=self._HEADERS)
482 if not isinstance(stream, dict):
484 stream_url = url_or_none(stream.get('url'))
485 if invalid_url(stream_url):
487 format_urls.add(stream_url)
488 stream_format = t.get('format') or {}
489 protocol = stream_format.get('protocol')
490 if protocol != 'hls' and '/hls' in format_url:
493 preset = str_or_none(t.get('preset'))
495 ext = preset.split('_')[0]
496 if ext not in KNOWN_EXTENSIONS:
497 ext = mimetype2ext(stream_format.get('mime_type'))
501 }, 'http' if protocol == 'progressive' else protocol,
502 t.get('snipped') or '/preview/' in format_url)
507 if not formats and info.get('policy') == 'BLOCK':
508 self.raise_geo_restricted(metadata_available=True)
509 self._sort_formats(formats)
511 user = info.get('user') or {}
514 artwork_url = info.get('artwork_url')
515 thumbnail = artwork_url or user.get('avatar_url')
516 if isinstance(thumbnail, compat_str):
517 if re.search(self._IMAGE_REPL_RE, thumbnail):
518 for image_id, size in self._ARTWORK_MAP.items():
521 'url': re.sub(self._IMAGE_REPL_RE, '-%s.jpg' % image_id, thumbnail),
523 if image_id == 'tiny' and not artwork_url:
525 elif image_id == 'original':
534 thumbnails = [{'url': thumbnail}]
536 def extract_count(key):
537 return int_or_none(info.get('%s_count' % key))
541 'uploader': user.get('username'),
542 'uploader_id': str_or_none(user.get('id')) or user.get('permalink'),
543 'uploader_url': user.get('permalink_url'),
544 'timestamp': unified_timestamp(info.get('created_at')),
546 'description': info.get('description'),
547 'thumbnails': thumbnails,
548 'duration': float_or_none(info.get('duration'), 1000),
549 'webpage_url': info.get('permalink_url'),
550 'license': info.get('license'),
551 'view_count': extract_count('playback'),
552 'like_count': extract_count('favoritings') or extract_count('likes'),
553 'comment_count': extract_count('comment'),
554 'repost_count': extract_count('reposts'),
555 'genre': info.get('genre'),
559 def _real_extract(self, url):
560 mobj = re.match(self._VALID_URL, url)
562 track_id = mobj.group('track_id')
566 info_json_url = self._API_V2_BASE + 'tracks/' + track_id
567 full_title = track_id
568 token = mobj.group('secret_token')
570 query['secret_token'] = token
572 full_title = resolve_title = '%s/%s' % mobj.group('uploader', 'title')
573 token = mobj.group('token')
575 resolve_title += '/%s' % token
576 info_json_url = self._resolv_url(self._BASE_URL + resolve_title)
578 info = self._download_json(
579 info_json_url, full_title, 'Downloading info JSON', query=query, headers=self._HEADERS)
581 return self._extract_info_dict(info, full_title, token)
584 class SoundcloudPlaylistBaseIE(SoundcloudIE):
585 def _extract_set(self, playlist, token=None):
586 playlist_id = compat_str(playlist['id'])
587 tracks = playlist.get('tracks') or []
588 if not all([t.get('permalink_url') for t in tracks]) and token:
589 tracks = self._download_json(
590 self._API_V2_BASE + 'tracks', playlist_id,
591 'Downloading tracks', query={
592 'ids': ','.join([compat_str(t['id']) for t in tracks]),
593 'playlistId': playlist_id,
594 'playlistSecretToken': token,
595 }, headers=self._HEADERS)
598 track_id = str_or_none(track.get('id'))
599 url = track.get('permalink_url')
603 url = self._API_V2_BASE + 'tracks/' + track_id
605 url += '?secret_token=' + token
606 entries.append(self.url_result(
607 url, SoundcloudIE.ie_key(), track_id))
608 return self.playlist_result(
609 entries, playlist_id,
610 playlist.get('title'),
611 playlist.get('description'))
614 class SoundcloudSetIE(SoundcloudPlaylistBaseIE):
615 _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<uploader>[\w\d-]+)/sets/(?P<slug_title>[:\w\d-]+)(?:/(?P<token>[^?/]+))?'
616 IE_NAME = 'soundcloud:set'
618 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep',
621 'title': 'The Royal Concept EP',
622 'description': 'md5:71d07087c7a449e8941a70a29e34671e',
624 'playlist_mincount': 5,
626 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep/token',
627 'only_matching': True,
629 'url': 'https://soundcloud.com/discover/sets/weekly::flacmatic',
630 'only_matching': True,
632 'url': 'https://soundcloud.com/discover/sets/charts-top:all-music:de',
633 'only_matching': True,
635 'url': 'https://soundcloud.com/discover/sets/charts-top:hiphoprap:kr',
636 'only_matching': True,
639 def _real_extract(self, url):
640 mobj = re.match(self._VALID_URL, url)
642 full_title = '%s/sets/%s' % mobj.group('uploader', 'slug_title')
643 token = mobj.group('token')
645 full_title += '/' + token
647 info = self._download_json(self._resolv_url(
648 self._BASE_URL + full_title), full_title, headers=self._HEADERS)
651 msgs = (compat_str(err['error_message']) for err in info['errors'])
652 raise ExtractorError('unable to download video webpage: %s' % ','.join(msgs))
654 return self._extract_set(info, token)
657 class SoundcloudPagedPlaylistBaseIE(SoundcloudIE):
658 def _extract_playlist(self, base_url, playlist_id, playlist_title):
659 # Per the SoundCloud documentation, the maximum limit for a linked partitioning query is 200.
660 # https://developers.soundcloud.com/blog/offset-pagination-deprecated
663 'linked_partitioning': '1',
666 query = COMMON_QUERY.copy()
672 for i in itertools.count():
673 response = self._download_json(
674 next_href, playlist_id,
675 'Downloading track page %s' % (i + 1), query=query, headers=self._HEADERS)
677 collection = response['collection']
679 if not isinstance(collection, list):
682 # Empty collection may be returned, in this case we proceed
683 # straight to next_href
685 def resolve_entry(candidates):
686 for cand in candidates:
687 if not isinstance(cand, dict):
689 permalink_url = url_or_none(cand.get('permalink_url'))
690 if not permalink_url:
692 return self.url_result(
694 SoundcloudIE.ie_key() if SoundcloudIE.suitable(permalink_url) else None,
695 str_or_none(cand.get('id')), cand.get('title'))
698 entry = resolve_entry((e, e.get('track'), e.get('playlist')))
700 entries.append(entry)
702 next_href = response.get('next_href')
706 next_href = response['next_href']
707 parsed_next_href = compat_urlparse.urlparse(next_href)
708 query = compat_urlparse.parse_qs(parsed_next_href.query)
709 query.update(COMMON_QUERY)
714 'title': playlist_title,
719 class SoundcloudUserIE(SoundcloudPagedPlaylistBaseIE):
720 _VALID_URL = r'''(?x)
722 (?:(?:www|m)\.)?soundcloud\.com/
725 (?P<rsrc>tracks|albums|sets|reposts|likes|spotlight)
729 IE_NAME = 'soundcloud:user'
731 'url': 'https://soundcloud.com/soft-cell-official',
734 'title': 'Soft Cell (All)',
736 'playlist_mincount': 28,
738 'url': 'https://soundcloud.com/soft-cell-official/tracks',
741 'title': 'Soft Cell (Tracks)',
743 'playlist_mincount': 27,
745 'url': 'https://soundcloud.com/soft-cell-official/albums',
748 'title': 'Soft Cell (Albums)',
750 'playlist_mincount': 1,
752 'url': 'https://soundcloud.com/jcv246/sets',
755 'title': 'Jordi / cv (Sets)',
757 'playlist_mincount': 2,
759 'url': 'https://soundcloud.com/jcv246/reposts',
762 'title': 'Jordi / cv (Reposts)',
764 'playlist_mincount': 6,
766 'url': 'https://soundcloud.com/clalberg/likes',
769 'title': 'clalberg (Likes)',
771 'playlist_mincount': 5,
773 'url': 'https://soundcloud.com/grynpyret/spotlight',
776 'title': 'Grynpyret (Spotlight)',
778 'playlist_mincount': 1,
782 'all': 'stream/users/%s',
783 'tracks': 'users/%s/tracks',
784 'albums': 'users/%s/albums',
785 'sets': 'users/%s/playlists',
786 'reposts': 'stream/users/%s/reposts',
787 'likes': 'users/%s/likes',
788 'spotlight': 'users/%s/spotlight',
791 def _real_extract(self, url):
792 mobj = re.match(self._VALID_URL, url)
793 uploader = mobj.group('user')
795 user = self._download_json(
796 self._resolv_url(self._BASE_URL + uploader),
797 uploader, 'Downloading user info', headers=self._HEADERS)
799 resource = mobj.group('rsrc') or 'all'
801 return self._extract_playlist(
802 self._API_V2_BASE + self._BASE_URL_MAP[resource] % user['id'],
803 str_or_none(user.get('id')),
804 '%s (%s)' % (user['username'], resource.capitalize()))
807 class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
808 _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)'
809 IE_NAME = 'soundcloud:trackstation'
811 'url': 'https://soundcloud.com/stations/track/officialsundial/your-text',
814 'title': 'Track station: your text',
816 'playlist_mincount': 47,
819 def _real_extract(self, url):
820 track_name = self._match_id(url)
822 track = self._download_json(self._resolv_url(url), track_name, headers=self._HEADERS)
823 track_id = self._search_regex(
824 r'soundcloud:track-stations:(\d+)', track['id'], 'track id')
826 return self._extract_playlist(
827 self._API_V2_BASE + 'stations/%s/tracks' % track['id'],
828 track_id, 'Track station: %s' % track['title'])
831 class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE):
832 _VALID_URL = r'https?://api(?:-v2)?\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$'
833 IE_NAME = 'soundcloud:playlist'
835 'url': 'https://api.soundcloud.com/playlists/4110309',
838 'title': 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]',
839 'description': 're:.*?TILT Brass - Bowery Poetry Club',
844 def _real_extract(self, url):
845 mobj = re.match(self._VALID_URL, url)
846 playlist_id = mobj.group('id')
849 token = mobj.group('token')
851 query['secret_token'] = token
853 data = self._download_json(
854 self._API_V2_BASE + 'playlists/' + playlist_id,
855 playlist_id, 'Downloading playlist', query=query, headers=self._HEADERS)
857 return self._extract_set(data, token)
860 class SoundcloudSearchIE(SearchInfoExtractor, SoundcloudIE):
861 IE_NAME = 'soundcloud:search'
862 IE_DESC = 'Soundcloud search'
863 _MAX_RESULTS = float('inf')
865 'url': 'scsearch15:post-avant jazzcore',
867 'title': 'post-avant jazzcore',
869 'playlist_count': 15,
872 _SEARCH_KEY = 'scsearch'
873 _MAX_RESULTS_PER_PAGE = 200
874 _DEFAULT_RESULTS_PER_PAGE = 50
876 def _get_collection(self, endpoint, collection_id, **query):
878 query.get('limit', self._DEFAULT_RESULTS_PER_PAGE),
879 self._MAX_RESULTS_PER_PAGE)
882 'linked_partitioning': 1,
885 next_url = update_url_query(self._API_V2_BASE + endpoint, query)
887 collected_results = 0
889 for i in itertools.count(1):
890 response = self._download_json(
891 next_url, collection_id, 'Downloading page {0}'.format(i),
892 'Unable to download API page', headers=self._HEADERS)
894 collection = response.get('collection', [])
898 collection = list(filter(bool, collection))
899 collected_results += len(collection)
901 for item in collection:
902 yield self.url_result(item['uri'], SoundcloudIE.ie_key())
904 if not collection or collected_results >= limit:
907 next_url = response.get('next_href')
911 def _get_n_results(self, query, n):
912 tracks = self._get_collection('search/tracks', query, limit=n, q=query)
913 return self.playlist_result(tracks, playlist_title=query)