You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

634 lines
23 KiB

10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. from .common import (
  6. InfoExtractor,
  7. SearchInfoExtractor
  8. )
  9. from ..compat import (
  10. compat_str,
  11. compat_urlparse,
  12. compat_urllib_parse_urlencode,
  13. )
  14. from ..utils import (
  15. ExtractorError,
  16. int_or_none,
  17. unified_strdate,
  18. update_url_query,
  19. )
  20. class SoundcloudIE(InfoExtractor):
  21. """Information extractor for soundcloud.com
  22. To access the media, the uid of the song and a stream token
  23. must be extracted from the page source and the script must make
  24. a request to media.soundcloud.com/crossdomain.xml. Then
  25. the media can be grabbed by requesting from an url composed
  26. of the stream token and uid
  27. """
  28. _VALID_URL = r'''(?x)^(?:https?://)?
  29. (?:(?:(?:www\.|m\.)?soundcloud\.com/
  30. (?!stations/track)
  31. (?P<uploader>[\w\d-]+)/
  32. (?!(?:tracks|sets(?:/.+?)?|reposts|likes|spotlight)/?(?:$|[?#]))
  33. (?P<title>[\w\d-]+)/?
  34. (?P<token>[^?]+?)?(?:[?].*)?$)
  35. |(?:api\.soundcloud\.com/tracks/(?P<track_id>\d+)
  36. (?:/?\?secret_token=(?P<secret_token>[^&]+))?)
  37. |(?P<player>(?:w|player|p.)\.soundcloud\.com/player/?.*?url=.*)
  38. )
  39. '''
  40. IE_NAME = 'soundcloud'
  41. _TESTS = [
  42. {
  43. 'url': 'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy',
  44. 'md5': 'ebef0a451b909710ed1d7787dddbf0d7',
  45. 'info_dict': {
  46. 'id': '62986583',
  47. 'ext': 'mp3',
  48. 'upload_date': '20121011',
  49. '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',
  50. 'uploader': 'E.T. ExTerrestrial Music',
  51. 'title': 'Lostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1',
  52. 'duration': 143,
  53. 'license': 'all-rights-reserved',
  54. }
  55. },
  56. # not streamable song
  57. {
  58. 'url': 'https://soundcloud.com/the-concept-band/goldrushed-mastered?in=the-concept-band/sets/the-royal-concept-ep',
  59. 'info_dict': {
  60. 'id': '47127627',
  61. 'ext': 'mp3',
  62. 'title': 'Goldrushed',
  63. 'description': 'From Stockholm Sweden\r\nPovel / Magnus / Filip / David\r\nwww.theroyalconcept.com',
  64. 'uploader': 'The Royal Concept',
  65. 'upload_date': '20120521',
  66. 'duration': 227,
  67. 'license': 'all-rights-reserved',
  68. },
  69. 'params': {
  70. # rtmp
  71. 'skip_download': True,
  72. },
  73. },
  74. # private link
  75. {
  76. 'url': 'https://soundcloud.com/jaimemf/youtube-dl-test-video-a-y-baw/s-8Pjrp',
  77. 'md5': 'aa0dd32bfea9b0c5ef4f02aacd080604',
  78. 'info_dict': {
  79. 'id': '123998367',
  80. 'ext': 'mp3',
  81. 'title': 'Youtube - Dl Test Video \'\' Ä↭',
  82. 'uploader': 'jaimeMF',
  83. 'description': 'test chars: \"\'/\\ä↭',
  84. 'upload_date': '20131209',
  85. 'duration': 9,
  86. 'license': 'all-rights-reserved',
  87. },
  88. },
  89. # private link (alt format)
  90. {
  91. 'url': 'https://api.soundcloud.com/tracks/123998367?secret_token=s-8Pjrp',
  92. 'md5': 'aa0dd32bfea9b0c5ef4f02aacd080604',
  93. 'info_dict': {
  94. 'id': '123998367',
  95. 'ext': 'mp3',
  96. 'title': 'Youtube - Dl Test Video \'\' Ä↭',
  97. 'uploader': 'jaimeMF',
  98. 'description': 'test chars: \"\'/\\ä↭',
  99. 'upload_date': '20131209',
  100. 'duration': 9,
  101. 'license': 'all-rights-reserved',
  102. },
  103. },
  104. # downloadable song
  105. {
  106. 'url': 'https://soundcloud.com/oddsamples/bus-brakes',
  107. 'md5': '7624f2351f8a3b2e7cd51522496e7631',
  108. 'info_dict': {
  109. 'id': '128590877',
  110. 'ext': 'mp3',
  111. 'title': 'Bus Brakes',
  112. 'description': 'md5:0053ca6396e8d2fd7b7e1595ef12ab66',
  113. 'uploader': 'oddsamples',
  114. 'upload_date': '20140109',
  115. 'duration': 17,
  116. 'license': 'cc-by-sa',
  117. },
  118. },
  119. # private link, downloadable format
  120. {
  121. 'url': 'https://soundcloud.com/oriuplift/uponly-238-no-talking-wav/s-AyZUd',
  122. 'md5': '64a60b16e617d41d0bef032b7f55441e',
  123. 'info_dict': {
  124. 'id': '340344461',
  125. 'ext': 'wav',
  126. 'title': 'Uplifting Only 238 [No Talking] (incl. Alex Feed Guestmix) (Aug 31, 2017) [wav]',
  127. 'description': 'md5:fa20ee0fca76a3d6df8c7e57f3715366',
  128. 'uploader': 'Ori Uplift Music',
  129. 'upload_date': '20170831',
  130. 'duration': 7449,
  131. 'license': 'all-rights-reserved',
  132. },
  133. },
  134. # no album art, use avatar pic for thumbnail
  135. {
  136. 'url': 'https://soundcloud.com/garyvee/sideways-prod-mad-real',
  137. 'md5': '59c7872bc44e5d99b7211891664760c2',
  138. 'info_dict': {
  139. 'id': '309699954',
  140. 'ext': 'mp3',
  141. 'title': 'Sideways (Prod. Mad Real)',
  142. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  143. 'uploader': 'garyvee',
  144. 'upload_date': '20170226',
  145. 'duration': 207,
  146. 'thumbnail': r're:https?://.*\.jpg',
  147. 'license': 'all-rights-reserved',
  148. },
  149. 'params': {
  150. 'skip_download': True,
  151. },
  152. },
  153. ]
  154. _CLIENT_ID = 'c6CU49JDMapyrQo06UxU9xouB9ZVzqCn'
  155. _IPHONE_CLIENT_ID = '376f225bf427445fc4bfb6b99b72e0bf'
  156. @staticmethod
  157. def _extract_urls(webpage):
  158. return [m.group('url') for m in re.finditer(
  159. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?(?:w\.)?soundcloud\.com/player.+?)\1',
  160. webpage)]
  161. def report_resolve(self, video_id):
  162. """Report information extraction."""
  163. self.to_screen('%s: Resolving id' % video_id)
  164. @classmethod
  165. def _resolv_url(cls, url):
  166. return 'https://api.soundcloud.com/resolve.json?url=' + url + '&client_id=' + cls._CLIENT_ID
  167. def _extract_info_dict(self, info, full_title=None, quiet=False, secret_token=None):
  168. track_id = compat_str(info['id'])
  169. name = full_title or track_id
  170. if quiet:
  171. self.report_extraction(name)
  172. thumbnail = info.get('artwork_url') or info.get('user', {}).get('avatar_url')
  173. if isinstance(thumbnail, compat_str):
  174. thumbnail = thumbnail.replace('-large', '-t500x500')
  175. ext = 'mp3'
  176. result = {
  177. 'id': track_id,
  178. 'uploader': info.get('user', {}).get('username'),
  179. 'upload_date': unified_strdate(info.get('created_at')),
  180. 'title': info['title'],
  181. 'description': info.get('description'),
  182. 'thumbnail': thumbnail,
  183. 'duration': int_or_none(info.get('duration'), 1000),
  184. 'webpage_url': info.get('permalink_url'),
  185. 'license': info.get('license'),
  186. }
  187. formats = []
  188. query = {'client_id': self._CLIENT_ID}
  189. if secret_token is not None:
  190. query['secret_token'] = secret_token
  191. if info.get('downloadable', False):
  192. # We can build a direct link to the song
  193. format_url = update_url_query(
  194. 'https://api.soundcloud.com/tracks/%s/download' % track_id, query)
  195. formats.append({
  196. 'format_id': 'download',
  197. 'ext': info.get('original_format', 'mp3'),
  198. 'url': format_url,
  199. 'vcodec': 'none',
  200. 'preference': 10,
  201. })
  202. # We have to retrieve the url
  203. format_dict = self._download_json(
  204. 'https://api.soundcloud.com/i1/tracks/%s/streams' % track_id,
  205. track_id, 'Downloading track url', query=query)
  206. for key, stream_url in format_dict.items():
  207. abr = int_or_none(self._search_regex(
  208. r'_(\d+)_url', key, 'audio bitrate', default=None))
  209. if key.startswith('http'):
  210. stream_formats = [{
  211. 'format_id': key,
  212. 'ext': ext,
  213. 'url': stream_url,
  214. }]
  215. elif key.startswith('rtmp'):
  216. # The url doesn't have an rtmp app, we have to extract the playpath
  217. url, path = stream_url.split('mp3:', 1)
  218. stream_formats = [{
  219. 'format_id': key,
  220. 'url': url,
  221. 'play_path': 'mp3:' + path,
  222. 'ext': 'flv',
  223. }]
  224. elif key.startswith('hls'):
  225. stream_formats = self._extract_m3u8_formats(
  226. stream_url, track_id, 'mp3', entry_protocol='m3u8_native',
  227. m3u8_id=key, fatal=False)
  228. else:
  229. continue
  230. for f in stream_formats:
  231. f['abr'] = abr
  232. formats.extend(stream_formats)
  233. if not formats:
  234. # We fallback to the stream_url in the original info, this
  235. # cannot be always used, sometimes it can give an HTTP 404 error
  236. formats.append({
  237. 'format_id': 'fallback',
  238. 'url': update_url_query(info['stream_url'], query),
  239. 'ext': ext,
  240. })
  241. for f in formats:
  242. f['vcodec'] = 'none'
  243. self._check_formats(formats, track_id)
  244. self._sort_formats(formats)
  245. result['formats'] = formats
  246. return result
  247. def _real_extract(self, url):
  248. mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
  249. if mobj is None:
  250. raise ExtractorError('Invalid URL: %s' % url)
  251. track_id = mobj.group('track_id')
  252. if track_id is not None:
  253. info_json_url = 'https://api.soundcloud.com/tracks/' + track_id + '.json?client_id=' + self._CLIENT_ID
  254. full_title = track_id
  255. token = mobj.group('secret_token')
  256. if token:
  257. info_json_url += '&secret_token=' + token
  258. elif mobj.group('player'):
  259. query = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  260. real_url = query['url'][0]
  261. # If the token is in the query of the original url we have to
  262. # manually add it
  263. if 'secret_token' in query:
  264. real_url += '?secret_token=' + query['secret_token'][0]
  265. return self.url_result(real_url)
  266. else:
  267. # extract uploader (which is in the url)
  268. uploader = mobj.group('uploader')
  269. # extract simple title (uploader + slug of song title)
  270. slug_title = mobj.group('title')
  271. token = mobj.group('token')
  272. full_title = resolve_title = '%s/%s' % (uploader, slug_title)
  273. if token:
  274. resolve_title += '/%s' % token
  275. self.report_resolve(full_title)
  276. url = 'https://soundcloud.com/%s' % resolve_title
  277. info_json_url = self._resolv_url(url)
  278. info = self._download_json(info_json_url, full_title, 'Downloading info JSON')
  279. return self._extract_info_dict(info, full_title, secret_token=token)
  280. class SoundcloudPlaylistBaseIE(SoundcloudIE):
  281. @staticmethod
  282. def _extract_id(e):
  283. return compat_str(e['id']) if e.get('id') else None
  284. def _extract_track_entries(self, tracks):
  285. return [
  286. self.url_result(
  287. track['permalink_url'], SoundcloudIE.ie_key(),
  288. video_id=self._extract_id(track))
  289. for track in tracks if track.get('permalink_url')]
  290. class SoundcloudSetIE(SoundcloudPlaylistBaseIE):
  291. _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<uploader>[\w\d-]+)/sets/(?P<slug_title>[\w\d-]+)(?:/(?P<token>[^?/]+))?'
  292. IE_NAME = 'soundcloud:set'
  293. _TESTS = [{
  294. 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep',
  295. 'info_dict': {
  296. 'id': '2284613',
  297. 'title': 'The Royal Concept EP',
  298. },
  299. 'playlist_mincount': 5,
  300. }, {
  301. 'url': 'https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep/token',
  302. 'only_matching': True,
  303. }]
  304. def _real_extract(self, url):
  305. mobj = re.match(self._VALID_URL, url)
  306. # extract uploader (which is in the url)
  307. uploader = mobj.group('uploader')
  308. # extract simple title (uploader + slug of song title)
  309. slug_title = mobj.group('slug_title')
  310. full_title = '%s/sets/%s' % (uploader, slug_title)
  311. url = 'https://soundcloud.com/%s/sets/%s' % (uploader, slug_title)
  312. token = mobj.group('token')
  313. if token:
  314. full_title += '/' + token
  315. url += '/' + token
  316. self.report_resolve(full_title)
  317. resolv_url = self._resolv_url(url)
  318. info = self._download_json(resolv_url, full_title)
  319. if 'errors' in info:
  320. msgs = (compat_str(err['error_message']) for err in info['errors'])
  321. raise ExtractorError('unable to download video webpage: %s' % ','.join(msgs))
  322. entries = self._extract_track_entries(info['tracks'])
  323. return {
  324. '_type': 'playlist',
  325. 'entries': entries,
  326. 'id': '%s' % info['id'],
  327. 'title': info['title'],
  328. }
  329. class SoundcloudPagedPlaylistBaseIE(SoundcloudPlaylistBaseIE):
  330. _API_BASE = 'https://api.soundcloud.com'
  331. _API_V2_BASE = 'https://api-v2.soundcloud.com'
  332. def _extract_playlist(self, base_url, playlist_id, playlist_title):
  333. COMMON_QUERY = {
  334. 'limit': 50,
  335. 'client_id': self._CLIENT_ID,
  336. 'linked_partitioning': '1',
  337. }
  338. query = COMMON_QUERY.copy()
  339. query['offset'] = 0
  340. next_href = base_url + '?' + compat_urllib_parse_urlencode(query)
  341. entries = []
  342. for i in itertools.count():
  343. response = self._download_json(
  344. next_href, playlist_id, 'Downloading track page %s' % (i + 1))
  345. collection = response['collection']
  346. if not collection:
  347. break
  348. def resolve_permalink_url(candidates):
  349. for cand in candidates:
  350. if isinstance(cand, dict):
  351. permalink_url = cand.get('permalink_url')
  352. entry_id = self._extract_id(cand)
  353. if permalink_url and permalink_url.startswith('http'):
  354. return permalink_url, entry_id
  355. for e in collection:
  356. permalink_url, entry_id = resolve_permalink_url((e, e.get('track'), e.get('playlist')))
  357. if permalink_url:
  358. entries.append(self.url_result(permalink_url, video_id=entry_id))
  359. next_href = response.get('next_href')
  360. if not next_href:
  361. break
  362. parsed_next_href = compat_urlparse.urlparse(response['next_href'])
  363. qs = compat_urlparse.parse_qs(parsed_next_href.query)
  364. qs.update(COMMON_QUERY)
  365. next_href = compat_urlparse.urlunparse(
  366. parsed_next_href._replace(query=compat_urllib_parse_urlencode(qs, True)))
  367. return {
  368. '_type': 'playlist',
  369. 'id': playlist_id,
  370. 'title': playlist_title,
  371. 'entries': entries,
  372. }
  373. class SoundcloudUserIE(SoundcloudPagedPlaylistBaseIE):
  374. _VALID_URL = r'''(?x)
  375. https?://
  376. (?:(?:www|m)\.)?soundcloud\.com/
  377. (?P<user>[^/]+)
  378. (?:/
  379. (?P<rsrc>tracks|sets|reposts|likes|spotlight)
  380. )?
  381. /?(?:[?#].*)?$
  382. '''
  383. IE_NAME = 'soundcloud:user'
  384. _TESTS = [{
  385. 'url': 'https://soundcloud.com/the-akashic-chronicler',
  386. 'info_dict': {
  387. 'id': '114582580',
  388. 'title': 'The Akashic Chronicler (All)',
  389. },
  390. 'playlist_mincount': 74,
  391. }, {
  392. 'url': 'https://soundcloud.com/the-akashic-chronicler/tracks',
  393. 'info_dict': {
  394. 'id': '114582580',
  395. 'title': 'The Akashic Chronicler (Tracks)',
  396. },
  397. 'playlist_mincount': 37,
  398. }, {
  399. 'url': 'https://soundcloud.com/the-akashic-chronicler/sets',
  400. 'info_dict': {
  401. 'id': '114582580',
  402. 'title': 'The Akashic Chronicler (Playlists)',
  403. },
  404. 'playlist_mincount': 2,
  405. }, {
  406. 'url': 'https://soundcloud.com/the-akashic-chronicler/reposts',
  407. 'info_dict': {
  408. 'id': '114582580',
  409. 'title': 'The Akashic Chronicler (Reposts)',
  410. },
  411. 'playlist_mincount': 7,
  412. }, {
  413. 'url': 'https://soundcloud.com/the-akashic-chronicler/likes',
  414. 'info_dict': {
  415. 'id': '114582580',
  416. 'title': 'The Akashic Chronicler (Likes)',
  417. },
  418. 'playlist_mincount': 321,
  419. }, {
  420. 'url': 'https://soundcloud.com/grynpyret/spotlight',
  421. 'info_dict': {
  422. 'id': '7098329',
  423. 'title': 'Grynpyret (Spotlight)',
  424. },
  425. 'playlist_mincount': 1,
  426. }]
  427. _BASE_URL_MAP = {
  428. 'all': '%s/profile/soundcloud:users:%%s' % SoundcloudPagedPlaylistBaseIE._API_V2_BASE,
  429. 'tracks': '%s/users/%%s/tracks' % SoundcloudPagedPlaylistBaseIE._API_BASE,
  430. 'sets': '%s/users/%%s/playlists' % SoundcloudPagedPlaylistBaseIE._API_V2_BASE,
  431. 'reposts': '%s/profile/soundcloud:users:%%s/reposts' % SoundcloudPagedPlaylistBaseIE._API_V2_BASE,
  432. 'likes': '%s/users/%%s/likes' % SoundcloudPagedPlaylistBaseIE._API_V2_BASE,
  433. 'spotlight': '%s/users/%%s/spotlight' % SoundcloudPagedPlaylistBaseIE._API_V2_BASE,
  434. }
  435. _TITLE_MAP = {
  436. 'all': 'All',
  437. 'tracks': 'Tracks',
  438. 'sets': 'Playlists',
  439. 'reposts': 'Reposts',
  440. 'likes': 'Likes',
  441. 'spotlight': 'Spotlight',
  442. }
  443. def _real_extract(self, url):
  444. mobj = re.match(self._VALID_URL, url)
  445. uploader = mobj.group('user')
  446. url = 'https://soundcloud.com/%s/' % uploader
  447. resolv_url = self._resolv_url(url)
  448. user = self._download_json(
  449. resolv_url, uploader, 'Downloading user info')
  450. resource = mobj.group('rsrc') or 'all'
  451. return self._extract_playlist(
  452. self._BASE_URL_MAP[resource] % user['id'], compat_str(user['id']),
  453. '%s (%s)' % (user['username'], self._TITLE_MAP[resource]))
  454. class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
  455. _VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)'
  456. IE_NAME = 'soundcloud:trackstation'
  457. _TESTS = [{
  458. 'url': 'https://soundcloud.com/stations/track/officialsundial/your-text',
  459. 'info_dict': {
  460. 'id': '286017854',
  461. 'title': 'Track station: your-text',
  462. },
  463. 'playlist_mincount': 47,
  464. }]
  465. def _real_extract(self, url):
  466. track_name = self._match_id(url)
  467. webpage = self._download_webpage(url, track_name)
  468. track_id = self._search_regex(
  469. r'soundcloud:track-stations:(\d+)', webpage, 'track id')
  470. return self._extract_playlist(
  471. '%s/stations/soundcloud:track-stations:%s/tracks'
  472. % (self._API_V2_BASE, track_id),
  473. track_id, 'Track station: %s' % track_name)
  474. class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE):
  475. _VALID_URL = r'https?://api\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$'
  476. IE_NAME = 'soundcloud:playlist'
  477. _TESTS = [{
  478. 'url': 'https://api.soundcloud.com/playlists/4110309',
  479. 'info_dict': {
  480. 'id': '4110309',
  481. 'title': 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]',
  482. 'description': 're:.*?TILT Brass - Bowery Poetry Club',
  483. },
  484. 'playlist_count': 6,
  485. }]
  486. def _real_extract(self, url):
  487. mobj = re.match(self._VALID_URL, url)
  488. playlist_id = mobj.group('id')
  489. base_url = '%s//api.soundcloud.com/playlists/%s.json?' % (self.http_scheme(), playlist_id)
  490. data_dict = {
  491. 'client_id': self._CLIENT_ID,
  492. }
  493. token = mobj.group('token')
  494. if token:
  495. data_dict['secret_token'] = token
  496. data = compat_urllib_parse_urlencode(data_dict)
  497. data = self._download_json(
  498. base_url + data, playlist_id, 'Downloading playlist')
  499. entries = self._extract_track_entries(data['tracks'])
  500. return {
  501. '_type': 'playlist',
  502. 'id': playlist_id,
  503. 'title': data.get('title'),
  504. 'description': data.get('description'),
  505. 'entries': entries,
  506. }
  507. class SoundcloudSearchIE(SearchInfoExtractor, SoundcloudIE):
  508. IE_NAME = 'soundcloud:search'
  509. IE_DESC = 'Soundcloud search'
  510. _MAX_RESULTS = float('inf')
  511. _TESTS = [{
  512. 'url': 'scsearch15:post-avant jazzcore',
  513. 'info_dict': {
  514. 'title': 'post-avant jazzcore',
  515. },
  516. 'playlist_count': 15,
  517. }]
  518. _SEARCH_KEY = 'scsearch'
  519. _MAX_RESULTS_PER_PAGE = 200
  520. _DEFAULT_RESULTS_PER_PAGE = 50
  521. _API_V2_BASE = 'https://api-v2.soundcloud.com'
  522. def _get_collection(self, endpoint, collection_id, **query):
  523. limit = min(
  524. query.get('limit', self._DEFAULT_RESULTS_PER_PAGE),
  525. self._MAX_RESULTS_PER_PAGE)
  526. query['limit'] = limit
  527. query['client_id'] = self._CLIENT_ID
  528. query['linked_partitioning'] = '1'
  529. query['offset'] = 0
  530. data = compat_urllib_parse_urlencode(query)
  531. next_url = '{0}{1}?{2}'.format(self._API_V2_BASE, endpoint, data)
  532. collected_results = 0
  533. for i in itertools.count(1):
  534. response = self._download_json(
  535. next_url, collection_id, 'Downloading page {0}'.format(i),
  536. 'Unable to download API page')
  537. collection = response.get('collection', [])
  538. if not collection:
  539. break
  540. collection = list(filter(bool, collection))
  541. collected_results += len(collection)
  542. for item in collection:
  543. yield self.url_result(item['uri'], SoundcloudIE.ie_key())
  544. if not collection or collected_results >= limit:
  545. break
  546. next_url = response.get('next_href')
  547. if not next_url:
  548. break
  549. def _get_n_results(self, query, n):
  550. tracks = self._get_collection('/search/tracks', query, limit=n, q=query)
  551. return self.playlist_result(tracks, playlist_title=query)