Skip to content

Commit

Permalink
Merge 76b70aa into adecba4
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Oct 11, 2013
2 parents adecba4 + 76b70aa commit dd8bb5f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
10 changes: 10 additions & 0 deletions mopidy/backends/local/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def find_exact(self, query=None, uris=None):
album_filter = lambda t: q == getattr(t, 'album', Album()).name
artist_filter = lambda t: filter(
lambda a: q == a.name, t.artists)
albumartist_filter = lambda t: any([
q == a.name
for a in getattr(t.album, 'artists', [])])
date_filter = lambda t: q == t.date
any_filter = lambda t: (
track_filter(t) or album_filter(t) or
Expand All @@ -75,6 +78,8 @@ def find_exact(self, query=None, uris=None):
result_tracks = filter(album_filter, result_tracks)
elif field == 'artist':
result_tracks = filter(artist_filter, result_tracks)
elif field == 'albumartist':
result_tracks = filter(albumartist_filter, result_tracks)
elif field == 'date':
result_tracks = filter(date_filter, result_tracks)
elif field == 'any':
Expand Down Expand Up @@ -105,6 +110,9 @@ def search(self, query=None, uris=None):
t, 'album', Album()).name.lower()
artist_filter = lambda t: filter(
lambda a: q in a.name.lower(), t.artists)
albumartist_filter = lambda t: any([
q in a.name.lower()
for a in getattr(t.album, 'artists', [])])
date_filter = lambda t: t.date and t.date.startswith(q)
any_filter = lambda t: track_filter(t) or album_filter(t) or \
artist_filter(t) or uri_filter(t)
Expand All @@ -117,6 +125,8 @@ def search(self, query=None, uris=None):
result_tracks = filter(album_filter, result_tracks)
elif field == 'artist':
result_tracks = filter(artist_filter, result_tracks)
elif field == 'albumartist':
result_tracks = filter(albumartist_filter, result_tracks)
elif field == 'date':
result_tracks = filter(date_filter, result_tracks)
elif field == 'any':
Expand Down
2 changes: 1 addition & 1 deletion mopidy/frontends/mpd/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def query_from_mpd_list_format(field, mpd_query):
key = tokens[0].lower()
value = tokens[1]
tokens = tokens[2:]
if key not in ('artist', 'album', 'date', 'genre'):
if key not in ('artist', 'album', 'albumartist', 'date', 'genre'):
raise MpdArgError('not able to parse args', command='list')
if not value:
raise ValueError
Expand Down
59 changes: 50 additions & 9 deletions tests/backends/local/library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,33 @@


class LocalLibraryControllerTest(unittest.TestCase):
artists = [Artist(name='artist1'), Artist(name='artist2'), Artist()]
artists = [
Artist(name='artist1'),
Artist(name='artist2'),
Artist(name='artist3'),
Artist(name='artist4'),
]

albums = [
Album(name='album1', artists=artists[:1]),
Album(name='album2', artists=artists[1:2]),
Album()]
Album(name='album1', artists=[artists[0]]),
Album(name='album2', artists=[artists[1]]),
Album(name='album3', artists=[artists[2]]),
]

tracks = [
Track(uri='local:track:path1', name='track1', artists=artists[:1],
album=albums[0], date='2001-02-03', length=4000),
Track(uri='local:track:path2', name='track2', artists=artists[1:2],
album=albums[1], date='2002', length=4000),
Track()]
Track(
uri='local:track:path1', name='track1',
artists=[artists[0]], album=albums[0],
date='2001-02-03', length=4000),
Track(
uri='local:track:path2', name='track2',
artists=[artists[1]], album=albums[1],
date='2002', length=4000),
Track(
uri='local:track:path3', name='track3',
artists=[artists[3]], album=albums[2],
date='2003', length=4000),
]

config = {
'local': {
Expand All @@ -35,6 +49,7 @@ class LocalLibraryControllerTest(unittest.TestCase):
}

def setUp(self):

self.backend = actor.LocalBackend.start(
config=self.config, audio=None).proxy()
self.core = core.Core(backends=[self.backend])
Expand Down Expand Up @@ -102,6 +117,19 @@ def test_find_exact_album(self):
result = self.library.find_exact(album=['album2'])
self.assertEqual(list(result[0].tracks), self.tracks[1:2])

def test_find_exact_albumartist(self):
# Artist is both track artist and album artist
result = self.library.find_exact(albumartist=['artist1'])
self.assertEqual(list(result[0].tracks), [self.tracks[0]])

# Artist is both track and album artist
result = self.library.find_exact(albumartist=['artist2'])
self.assertEqual(list(result[0].tracks), [self.tracks[1]])

# Artist is just album artist
result = self.library.find_exact(albumartist=['artist3'])
self.assertEqual(list(result[0].tracks), [self.tracks[2]])

def test_find_exact_date(self):
result = self.library.find_exact(date=['2001'])
self.assertEqual(list(result[0].tracks), [])
Expand Down Expand Up @@ -163,6 +191,19 @@ def test_search_artist(self):
result = self.library.search(artist=['Tist2'])
self.assertEqual(list(result[0].tracks), self.tracks[1:2])

def test_search_albumartist(self):
# Artist is both track artist and album artist
result = self.library.search(albumartist=['Tist1'])
self.assertEqual(list(result[0].tracks), [self.tracks[0]])

# Artist is both track artist and album artist
result = self.library.search(albumartist=['Tist2'])
self.assertEqual(list(result[0].tracks), [self.tracks[1]])

# Artist is just album artist
result = self.library.search(albumartist=['Tist3'])
self.assertEqual(list(result[0].tracks), [self.tracks[2]])

def test_search_album(self):
result = self.library.search(album=['Bum1'])
self.assertEqual(list(result[0].tracks), self.tracks[:1])
Expand Down
6 changes: 4 additions & 2 deletions tests/data/library_tag_cache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Title: track1
Album: album1
Date: 2001-02-03
Time: 4
key: key1
key: key2
file: /path2
Artist: artist2
Title: track2
Expand All @@ -19,8 +19,10 @@ Date: 2002
Time: 4
key: key3
file: /path3
Artist: artist3
Artist: artist4
AlbumArtist: artist3
Title: track3
Album: album3
Date: 2003
Time: 4
songList end
4 changes: 4 additions & 0 deletions tests/frontends/mpd/protocol/music_db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def test_list_album_by_album(self):
self.sendRequest('list "album" "album" "analbum"')
self.assertInResponse('OK')

def test_list_album_by_albumartist(self):
self.sendRequest('list "album" "albumartist" "anartist"')
self.assertInResponse('OK')

def test_list_album_by_full_date(self):
self.sendRequest('list "album" "date" "2001-01-01"')
self.assertInResponse('OK')
Expand Down

0 comments on commit dd8bb5f

Please sign in to comment.