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