+ return {
+ '_type': 'playlist',
+ 'entries': [self._extract_info_dict(track, secret_token=token) for track in info['tracks']],
+ 'id': '%s' % info['id'],
+ 'title': info['title'],
+ }
+
+
+class SoundcloudUserIE(SoundcloudIE):
+ _VALID_URL = r'https?://(www\.)?soundcloud\.com/(?P<user>[^/]+)/?((?P<rsrc>tracks|likes)/?)?(\?.*)?$'
+ IE_NAME = 'soundcloud:user'
+ _TESTS = [{
+ 'url': 'https://soundcloud.com/the-concept-band',
+ 'info_dict': {
+ 'id': '9615865',
+ 'title': 'The Royal Concept',
+ },
+ 'playlist_mincount': 12
+ }, {
+ 'url': 'https://soundcloud.com/the-concept-band/likes',
+ 'info_dict': {
+ 'id': '9615865',
+ 'title': 'The Royal Concept',
+ },
+ 'playlist_mincount': 1,
+ }]
+
+ def _real_extract(self, url):
+ mobj = re.match(self._VALID_URL, url)
+ uploader = mobj.group('user')
+ resource = mobj.group('rsrc')
+ if resource is None:
+ resource = 'tracks'
+ elif resource == 'likes':
+ resource = 'favorites'
+
+ url = 'http://soundcloud.com/%s/' % uploader
+ resolv_url = self._resolv_url(url)
+ user = self._download_json(
+ resolv_url, uploader, 'Downloading user info')
+ base_url = 'http://api.soundcloud.com/users/%s/%s.json?' % (uploader, resource)
+
+ entries = []
+ for i in itertools.count():
+ data = compat_urllib_parse.urlencode({
+ 'offset': i * 50,
+ 'limit': 50,
+ 'client_id': self._CLIENT_ID,
+ })
+ new_entries = self._download_json(
+ base_url + data, uploader, 'Downloading track page %s' % (i + 1))
+ if len(new_entries) == 0:
+ self.to_screen('%s: End page received' % uploader)
+ break
+ entries.extend(self._extract_info_dict(e, quiet=True) for e in new_entries)
+
+ return {
+ '_type': 'playlist',
+ 'id': compat_str(user['id']),
+ 'title': user['username'],
+ 'entries': entries,
+ }
+
+
+class SoundcloudPlaylistIE(SoundcloudIE):
+ _VALID_URL = r'https?://api\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$'
+ IE_NAME = 'soundcloud:playlist'
+ _TESTS = [{
+ 'url': 'http://api.soundcloud.com/playlists/4110309',
+ 'info_dict': {
+ 'id': '4110309',
+ 'title': 'TILT Brass - Bowery Poetry Club, August \'03 [Non-Site SCR 02]',
+ 'description': 're:.*?TILT Brass - Bowery Poetry Club',
+ },
+ 'playlist_count': 6,
+ }]
+
+ def _real_extract(self, url):
+ mobj = re.match(self._VALID_URL, url)
+ playlist_id = mobj.group('id')
+ base_url = '%s//api.soundcloud.com/playlists/%s.json?' % (self.http_scheme(), playlist_id)
+
+ data_dict = {
+ 'client_id': self._CLIENT_ID,
+ }
+ token = mobj.group('token')
+
+ if token:
+ data_dict['secret_token'] = token
+
+ data = compat_urllib_parse.urlencode(data_dict)
+ data = self._download_json(
+ base_url + data, playlist_id, 'Downloading playlist')
+
+ entries = [
+ self._extract_info_dict(t, quiet=True, secret_token=token)
+ for t in data['tracks']]
+
+ return {
+ '_type': 'playlist',
+ 'id': playlist_id,
+ 'title': data.get('title'),
+ 'description': data.get('description'),
+ 'entries': entries,
+ }