From 6c35af587740d80b7a6b70c1e0ecc9f951828d6b Mon Sep 17 00:00:00 2001 From: baumgartnerniels Date: Mon, 2 Mar 2015 19:52:46 +0100 Subject: [PATCH] Fix #48: Fetch more songs from stream, load tracks in playlists --- mopidy_soundcloud/soundcloud.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/mopidy_soundcloud/soundcloud.py b/mopidy_soundcloud/soundcloud.py index 58ecc5d..f9f5518 100644 --- a/mopidy_soundcloud/soundcloud.py +++ b/mopidy_soundcloud/soundcloud.py @@ -89,20 +89,18 @@ def user(self): @cache() def get_user_stream(self): # User timeline like playlist which uses undocumented api - # https://api.soundcloud.com/e1/me/stream.json?offset=0 - # returns five elements per request + # https://api.soundcloud.com/e1/me/stream.json?limit=100 tracks = [] - for sid in xrange(0, 2): - stream = self._get('e1/me/stream.json?offset=%s' % sid * 5) - for data in stream.get('collection'): - kind = data.get('type') - # multiple types of track with same data - if 'track' in kind: - tracks.append(self.parse_track(data.get('track'))) - if kind == 'playlist': - playlist = data.get('playlist').get('tracks') - if isinstance(playlist, collections.Iterable): - tracks.extend(self.parse_results(playlist)) + stream = self._get('e1/me/stream.json?limit=100') + for data in stream.get('collection'): + kind = data.get('type') + # multiple types of track with same data + if 'track' in kind: + tracks.append(self.parse_track(data.get('track'))) + if kind == 'playlist': + playlist_id = data.get('playlist').get('id') + for track in self.get_set(playlist_id): + tracks.append(self.parse_track(track)) return self.sanitize_tracks(tracks)