local: Add albumartist support to search/find_exact
This commit is contained in:
parent
adecba40e5
commit
ccbae310c6
@ -62,6 +62,9 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
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
|
||||
@ -75,6 +78,8 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
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':
|
||||
@ -105,6 +110,9 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
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)
|
||||
@ -117,6 +125,8 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
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':
|
||||
|
||||
@ -12,19 +12,33 @@ from tests import path_to_data_dir
|
||||
|
||||
|
||||
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': {
|
||||
@ -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])
|
||||
@ -102,6 +117,19 @@ class LocalLibraryControllerTest(unittest.TestCase):
|
||||
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), [])
|
||||
@ -163,6 +191,19 @@ class LocalLibraryControllerTest(unittest.TestCase):
|
||||
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])
|
||||
|
||||
@ -10,7 +10,7 @@ Title: track1
|
||||
Album: album1
|
||||
Date: 2001-02-03
|
||||
Time: 4
|
||||
key: key1
|
||||
key: key2
|
||||
file: /path2
|
||||
Artist: artist2
|
||||
Title: track2
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user