From 7c414d4abc7a4478ccaddc092e1039c779de6e79 Mon Sep 17 00:00:00 2001 From: Lasse Bigum Date: Thu, 31 Oct 2013 20:15:13 +0100 Subject: [PATCH 1/4] Support 'list albumartist' --- mopidy/frontends/mpd/protocol/music_db.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 6dd43d68..1c737520 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -127,7 +127,7 @@ def findadd(context, mpd_query): @handle_request( - r'^list "?(?P([Aa]rtist|[Aa]lbum|[Dd]ate|[Gg]enre))"?' + r'^list "?(?P([Aa]rtist|[Aa]lbumartist|[Aa]lbum|[Dd]ate|[Gg]enre))"?' r'( (?P.*))?$') def list_(context, field, mpd_query=None): """ @@ -136,7 +136,7 @@ def list_(context, field, mpd_query=None): ``list {TYPE} [ARTIST]`` Lists all tags of the specified type. ``TYPE`` should be ``album``, - ``artist``, ``date``, or ``genre``. + ``artist``, ``albumartist``, ``date``, or ``genre``. ``ARTIST`` is an optional parameter when type is ``album``, ``date``, or ``genre``. This filters the result list by an artist. @@ -218,6 +218,8 @@ def list_(context, field, mpd_query=None): return if field == 'artist': return _list_artist(context, query) + if field == 'albumartist': + return _list_albumartist(context, query) elif field == 'album': return _list_album(context, query) elif field == 'date': @@ -236,6 +238,18 @@ def _list_artist(context, query): return artists +def _list_albumartist(context, query): + import logging + logger = logging.getLogger('mopidy.backends.local') + albumartists = set() + results = context.core.library.find_exact(**query).get() + for track in _get_tracks(results): + for artist in track.album.artists: + if artist.name: + albumartists.add(('AlbumArtist', artist.name)) + return albumartists + + def _list_album(context, query): albums = set() results = context.core.library.find_exact(**query).get() From fd213f2d785f22958dedebe6a046757cf38269e2 Mon Sep 17 00:00:00 2001 From: Lasse Bigum Date: Thu, 31 Oct 2013 22:00:43 +0100 Subject: [PATCH 2/4] Add tests for albumartist --- tests/frontends/mpd/protocol/music_db_test.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/frontends/mpd/protocol/music_db_test.py b/tests/frontends/mpd/protocol/music_db_test.py index 0114340b..60c30372 100644 --- a/tests/frontends/mpd/protocol/music_db_test.py +++ b/tests/frontends/mpd/protocol/music_db_test.py @@ -398,6 +398,66 @@ class MusicDatabaseListTest(protocol.BaseTestCase): self.assertNotInResponse('Artist: ') self.assertInResponse('OK') + ### Albumartist + + def test_list_albumartist_with_quotes(self): + self.sendRequest('list "albumartist"') + self.assertInResponse('OK') + + def test_list_albumartist_without_quotes(self): + self.sendRequest('list albumartist') + self.assertInResponse('OK') + + def test_list_albumartist_without_quotes_and_capitalized(self): + self.sendRequest('list Albumartist') + self.assertInResponse('OK') + + def test_list_albumartist_with_query_of_one_token(self): + self.sendRequest('list "albumartist" "anartist"') + self.assertEqualResponse( + 'ACK [2@0] {list} should be "Album" for 3 arguments') + + def test_list_albumartist_with_unknown_field_in_query_returns_ack(self): + self.sendRequest('list "albumartist" "foo" "bar"') + self.assertEqualResponse('ACK [2@0] {list} not able to parse args') + + def test_list_albumartist_by_artist(self): + self.sendRequest('list "albumartist" "artist" "anartist"') + self.assertInResponse('OK') + + def test_list_albumartist_by_album(self): + self.sendRequest('list "albumartist" "album" "analbum"') + self.assertInResponse('OK') + + def test_list_albumartist_by_full_date(self): + self.sendRequest('list "albumartist" "date" "2001-01-01"') + self.assertInResponse('OK') + + def test_list_albumartist_by_year(self): + self.sendRequest('list "albumartist" "date" "2001"') + self.assertInResponse('OK') + + def test_list_albumartist_by_genre(self): + self.sendRequest('list "albumartist" "genre" "agenre"') + self.assertInResponse('OK') + + def test_list_albumartist_by_artist_and_album(self): + self.sendRequest( + 'list "albumartist" "artist" "anartist" "album" "analbum"') + self.assertInResponse('OK') + + def test_list_albumartist_without_filter_value(self): + self.sendRequest('list "albumartist" "artist" ""') + self.assertInResponse('OK') + + def test_list_albumartist_should_not_return_artists_without_names(self): + self.backend.library.dummy_find_exact_result = SearchResult( + tracks=[Track(album=Album(artists=[Artist(name='')]))]) + + self.sendRequest('list "albumartist"') + self.assertNotInResponse('Artist: ') + self.assertInResponse('OK') + ### Album def test_list_album_with_quotes(self): From 86f18935fe8ef5e6592e072e19c1aa644fb2c916 Mon Sep 17 00:00:00 2001 From: Lasse Bigum Date: Sat, 2 Nov 2013 02:43:12 +0100 Subject: [PATCH 3/4] Fix flake8 errors and add a few more tests --- mopidy/frontends/mpd/protocol/music_db.py | 6 ++---- tests/backends/local/library_test.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 1c737520..972f5840 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -127,8 +127,8 @@ def findadd(context, mpd_query): @handle_request( - r'^list "?(?P([Aa]rtist|[Aa]lbumartist|[Aa]lbum|[Dd]ate|[Gg]enre))"?' - r'( (?P.*))?$') + r'^list "?(?P([Aa]rtist|[Aa]lbumartist|[Aa]lbum|[Dd]ate|' + r'[Gg]enre))"?( (?P.*))?$') def list_(context, field, mpd_query=None): """ *musicpd.org, music database section:* @@ -239,8 +239,6 @@ def _list_artist(context, query): def _list_albumartist(context, query): - import logging - logger = logging.getLogger('mopidy.backends.local') albumartists = set() results = context.core.library.find_exact(**query).get() for track in _get_tracks(results): diff --git a/tests/backends/local/library_test.py b/tests/backends/local/library_test.py index 061895d8..0e33b412 100644 --- a/tests/backends/local/library_test.py +++ b/tests/backends/local/library_test.py @@ -108,6 +108,9 @@ class LocalLibraryProviderTest(unittest.TestCase): result = self.library.find_exact(artist=['unknown artist']) self.assertEqual(list(result[0].tracks), []) + result = self.library.find_exact(albumartist=['unknown albumartist']) + self.assertEqual(list(result[0].tracks), []) + result = self.library.find_exact(album=['unknown artist']) self.assertEqual(list(result[0].tracks), []) @@ -225,6 +228,9 @@ class LocalLibraryProviderTest(unittest.TestCase): test = lambda: self.library.find_exact(artist=['']) self.assertRaises(LookupError, test) + test = lambda: self.library.find_exact(albumartist=['']) + self.assertRaises(LookupError, test) + test = lambda: self.library.find_exact(track=['']) self.assertRaises(LookupError, test) @@ -247,6 +253,9 @@ class LocalLibraryProviderTest(unittest.TestCase): result = self.library.search(artist=['unknown artist']) self.assertEqual(list(result[0].tracks), []) + result = self.library.search(albumartist=['unknown albumartist']) + self.assertEqual(list(result[0].tracks), []) + result = self.library.search(album=['unknown artist']) self.assertEqual(list(result[0].tracks), []) @@ -358,6 +367,9 @@ class LocalLibraryProviderTest(unittest.TestCase): test = lambda: self.library.search(artist=['']) self.assertRaises(LookupError, test) + test = lambda: self.library.search(albumartist=['']) + self.assertRaises(LookupError, test) + test = lambda: self.library.search(track=['']) self.assertRaises(LookupError, test) From 0df84b85d085f4220ccd3d1aaff3b6e1f21e240a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 2 Nov 2013 22:00:35 +0100 Subject: [PATCH 4/4] mpd: Check if track.album exists before using it --- mopidy/frontends/mpd/protocol/music_db.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 972f5840..e70815f8 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -242,9 +242,10 @@ def _list_albumartist(context, query): albumartists = set() results = context.core.library.find_exact(**query).get() for track in _get_tracks(results): - for artist in track.album.artists: - if artist.name: - albumartists.add(('AlbumArtist', artist.name)) + if track.album: + for artist in track.album.artists: + if artist.name: + albumartists.add(('AlbumArtist', artist.name)) return albumartists