Skip to content

Commit

Permalink
browse: Add playlist browsing
Browse files Browse the repository at this point in the history
This fixes Mopidy-Spotify-Tunigo compatability.
  • Loading branch information
jodal committed Jan 22, 2015
1 parent f6634b8 commit 327e83e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mopidy_spotify/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def __init__(self, backend):
def browse(self, uri):
if uri == self.root_directory.uri:
return self._root_dir_contents
elif uri.startswith('spotify:user:'):
return self._browse_playlist(uri)
elif uri.startswith('spotify:album:'):
return self._browse_album(uri)
elif uri.startswith('spotify:artist:'):
Expand All @@ -66,6 +68,11 @@ def browse(self, uri):
logger.info('Failed to browse "%s": Unknown URI type', uri)
return []

def _browse_playlist(self, uri):
playlist = self._backend._session.get_playlist(uri)
playlist.load()
return list(self._get_track_refs(playlist.tracks))

def _browse_album(self, uri):
album_browser = self._backend._session.get_album(uri).browse()
album_browser.load()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def test_browse_root_directory(provider):
uri='spotify:top:artists', name='Top artists') in results


def test_browse_playlist(
session_mock, sp_playlist_mock, sp_track_mock, provider):
session_mock.get_playlist.return_value = sp_playlist_mock
sp_playlist_mock.tracks = [sp_track_mock, sp_track_mock]

results = provider.browse('spotify:user:alice:playlist:foo')

session_mock.get_playlist.assert_called_once_with(
'spotify:user:alice:playlist:foo')
assert len(results) == 2
assert results[0] == models.Ref.track(
uri='spotify:track:abc', name='ABC 123')


def test_browse_album(
session_mock, sp_album_mock, sp_album_browser_mock, sp_track_mock,
provider):
Expand Down

0 comments on commit 327e83e

Please sign in to comment.