Skip to content

Commit

Permalink
lookup: Make artist lookup ignore unavailable albums
Browse files Browse the repository at this point in the history
This reduces the amount of returned data a lot, since we don't include
both available albums and unavailable albums autolinked to the available
album.

This also makes artist lookup notably faster, improving from 2.27s to
0.75s for a worst-case artist.

Fixes #31
  • Loading branch information
jodal committed Jul 22, 2015
1 parent bf639c3 commit 4572ae5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mopidy_spotify/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def _lookup_artist(config, sp_link):
sp_album_browsers = []
for sp_album in sp_artist_browser.albums:
sp_album.load()
if not sp_album.is_available:
continue
if sp_album.type is spotify.AlbumType.COMPILATION:
continue
if sp_album.artist.link.uri in _VARIOUS_ARTISTS_URIS:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def test_lookup_of_artist_uri(
assert track.bitrate == 160


def test_lookup_of_artist_ignores_unavailable_albums(
session_mock, sp_artist_browser_mock, sp_album_browser_mock, provider):
sp_artist_mock = sp_artist_browser_mock.artist
session_mock.get_link.return_value = sp_artist_mock.link
sp_album_mock = sp_album_browser_mock.album
sp_album_mock.is_available = False

results = provider.lookup('spotify:artist:abba')

assert len(results) == 0


def test_lookup_of_artist_uri_ignores_compilations(
session_mock, sp_artist_browser_mock, sp_album_browser_mock, provider):
sp_artist_mock = sp_artist_browser_mock.artist
Expand Down

0 comments on commit 4572ae5

Please sign in to comment.