Skip to content

Commit

Permalink
Fix mopidy#48: Fetch more songs from stream, load tracks in playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
baumgartnerniels committed Mar 2, 2015
1 parent a2851ac commit 6c35af5
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions mopidy_soundcloud/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6c35af5

Please sign in to comment.