]>
Commit | Line | Data |
---|---|---|
92790f4e | 1 | import itertools |
73602bcd | 2 | import re |
2ab47fa3 | 3 | import json |
be05d5cf | 4 | # import random |
aad0d6d5 | 5 | |
2abf7cab | 6 | from .common import ( |
7 | InfoExtractor, | |
8 | SearchInfoExtractor | |
9 | ) | |
1cc79574 | 10 | from ..compat import ( |
3bed6217 | 11 | compat_HTTPError, |
aad0d6d5 | 12 | compat_str, |
1cc79574 PH |
13 | ) |
14 | from ..utils import ( | |
de7aade2 | 15 | error_to_compat_str, |
aad0d6d5 | 16 | ExtractorError, |
e09965d5 | 17 | float_or_none, |
548c3957 | 18 | HEADRequest, |
eb920777 | 19 | int_or_none, |
e09965d5 | 20 | KNOWN_EXTENSIONS, |
e09965d5 | 21 | mimetype2ext, |
e04a1ff9 | 22 | remove_end, |
aa6c2530 | 23 | parse_qs, |
e09965d5 | 24 | str_or_none, |
f516f440 S |
25 | try_get, |
26 | unified_timestamp, | |
d7c7100e | 27 | update_url_query, |
7c5307f4 | 28 | url_or_none, |
a6c5859d | 29 | urlhandle_detect_ext, |
2ab47fa3 | 30 | sanitized_Request, |
d7c7100e | 31 | ) |
aad0d6d5 PH |
32 | |
33 | ||
548c3957 | 34 | class SoundcloudEmbedIE(InfoExtractor): |
cf80ff18 | 35 | _VALID_URL = r'https?://(?:w|player|p)\.soundcloud\.com/player/?.*?\burl=(?P<id>.+)' |
bfd973ec | 36 | _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?(?:w\.)?soundcloud\.com/player.+?)\1'] |
cf80ff18 RA |
37 | _TEST = { |
38 | # from https://www.soundi.fi/uutiset/ennakkokuuntelussa-timo-kaukolammen-station-to-station-to-station-julkaisua-juhlitaan-tanaan-g-livelabissa/ | |
39 | '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', | |
40 | 'only_matching': True, | |
41 | } | |
548c3957 | 42 | |
548c3957 | 43 | def _real_extract(self, url): |
aa6c2530 | 44 | query = parse_qs(url) |
cf80ff18 RA |
45 | api_url = query['url'][0] |
46 | secret_token = query.get('secret_token') | |
47 | if secret_token: | |
48 | api_url = update_url_query(api_url, {'secret_token': secret_token[0]}) | |
49 | return self.url_result(api_url) | |
548c3957 RA |
50 | |
51 | ||
63ccf4ff | 52 | class SoundcloudBaseIE(InfoExtractor): |
08d30158 | 53 | _NETRC_MACHINE = 'soundcloud' |
54 | ||
63ccf4ff | 55 | _API_V2_BASE = 'https://api-v2.soundcloud.com/' |
56 | _BASE_URL = 'https://soundcloud.com/' | |
08d30158 | 57 | _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' |
58 | _API_AUTH_QUERY_TEMPLATE = '?client_id=%s' | |
59 | _API_AUTH_URL_PW = 'https://api-auth.soundcloud.com/web-auth/sign-in/password%s' | |
60 | _API_VERIFY_AUTH_TOKEN = 'https://api-auth.soundcloud.com/connect/session%s' | |
61 | _access_token = None | |
62 | _HEADERS = {} | |
63ccf4ff | 63 | |
64 | def _store_client_id(self, client_id): | |
9809740b | 65 | self.cache.store('soundcloud', 'client_id', client_id) |
63ccf4ff | 66 | |
67 | def _update_client_id(self): | |
68 | webpage = self._download_webpage('https://soundcloud.com/', None) | |
69 | for src in reversed(re.findall(r'<script[^>]+src="([^"]+)"', webpage)): | |
70 | script = self._download_webpage(src, None, fatal=False) | |
71 | if script: | |
72 | client_id = self._search_regex( | |
73 | r'client_id\s*:\s*"([0-9a-zA-Z]{32})"', | |
74 | script, 'client id', default=None) | |
75 | if client_id: | |
76 | self._CLIENT_ID = client_id | |
77 | self._store_client_id(client_id) | |
78 | return | |
79 | raise ExtractorError('Unable to extract client id') | |
80 | ||
81 | def _download_json(self, *args, **kwargs): | |
82 | non_fatal = kwargs.get('fatal') is False | |
83 | if non_fatal: | |
84 | del kwargs['fatal'] | |
85 | query = kwargs.get('query', {}).copy() | |
86 | for _ in range(2): | |
87 | query['client_id'] = self._CLIENT_ID | |
88 | kwargs['query'] = query | |
89 | try: | |
f9934b96 | 90 | return super()._download_json(*args, **kwargs) |
63ccf4ff | 91 | except ExtractorError as e: |
92 | if isinstance(e.cause, compat_HTTPError) and e.cause.code in (401, 403): | |
93 | self._store_client_id(None) | |
94 | self._update_client_id() | |
95 | continue | |
96 | elif non_fatal: | |
97 | self.report_warning(error_to_compat_str(e)) | |
98 | return False | |
99 | raise | |
100 | ||
52efa4b3 | 101 | def _initialize_pre_login(self): |
9809740b | 102 | self._CLIENT_ID = self.cache.load('soundcloud', 'client_id') or 'a3e059563d7fd3372b49b37f00a00bcf' |
63ccf4ff | 103 | |
52efa4b3 | 104 | def _perform_login(self, username, password): |
105 | if username != 'oauth': | |
63ccf4ff | 106 | self.report_warning( |
107 | 'Login using username and password is not currently supported. ' | |
b69fd25c | 108 | 'Use "--username oauth --password <oauth_token>" to login using an oauth token') |
52efa4b3 | 109 | self._access_token = password |
110 | query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID | |
111 | payload = {'session': {'access_token': self._access_token}} | |
112 | token_verification = sanitized_Request(self._API_VERIFY_AUTH_TOKEN % query, json.dumps(payload).encode('utf-8')) | |
113 | response = self._download_json(token_verification, None, note='Verifying login token...', fatal=False) | |
114 | if response is not False: | |
115 | self._HEADERS = {'Authorization': 'OAuth ' + self._access_token} | |
116 | self.report_login() | |
117 | else: | |
118 | self.report_warning('Provided authorization token seems to be invalid. Continue as guest') | |
63ccf4ff | 119 | |
120 | r''' | |
121 | def genDevId(): | |
122 | def genNumBlock(): | |
123 | return ''.join([str(random.randrange(10)) for i in range(6)]) | |
124 | return '-'.join([genNumBlock() for i in range(4)]) | |
125 | ||
126 | payload = { | |
127 | 'client_id': self._CLIENT_ID, | |
128 | 'recaptcha_pubkey': 'null', | |
129 | 'recaptcha_response': 'null', | |
130 | 'credentials': { | |
131 | 'identifier': username, | |
132 | 'password': password | |
133 | }, | |
134 | 'signature': self.sign(username, password, self._CLIENT_ID), | |
135 | 'device_id': genDevId(), | |
136 | 'user_agent': self._USER_AGENT | |
137 | } | |
138 | ||
139 | query = self._API_AUTH_QUERY_TEMPLATE % self._CLIENT_ID | |
140 | login = sanitized_Request(self._API_AUTH_URL_PW % query, json.dumps(payload).encode('utf-8')) | |
141 | response = self._download_json(login, None) | |
142 | self._access_token = response.get('session').get('access_token') | |
143 | if not self._access_token: | |
144 | self.report_warning('Unable to get access token, login may has failed') | |
145 | else: | |
146 | self._HEADERS = {'Authorization': 'OAuth ' + self._access_token} | |
147 | ''' | |
148 | ||
149 | # signature generation | |
150 | def sign(self, user, pw, clid): | |
151 | a = 33 | |
152 | i = 1 | |
153 | s = 440123 | |
154 | w = 117 | |
155 | u = 1800000 | |
156 | l = 1042 | |
157 | b = 37 | |
158 | k = 37 | |
159 | c = 5 | |
160 | n = '0763ed7314c69015fd4a0dc16bbf4b90' # _KEY | |
161 | y = '8' # _REV | |
162 | 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 | |
163 | e = user # _USERNAME | |
164 | t = clid # _CLIENT_ID | |
165 | ||
166 | d = '-'.join([str(mInt) for mInt in [a, i, s, w, u, l, b, k]]) | |
167 | p = n + y + d + r + e + t + d + n | |
168 | h = p | |
169 | ||
170 | m = 8011470 | |
171 | f = 0 | |
172 | ||
173 | for f in range(f, len(h)): | |
174 | m = (m >> 1) + ((1 & m) << 23) | |
175 | m += ord(h[f]) | |
176 | m &= 16777215 | |
177 | ||
178 | # c is not even needed | |
179 | out = str(y) + ':' + str(d) + ':' + format(m, 'x') + ':' + str(c) | |
180 | ||
181 | return out | |
182 | ||
183 | @classmethod | |
184 | def _resolv_url(cls, url): | |
185 | return cls._API_V2_BASE + 'resolve?url=' + url | |
186 | ||
187 | ||
188 | class SoundcloudIE(SoundcloudBaseIE): | |
aad0d6d5 PH |
189 | """Information extractor for soundcloud.com |
190 | To access the media, the uid of the song and a stream token | |
191 | must be extracted from the page source and the script must make | |
192 | a request to media.soundcloud.com/crossdomain.xml. Then | |
193 | the media can be grabbed by requesting from an url composed | |
194 | of the stream token and uid | |
195 | """ | |
196 | ||
20991253 | 197 | _VALID_URL = r'''(?x)^(?:https?://)? |
71507a11 | 198 | (?:(?:(?:www\.|m\.)?soundcloud\.com/ |
836ef264 | 199 | (?!stations/track) |
4ff50ef8 | 200 | (?P<uploader>[\w\d-]+)/ |
3ef2da2d | 201 | (?!(?:tracks|albums|sets(?:/.+?)?|reposts|likes|spotlight)/?(?:$|[?#])) |
c2dedf12 L |
202 | (?P<title>[\w\d-]+) |
203 | (?:/(?P<token>(?!(?:albums|sets|recommended))[^?]+?))? | |
204 | (?:[?].*)?$) | |
548c3957 | 205 | |(?:api(?:-v2)?\.soundcloud\.com/tracks/(?P<track_id>\d+) |
0403b069 | 206 | (?:/?\?secret_token=(?P<secret_token>[^&]+))?) |
eb6a41ba JMF |
207 | ) |
208 | ''' | |
fbcd7b5f | 209 | IE_NAME = 'soundcloud' |
12c167c8 JMF |
210 | _TESTS = [ |
211 | { | |
fbcd7b5f | 212 | 'url': 'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy', |
fbcd7b5f PH |
213 | 'md5': 'ebef0a451b909710ed1d7787dddbf0d7', |
214 | 'info_dict': { | |
0eb9fb9f JMF |
215 | 'id': '62986583', |
216 | 'ext': 'mp3', | |
f516f440 | 217 | 'title': 'Lostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1', |
0eb9fb9f JMF |
218 | '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', |
219 | 'uploader': 'E.T. ExTerrestrial Music', | |
548c3957 | 220 | 'uploader_id': '1571244', |
f516f440 S |
221 | 'timestamp': 1349920598, |
222 | 'upload_date': '20121011', | |
e09965d5 | 223 | 'duration': 143.216, |
4bfd294e | 224 | 'license': 'all-rights-reserved', |
f516f440 S |
225 | 'view_count': int, |
226 | 'like_count': int, | |
227 | 'comment_count': int, | |
228 | 'repost_count': int, | |
12c167c8 JMF |
229 | } |
230 | }, | |
a6c5859d | 231 | # geo-restricted |
12c167c8 | 232 | { |
fbcd7b5f PH |
233 | 'url': 'https://soundcloud.com/the-concept-band/goldrushed-mastered?in=the-concept-band/sets/the-royal-concept-ep', |
234 | 'info_dict': { | |
235 | 'id': '47127627', | |
236 | 'ext': 'mp3', | |
237 | 'title': 'Goldrushed', | |
63ad0315 | 238 | 'description': 'From Stockholm Sweden\r\nPovel / Magnus / Filip / David\r\nwww.theroyalconcept.com', |
fbcd7b5f | 239 | 'uploader': 'The Royal Concept', |
548c3957 | 240 | 'uploader_id': '9615865', |
f516f440 | 241 | 'timestamp': 1337635207, |
fbcd7b5f | 242 | 'upload_date': '20120521', |
a6c5859d | 243 | 'duration': 227.155, |
4bfd294e | 244 | 'license': 'all-rights-reserved', |
f516f440 S |
245 | 'view_count': int, |
246 | 'like_count': int, | |
247 | 'comment_count': int, | |
248 | 'repost_count': int, | |
12c167c8 | 249 | }, |
12c167c8 | 250 | }, |
de2dd4c5 JMF |
251 | # private link |
252 | { | |
7a5c1cfe | 253 | 'url': 'https://soundcloud.com/jaimemf/youtube-dl-test-video-a-y-baw/s-8Pjrp', |
fbcd7b5f PH |
254 | 'md5': 'aa0dd32bfea9b0c5ef4f02aacd080604', |
255 | 'info_dict': { | |
256 | 'id': '123998367', | |
257 | 'ext': 'mp3', | |
258 | 'title': 'Youtube - Dl Test Video \'\' Ä↭', | |
fbcd7b5f | 259 | 'description': 'test chars: \"\'/\\ä↭', |
f516f440 | 260 | 'uploader': 'jaimeMF', |
548c3957 | 261 | 'uploader_id': '69767071', |
f516f440 | 262 | 'timestamp': 1386604920, |
fbcd7b5f | 263 | 'upload_date': '20131209', |
e09965d5 | 264 | 'duration': 9.927, |
4bfd294e | 265 | 'license': 'all-rights-reserved', |
f516f440 S |
266 | 'view_count': int, |
267 | 'like_count': int, | |
268 | 'comment_count': int, | |
269 | 'repost_count': int, | |
de2dd4c5 JMF |
270 | }, |
271 | }, | |
9296738f | 272 | # private link (alt format) |
273 | { | |
274 | 'url': 'https://api.soundcloud.com/tracks/123998367?secret_token=s-8Pjrp', | |
275 | 'md5': 'aa0dd32bfea9b0c5ef4f02aacd080604', | |
276 | 'info_dict': { | |
277 | 'id': '123998367', | |
278 | 'ext': 'mp3', | |
279 | 'title': 'Youtube - Dl Test Video \'\' Ä↭', | |
9296738f | 280 | 'description': 'test chars: \"\'/\\ä↭', |
f516f440 | 281 | 'uploader': 'jaimeMF', |
548c3957 | 282 | 'uploader_id': '69767071', |
f516f440 | 283 | 'timestamp': 1386604920, |
9296738f | 284 | 'upload_date': '20131209', |
e09965d5 | 285 | 'duration': 9.927, |
4bfd294e | 286 | 'license': 'all-rights-reserved', |
f516f440 S |
287 | 'view_count': int, |
288 | 'like_count': int, | |
289 | 'comment_count': int, | |
290 | 'repost_count': int, | |
9296738f | 291 | }, |
292 | }, | |
f67ca84d JMF |
293 | # downloadable song |
294 | { | |
be05d5cf TOH |
295 | 'url': 'https://soundcloud.com/the80m/the-following', |
296 | 'md5': '9ffcddb08c87d74fb5808a3c183a1d04', | |
fbcd7b5f | 297 | 'info_dict': { |
be05d5cf TOH |
298 | 'id': '343609555', |
299 | 'ext': 'wav', | |
f67ca84d JMF |
300 | }, |
301 | }, | |
d7c7100e S |
302 | # private link, downloadable format |
303 | { | |
304 | 'url': 'https://soundcloud.com/oriuplift/uponly-238-no-talking-wav/s-AyZUd', | |
305 | 'md5': '64a60b16e617d41d0bef032b7f55441e', | |
306 | 'info_dict': { | |
307 | 'id': '340344461', | |
308 | 'ext': 'wav', | |
309 | 'title': 'Uplifting Only 238 [No Talking] (incl. Alex Feed Guestmix) (Aug 31, 2017) [wav]', | |
310 | 'description': 'md5:fa20ee0fca76a3d6df8c7e57f3715366', | |
311 | 'uploader': 'Ori Uplift Music', | |
548c3957 | 312 | 'uploader_id': '12563093', |
f516f440 | 313 | 'timestamp': 1504206263, |
d7c7100e | 314 | 'upload_date': '20170831', |
e09965d5 | 315 | 'duration': 7449.096, |
d7c7100e | 316 | 'license': 'all-rights-reserved', |
f516f440 S |
317 | 'view_count': int, |
318 | 'like_count': int, | |
319 | 'comment_count': int, | |
320 | 'repost_count': int, | |
d7c7100e S |
321 | }, |
322 | }, | |
0b0870f9 PV |
323 | # no album art, use avatar pic for thumbnail |
324 | { | |
325 | 'url': 'https://soundcloud.com/garyvee/sideways-prod-mad-real', | |
326 | 'md5': '59c7872bc44e5d99b7211891664760c2', | |
327 | 'info_dict': { | |
328 | 'id': '309699954', | |
329 | 'ext': 'mp3', | |
330 | 'title': 'Sideways (Prod. Mad Real)', | |
331 | 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e', | |
332 | 'uploader': 'garyvee', | |
548c3957 | 333 | 'uploader_id': '2366352', |
f516f440 | 334 | 'timestamp': 1488152409, |
0b0870f9 | 335 | 'upload_date': '20170226', |
e09965d5 | 336 | 'duration': 207.012, |
0b0870f9 PV |
337 | 'thumbnail': r're:https?://.*\.jpg', |
338 | 'license': 'all-rights-reserved', | |
f516f440 S |
339 | 'view_count': int, |
340 | 'like_count': int, | |
341 | 'comment_count': int, | |
342 | 'repost_count': int, | |
0b0870f9 PV |
343 | }, |
344 | 'params': { | |
345 | 'skip_download': True, | |
346 | }, | |
347 | }, | |
e09965d5 S |
348 | { |
349 | 'url': 'https://soundcloud.com/giovannisarani/mezzo-valzer', | |
350 | 'md5': 'e22aecd2bc88e0e4e432d7dcc0a1abf7', | |
351 | 'info_dict': { | |
352 | 'id': '583011102', | |
353 | 'ext': 'mp3', | |
354 | 'title': 'Mezzo Valzer', | |
355 | 'description': 'md5:4138d582f81866a530317bae316e8b61', | |
2a5c26c9 | 356 | 'uploader': 'Micronie', |
548c3957 | 357 | 'uploader_id': '3352531', |
e09965d5 S |
358 | 'timestamp': 1551394171, |
359 | 'upload_date': '20190228', | |
360 | 'duration': 180.157, | |
361 | 'thumbnail': r're:https?://.*\.jpg', | |
362 | 'license': 'all-rights-reserved', | |
363 | 'view_count': int, | |
364 | 'like_count': int, | |
365 | 'comment_count': int, | |
366 | 'repost_count': int, | |
367 | }, | |
75294a5e S |
368 | }, |
369 | { | |
bc842c27 | 370 | # AAC HQ format available (account with active subscription needed) |
75294a5e S |
371 | 'url': 'https://soundcloud.com/wandw/the-chainsmokers-ft-daya-dont-let-me-down-ww-remix-1', |
372 | 'only_matching': True, | |
373 | }, | |
bc842c27 U |
374 | { |
375 | # Go+ (account with active subscription needed) | |
376 | 'url': 'https://soundcloud.com/taylorswiftofficial/look-what-you-made-me-do', | |
377 | 'only_matching': True, | |
378 | }, | |
12c167c8 | 379 | ] |
aad0d6d5 | 380 | |
548c3957 RA |
381 | _IMAGE_REPL_RE = r'-([0-9a-z]+)\.jpg' |
382 | ||
383 | _ARTWORK_MAP = { | |
384 | 'mini': 16, | |
385 | 'tiny': 20, | |
386 | 'small': 32, | |
387 | 'badge': 47, | |
388 | 't67x67': 67, | |
389 | 'large': 100, | |
390 | 't300x300': 300, | |
391 | 'crop': 400, | |
392 | 't500x500': 500, | |
393 | 'original': 0, | |
394 | } | |
fbdf8d15 | 395 | |
a6c5859d | 396 | def _extract_info_dict(self, info, full_title=None, secret_token=None): |
12c167c8 | 397 | track_id = compat_str(info['id']) |
f516f440 | 398 | title = info['title'] |
e09965d5 S |
399 | |
400 | format_urls = set() | |
5e114e4b | 401 | formats = [] |
73602bcd | 402 | query = {'client_id': self._CLIENT_ID} |
548c3957 | 403 | if secret_token: |
73602bcd | 404 | query['secret_token'] = secret_token |
548c3957 | 405 | |
2e9ad59a | 406 | if info.get('downloadable') and info.get('has_downloads_left'): |
a6c5859d RA |
407 | download_url = update_url_query( |
408 | self._API_V2_BASE + 'tracks/' + track_id + '/download', query) | |
409 | redirect_url = (self._download_json(download_url, track_id, fatal=False) or {}).get('redirectUri') | |
410 | if redirect_url: | |
411 | urlh = self._request_webpage( | |
412 | HEADRequest(redirect_url), track_id, fatal=False) | |
413 | if urlh: | |
414 | format_url = urlh.geturl() | |
415 | format_urls.add(format_url) | |
416 | formats.append({ | |
417 | 'format_id': 'download', | |
418 | 'ext': urlhandle_detect_ext(urlh) or 'mp3', | |
419 | 'filesize': int_or_none(urlh.headers.get('Content-Length')), | |
420 | 'url': format_url, | |
f983b875 | 421 | 'quality': 10, |
a6c5859d | 422 | }) |
5e114e4b | 423 | |
548c3957 | 424 | def invalid_url(url): |
e4e5fa6e | 425 | return not url or url in format_urls |
e09965d5 | 426 | |
e4e5fa6e | 427 | def add_format(f, protocol, is_preview=False): |
548c3957 RA |
428 | mobj = re.search(r'\.(?P<abr>\d+)\.(?P<ext>[0-9a-z]{3,4})(?=[/?])', stream_url) |
429 | if mobj: | |
430 | for k, v in mobj.groupdict().items(): | |
431 | if not f.get(k): | |
432 | f[k] = v | |
433 | format_id_list = [] | |
434 | if protocol: | |
435 | format_id_list.append(protocol) | |
75294a5e S |
436 | ext = f.get('ext') |
437 | if ext == 'aac': | |
b9e5f872 | 438 | f['abr'] = '256' |
548c3957 RA |
439 | for k in ('ext', 'abr'): |
440 | v = f.get(k) | |
441 | if v: | |
442 | format_id_list.append(v) | |
e4e5fa6e S |
443 | preview = is_preview or re.search(r'/(?:preview|playlist)/0/30/', f['url']) |
444 | if preview: | |
445 | format_id_list.append('preview') | |
548c3957 RA |
446 | abr = f.get('abr') |
447 | if abr: | |
448 | f['abr'] = int(abr) | |
75294a5e S |
449 | if protocol == 'hls': |
450 | protocol = 'm3u8' if ext == 'aac' else 'm3u8_native' | |
451 | else: | |
452 | protocol = 'http' | |
548c3957 RA |
453 | f.update({ |
454 | 'format_id': '_'.join(format_id_list), | |
75294a5e | 455 | 'protocol': protocol, |
e4e5fa6e | 456 | 'preference': -10 if preview else None, |
548c3957 RA |
457 | }) |
458 | formats.append(f) | |
e09965d5 S |
459 | |
460 | # New API | |
461 | transcodings = try_get( | |
462 | info, lambda x: x['media']['transcodings'], list) or [] | |
463 | for t in transcodings: | |
464 | if not isinstance(t, dict): | |
3a194cb4 | 465 | continue |
e09965d5 | 466 | format_url = url_or_none(t.get('url')) |
e4e5fa6e | 467 | if not format_url: |
e09965d5 S |
468 | continue |
469 | stream = self._download_json( | |
fb4126a1 | 470 | format_url, track_id, query=query, fatal=False, headers=self._HEADERS) |
e09965d5 S |
471 | if not isinstance(stream, dict): |
472 | continue | |
473 | stream_url = url_or_none(stream.get('url')) | |
548c3957 | 474 | if invalid_url(stream_url): |
e09965d5 S |
475 | continue |
476 | format_urls.add(stream_url) | |
548c3957 RA |
477 | stream_format = t.get('format') or {} |
478 | protocol = stream_format.get('protocol') | |
e09965d5 S |
479 | if protocol != 'hls' and '/hls' in format_url: |
480 | protocol = 'hls' | |
481 | ext = None | |
482 | preset = str_or_none(t.get('preset')) | |
483 | if preset: | |
484 | ext = preset.split('_')[0] | |
548c3957 RA |
485 | if ext not in KNOWN_EXTENSIONS: |
486 | ext = mimetype2ext(stream_format.get('mime_type')) | |
487 | add_format({ | |
e09965d5 | 488 | 'url': stream_url, |
e09965d5 | 489 | 'ext': ext, |
e4e5fa6e S |
490 | }, 'http' if protocol == 'progressive' else protocol, |
491 | t.get('snipped') or '/preview/' in format_url) | |
548c3957 | 492 | |
3a194cb4 S |
493 | for f in formats: |
494 | f['vcodec'] = 'none' | |
2a15e706 | 495 | |
a6c5859d | 496 | if not formats and info.get('policy') == 'BLOCK': |
b7da73eb | 497 | self.raise_geo_restricted(metadata_available=True) |
562ceab1 | 498 | self._sort_formats(formats) |
64bb5187 | 499 | |
548c3957 RA |
500 | user = info.get('user') or {} |
501 | ||
502 | thumbnails = [] | |
503 | artwork_url = info.get('artwork_url') | |
504 | thumbnail = artwork_url or user.get('avatar_url') | |
505 | if isinstance(thumbnail, compat_str): | |
506 | if re.search(self._IMAGE_REPL_RE, thumbnail): | |
507 | for image_id, size in self._ARTWORK_MAP.items(): | |
508 | i = { | |
509 | 'id': image_id, | |
510 | 'url': re.sub(self._IMAGE_REPL_RE, '-%s.jpg' % image_id, thumbnail), | |
511 | } | |
512 | if image_id == 'tiny' and not artwork_url: | |
513 | size = 18 | |
514 | elif image_id == 'original': | |
515 | i['preference'] = 10 | |
516 | if size: | |
517 | i.update({ | |
518 | 'width': size, | |
519 | 'height': size, | |
520 | }) | |
521 | thumbnails.append(i) | |
522 | else: | |
523 | thumbnails = [{'url': thumbnail}] | |
524 | ||
525 | def extract_count(key): | |
526 | return int_or_none(info.get('%s_count' % key)) | |
527 | ||
528 | return { | |
529 | 'id': track_id, | |
530 | 'uploader': user.get('username'), | |
531 | 'uploader_id': str_or_none(user.get('id')) or user.get('permalink'), | |
532 | 'uploader_url': user.get('permalink_url'), | |
533 | 'timestamp': unified_timestamp(info.get('created_at')), | |
534 | 'title': title, | |
535 | 'description': info.get('description'), | |
536 | 'thumbnails': thumbnails, | |
537 | 'duration': float_or_none(info.get('duration'), 1000), | |
538 | 'webpage_url': info.get('permalink_url'), | |
539 | 'license': info.get('license'), | |
540 | 'view_count': extract_count('playback'), | |
541 | 'like_count': extract_count('favoritings') or extract_count('likes'), | |
542 | 'comment_count': extract_count('comment'), | |
543 | 'repost_count': extract_count('reposts'), | |
544 | 'genre': info.get('genre'), | |
545 | 'formats': formats | |
546 | } | |
7d239269 | 547 | |
aad0d6d5 | 548 | def _real_extract(self, url): |
5ad28e7f | 549 | mobj = self._match_valid_url(url) |
aad0d6d5 | 550 | |
eb6a41ba | 551 | track_id = mobj.group('track_id') |
4bfd294e | 552 | |
3bed6217 | 553 | query = {} |
548c3957 RA |
554 | if track_id: |
555 | info_json_url = self._API_V2_BASE + 'tracks/' + track_id | |
eb6a41ba | 556 | full_title = track_id |
9296738f | 557 | token = mobj.group('secret_token') |
558 | if token: | |
548c3957 | 559 | query['secret_token'] = token |
eb6a41ba | 560 | else: |
548c3957 | 561 | full_title = resolve_title = '%s/%s' % mobj.group('uploader', 'title') |
de2dd4c5 | 562 | token = mobj.group('token') |
de2dd4c5 JMF |
563 | if token: |
564 | resolve_title += '/%s' % token | |
548c3957 | 565 | info_json_url = self._resolv_url(self._BASE_URL + resolve_title) |
5f6a1245 | 566 | |
e09965d5 | 567 | info = self._download_json( |
fb4126a1 | 568 | info_json_url, full_title, 'Downloading info JSON', query=query, headers=self._HEADERS) |
a6c5859d RA |
569 | |
570 | return self._extract_info_dict(info, full_title, token) | |
aad0d6d5 | 571 | |
20991253 | 572 | |
63ccf4ff | 573 | class SoundcloudPlaylistBaseIE(SoundcloudBaseIE): |
2a5c26c9 RA |
574 | def _extract_set(self, playlist, token=None): |
575 | playlist_id = compat_str(playlist['id']) | |
576 | tracks = playlist.get('tracks') or [] | |
577 | if not all([t.get('permalink_url') for t in tracks]) and token: | |
578 | tracks = self._download_json( | |
579 | self._API_V2_BASE + 'tracks', playlist_id, | |
580 | 'Downloading tracks', query={ | |
581 | 'ids': ','.join([compat_str(t['id']) for t in tracks]), | |
582 | 'playlistId': playlist_id, | |
583 | 'playlistSecretToken': token, | |
fb4126a1 | 584 | }, headers=self._HEADERS) |
548c3957 RA |
585 | entries = [] |
586 | for track in tracks: | |
587 | track_id = str_or_none(track.get('id')) | |
588 | url = track.get('permalink_url') | |
589 | if not url: | |
590 | if not track_id: | |
591 | continue | |
592 | url = self._API_V2_BASE + 'tracks/' + track_id | |
593 | if token: | |
594 | url += '?secret_token=' + token | |
595 | entries.append(self.url_result( | |
596 | url, SoundcloudIE.ie_key(), track_id)) | |
2a5c26c9 RA |
597 | return self.playlist_result( |
598 | entries, playlist_id, | |
599 | playlist.get('title'), | |
600 | playlist.get('description')) | |
8e45e1cc S |
601 | |
602 | ||
7518a61d | 603 | class SoundcloudSetIE(SoundcloudPlaylistBaseIE): |
906f980a | 604 | _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<uploader>[\w\d-]+)/sets/(?P<slug_title>[:\w\d-]+)(?:/(?P<token>[^?/]+))?' |
fbcd7b5f | 605 | IE_NAME = 'soundcloud:set' |
22a6f150 PH |
606 | _TESTS = [{ |
607 | 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep', | |
608 | 'info_dict': { | |
a9551e90 | 609 | 'id': '2284613', |
22a6f150 | 610 | 'title': 'The Royal Concept EP', |
2a5c26c9 | 611 | 'description': 'md5:71d07087c7a449e8941a70a29e34671e', |
22a6f150 | 612 | }, |
bf2dc9cc | 613 | 'playlist_mincount': 5, |
f7043ef3 S |
614 | }, { |
615 | 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep/token', | |
616 | 'only_matching': True, | |
906f980a U |
617 | }, { |
618 | 'url': 'https://soundcloud.com/discover/sets/weekly::flacmatic', | |
619 | 'only_matching': True, | |
620 | }, { | |
621 | 'url': 'https://soundcloud.com/discover/sets/charts-top:all-music:de', | |
622 | 'only_matching': True, | |
623 | }, { | |
624 | 'url': 'https://soundcloud.com/discover/sets/charts-top:hiphoprap:kr', | |
625 | 'only_matching': True, | |
22a6f150 | 626 | }] |
aad0d6d5 | 627 | |
aad0d6d5 | 628 | def _real_extract(self, url): |
5ad28e7f | 629 | mobj = self._match_valid_url(url) |
aad0d6d5 | 630 | |
548c3957 | 631 | full_title = '%s/sets/%s' % mobj.group('uploader', 'slug_title') |
2f834e93 | 632 | token = mobj.group('token') |
633 | if token: | |
634 | full_title += '/' + token | |
aad0d6d5 | 635 | |
548c3957 | 636 | info = self._download_json(self._resolv_url( |
fb4126a1 | 637 | self._BASE_URL + full_title), full_title, headers=self._HEADERS) |
aad0d6d5 | 638 | |
aad0d6d5 | 639 | if 'errors' in info: |
214e74bf JMF |
640 | msgs = (compat_str(err['error_message']) for err in info['errors']) |
641 | raise ExtractorError('unable to download video webpage: %s' % ','.join(msgs)) | |
aad0d6d5 | 642 | |
2a5c26c9 | 643 | return self._extract_set(info, token) |
92790f4e JMF |
644 | |
645 | ||
63ccf4ff | 646 | class SoundcloudPagedPlaylistBaseIE(SoundcloudBaseIE): |
836ef264 | 647 | def _extract_playlist(self, base_url, playlist_id, playlist_title): |
aa6c2530 | 648 | return { |
649 | '_type': 'playlist', | |
650 | 'id': playlist_id, | |
651 | 'title': playlist_title, | |
652 | 'entries': self._entries(base_url, playlist_id), | |
653 | } | |
654 | ||
e04a1ff9 | 655 | def _entries(self, url, playlist_id): |
a0566bbf | 656 | # Per the SoundCloud documentation, the maximum limit for a linked partitioning query is 200. |
aa272535 | 657 | # https://developers.soundcloud.com/blog/offset-pagination-deprecated |
aa6c2530 | 658 | query = { |
38970916 | 659 | 'limit': 200, |
836ef264 | 660 | 'linked_partitioning': '1', |
aa6c2530 | 661 | 'offset': 0, |
836ef264 S |
662 | } |
663 | ||
e04a1ff9 | 664 | retries = self.get_param('extractor_retries', 3) |
836ef264 | 665 | |
836ef264 | 666 | for i in itertools.count(): |
e04a1ff9 | 667 | attempt, last_error = -1, None |
668 | while attempt < retries: | |
669 | attempt += 1 | |
670 | if last_error: | |
671 | self.report_warning('%s. Retrying ...' % remove_end(last_error, '.'), playlist_id) | |
672 | try: | |
673 | response = self._download_json( | |
674 | url, playlist_id, query=query, headers=self._HEADERS, | |
675 | note='Downloading track page %s%s' % (i + 1, f' (retry #{attempt})' if attempt else '')) | |
676 | break | |
677 | except ExtractorError as e: | |
678 | # Downloading page may result in intermittent 502 HTTP error | |
679 | # See https://github.com/yt-dlp/yt-dlp/issues/872 | |
680 | if attempt >= retries or not isinstance(e.cause, compat_HTTPError) or e.cause.code != 502: | |
681 | raise | |
682 | last_error = str(e.cause or e.msg) | |
836ef264 | 683 | |
aa6c2530 | 684 | def resolve_entry(*candidates): |
7c5307f4 S |
685 | for cand in candidates: |
686 | if not isinstance(cand, dict): | |
687 | continue | |
688 | permalink_url = url_or_none(cand.get('permalink_url')) | |
aa6c2530 | 689 | if permalink_url: |
690 | return self.url_result( | |
691 | permalink_url, | |
692 | SoundcloudIE.ie_key() if SoundcloudIE.suitable(permalink_url) else None, | |
693 | str_or_none(cand.get('id')), cand.get('title')) | |
836ef264 | 694 | |
aa6c2530 | 695 | for e in response['collection'] or []: |
696 | yield resolve_entry(e, e.get('track'), e.get('playlist')) | |
836ef264 | 697 | |
e04a1ff9 | 698 | url = response.get('next_href') |
644149af | 699 | if not url: |
700 | break | |
aa6c2530 | 701 | query.pop('offset', None) |
836ef264 | 702 | |
836ef264 | 703 | |
836ef264 | 704 | class SoundcloudUserIE(SoundcloudPagedPlaylistBaseIE): |
16a08978 S |
705 | _VALID_URL = r'''(?x) |
706 | https?:// | |
707 | (?:(?:www|m)\.)?soundcloud\.com/ | |
708 | (?P<user>[^/]+) | |
709 | (?:/ | |
3ef2da2d | 710 | (?P<rsrc>tracks|albums|sets|reposts|likes|spotlight) |
16a08978 S |
711 | )? |
712 | /?(?:[?#].*)?$ | |
713 | ''' | |
fbcd7b5f | 714 | IE_NAME = 'soundcloud:user' |
22a6f150 | 715 | _TESTS = [{ |
b6423e6c | 716 | 'url': 'https://soundcloud.com/soft-cell-official', |
22a6f150 | 717 | 'info_dict': { |
b6423e6c S |
718 | 'id': '207965082', |
719 | 'title': 'Soft Cell (All)', | |
22a6f150 | 720 | }, |
b6423e6c | 721 | 'playlist_mincount': 28, |
22a6f150 | 722 | }, { |
b6423e6c | 723 | 'url': 'https://soundcloud.com/soft-cell-official/tracks', |
22a6f150 | 724 | 'info_dict': { |
b6423e6c S |
725 | 'id': '207965082', |
726 | 'title': 'Soft Cell (Tracks)', | |
22a6f150 | 727 | }, |
b6423e6c | 728 | 'playlist_mincount': 27, |
03b9c944 | 729 | }, { |
b6423e6c S |
730 | 'url': 'https://soundcloud.com/soft-cell-official/albums', |
731 | 'info_dict': { | |
732 | 'id': '207965082', | |
733 | 'title': 'Soft Cell (Albums)', | |
734 | }, | |
735 | 'playlist_mincount': 1, | |
736 | }, { | |
737 | 'url': 'https://soundcloud.com/jcv246/sets', | |
80fb6d4a | 738 | 'info_dict': { |
b6423e6c | 739 | 'id': '12982173', |
548c3957 | 740 | 'title': 'Jordi / cv (Sets)', |
80fb6d4a | 741 | }, |
8e45e1cc | 742 | 'playlist_mincount': 2, |
80fb6d4a | 743 | }, { |
b6423e6c | 744 | 'url': 'https://soundcloud.com/jcv246/reposts', |
80fb6d4a | 745 | 'info_dict': { |
b6423e6c S |
746 | 'id': '12982173', |
747 | 'title': 'Jordi / cv (Reposts)', | |
80fb6d4a | 748 | }, |
b6423e6c | 749 | 'playlist_mincount': 6, |
80fb6d4a | 750 | }, { |
b6423e6c | 751 | 'url': 'https://soundcloud.com/clalberg/likes', |
80fb6d4a | 752 | 'info_dict': { |
b6423e6c S |
753 | 'id': '11817582', |
754 | 'title': 'clalberg (Likes)', | |
80fb6d4a | 755 | }, |
b6423e6c | 756 | 'playlist_mincount': 5, |
80fb6d4a S |
757 | }, { |
758 | 'url': 'https://soundcloud.com/grynpyret/spotlight', | |
759 | 'info_dict': { | |
760 | 'id': '7098329', | |
bf2dc9cc | 761 | 'title': 'Grynpyret (Spotlight)', |
80fb6d4a S |
762 | }, |
763 | 'playlist_mincount': 1, | |
22a6f150 | 764 | }] |
92790f4e | 765 | |
80fb6d4a | 766 | _BASE_URL_MAP = { |
548c3957 RA |
767 | 'all': 'stream/users/%s', |
768 | 'tracks': 'users/%s/tracks', | |
769 | 'albums': 'users/%s/albums', | |
770 | 'sets': 'users/%s/playlists', | |
771 | 'reposts': 'stream/users/%s/reposts', | |
772 | 'likes': 'users/%s/likes', | |
773 | 'spotlight': 'users/%s/spotlight', | |
80fb6d4a S |
774 | } |
775 | ||
92790f4e | 776 | def _real_extract(self, url): |
5ad28e7f | 777 | mobj = self._match_valid_url(url) |
92790f4e JMF |
778 | uploader = mobj.group('user') |
779 | ||
20991253 | 780 | user = self._download_json( |
548c3957 | 781 | self._resolv_url(self._BASE_URL + uploader), |
fb4126a1 | 782 | uploader, 'Downloading user info', headers=self._HEADERS) |
80fb6d4a S |
783 | |
784 | resource = mobj.group('rsrc') or 'all' | |
80fb6d4a | 785 | |
836ef264 | 786 | return self._extract_playlist( |
548c3957 RA |
787 | self._API_V2_BASE + self._BASE_URL_MAP[resource] % user['id'], |
788 | str_or_none(user.get('id')), | |
789 | '%s (%s)' % (user['username'], resource.capitalize())) | |
97afd99a | 790 | |
92790f4e | 791 | |
836ef264 S |
792 | class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE): |
793 | _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)' | |
794 | IE_NAME = 'soundcloud:trackstation' | |
795 | _TESTS = [{ | |
796 | 'url': 'https://soundcloud.com/stations/track/officialsundial/your-text', | |
797 | 'info_dict': { | |
798 | 'id': '286017854', | |
548c3957 | 799 | 'title': 'Track station: your text', |
836ef264 S |
800 | }, |
801 | 'playlist_mincount': 47, | |
802 | }] | |
80fb6d4a | 803 | |
836ef264 S |
804 | def _real_extract(self, url): |
805 | track_name = self._match_id(url) | |
80fb6d4a | 806 | |
fb4126a1 | 807 | track = self._download_json(self._resolv_url(url), track_name, headers=self._HEADERS) |
836ef264 | 808 | track_id = self._search_regex( |
548c3957 | 809 | r'soundcloud:track-stations:(\d+)', track['id'], 'track id') |
92790f4e | 810 | |
836ef264 | 811 | return self._extract_playlist( |
548c3957 RA |
812 | self._API_V2_BASE + 'stations/%s/tracks' % track['id'], |
813 | track_id, 'Track station: %s' % track['title']) | |
20991253 PH |
814 | |
815 | ||
c2dedf12 L |
816 | class SoundcloudRelatedIE(SoundcloudPagedPlaylistBaseIE): |
817 | _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<slug>[\w\d-]+/[\w\d-]+)/(?P<relation>albums|sets|recommended)' | |
818 | IE_NAME = 'soundcloud:related' | |
819 | _TESTS = [{ | |
820 | 'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/recommended', | |
821 | 'info_dict': { | |
822 | 'id': '1084577272', | |
823 | 'title': 'Sexapil - Pingers 5 (Recommended)', | |
824 | }, | |
825 | 'playlist_mincount': 50, | |
826 | }, { | |
827 | 'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/albums', | |
828 | 'info_dict': { | |
829 | 'id': '1084577272', | |
830 | 'title': 'Sexapil - Pingers 5 (Albums)', | |
831 | }, | |
832 | 'playlist_mincount': 1, | |
833 | }, { | |
834 | 'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/sets', | |
835 | 'info_dict': { | |
836 | 'id': '1084577272', | |
837 | 'title': 'Sexapil - Pingers 5 (Sets)', | |
838 | }, | |
839 | 'playlist_mincount': 4, | |
840 | }] | |
841 | ||
842 | _BASE_URL_MAP = { | |
843 | 'albums': 'tracks/%s/albums', | |
844 | 'sets': 'tracks/%s/playlists_without_albums', | |
845 | 'recommended': 'tracks/%s/related', | |
846 | } | |
847 | ||
848 | def _real_extract(self, url): | |
849 | slug, relation = self._match_valid_url(url).group('slug', 'relation') | |
850 | ||
851 | track = self._download_json( | |
852 | self._resolv_url(self._BASE_URL + slug), | |
853 | slug, 'Downloading track info', headers=self._HEADERS) | |
854 | ||
855 | if track.get('errors'): | |
856 | raise ExtractorError(f'{self.IE_NAME} said: %s' % ','.join( | |
857 | str(err['error_message']) for err in track['errors']), expected=True) | |
858 | ||
859 | return self._extract_playlist( | |
860 | self._API_V2_BASE + self._BASE_URL_MAP[relation] % track['id'], str(track['id']), | |
861 | '%s (%s)' % (track.get('title') or slug, relation.capitalize())) | |
862 | ||
863 | ||
7518a61d | 864 | class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE): |
548c3957 | 865 | _VALID_URL = r'https?://api(?:-v2)?\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$' |
20991253 | 866 | IE_NAME = 'soundcloud:playlist' |
46f74bcf | 867 | _TESTS = [{ |
f1c05100 | 868 | 'url': 'https://api.soundcloud.com/playlists/4110309', |
46f74bcf PH |
869 | 'info_dict': { |
870 | 'id': '4110309', | |
871 | 'title': 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]', | |
872 | 'description': 're:.*?TILT Brass - Bowery Poetry Club', | |
873 | }, | |
874 | 'playlist_count': 6, | |
875 | }] | |
20991253 PH |
876 | |
877 | def _real_extract(self, url): | |
5ad28e7f | 878 | mobj = self._match_valid_url(url) |
20991253 | 879 | playlist_id = mobj.group('id') |
20991253 | 880 | |
3bed6217 | 881 | query = {} |
2f834e93 | 882 | token = mobj.group('token') |
2f834e93 | 883 | if token: |
548c3957 | 884 | query['secret_token'] = token |
2f834e93 | 885 | |
20991253 | 886 | data = self._download_json( |
548c3957 | 887 | self._API_V2_BASE + 'playlists/' + playlist_id, |
fb4126a1 | 888 | playlist_id, 'Downloading playlist', query=query, headers=self._HEADERS) |
20991253 | 889 | |
2a5c26c9 | 890 | return self._extract_set(data, token) |
2abf7cab | 891 | |
892 | ||
63ccf4ff | 893 | class SoundcloudSearchIE(SoundcloudBaseIE, SearchInfoExtractor): |
2abf7cab | 894 | IE_NAME = 'soundcloud:search' |
96565c7e | 895 | IE_DESC = 'Soundcloud search' |
896 | _SEARCH_KEY = 'scsearch' | |
2abf7cab | 897 | _TESTS = [{ |
898 | 'url': 'scsearch15:post-avant jazzcore', | |
899 | 'info_dict': { | |
900 | 'title': 'post-avant jazzcore', | |
901 | }, | |
902 | 'playlist_count': 15, | |
903 | }] | |
904 | ||
328a22e1 | 905 | _MAX_RESULTS_PER_PAGE = 200 |
906 | _DEFAULT_RESULTS_PER_PAGE = 50 | |
2abf7cab | 907 | |
908 | def _get_collection(self, endpoint, collection_id, **query): | |
a3372437 | 909 | limit = min( |
328a22e1 | 910 | query.get('limit', self._DEFAULT_RESULTS_PER_PAGE), |
911 | self._MAX_RESULTS_PER_PAGE) | |
548c3957 RA |
912 | query.update({ |
913 | 'limit': limit, | |
548c3957 RA |
914 | 'linked_partitioning': 1, |
915 | 'offset': 0, | |
916 | }) | |
917 | next_url = update_url_query(self._API_V2_BASE + endpoint, query) | |
2abf7cab | 918 | |
f6c903e7 | 919 | for i in itertools.count(1): |
7e347275 | 920 | response = self._download_json( |
cc16383f | 921 | next_url, collection_id, f'Downloading page {i}', |
fb4126a1 | 922 | 'Unable to download API page', headers=self._HEADERS) |
2abf7cab | 923 | |
cc16383f | 924 | for item in response.get('collection') or []: |
925 | if item: | |
926 | yield self.url_result(item['uri'], SoundcloudIE.ie_key()) | |
2abf7cab | 927 | |
7e347275 | 928 | next_url = response.get('next_href') |
f6c903e7 S |
929 | if not next_url: |
930 | break | |
2abf7cab | 931 | |
932 | def _get_n_results(self, query, n): | |
8863c8f0 | 933 | return self.playlist_result(itertools.islice( |
934 | self._get_collection('search/tracks', query, limit=n, q=query), | |
935 | 0, None if n == float('inf') else n), query, query) |