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