local: Add search-by-date support
This commit is contained in:
parent
53f3ef488c
commit
02c8ea53d7
@ -28,6 +28,8 @@ v0.11.0 (in development)
|
||||
|
||||
- Load track dates from tag cache.
|
||||
|
||||
- Add support for searching by track date.
|
||||
|
||||
**MPD frontend**
|
||||
|
||||
- Add :attr:`mopidy.settings.MPD_SERVER_CONNECTION_TIMEOUT` setting which
|
||||
|
||||
@ -51,6 +51,7 @@ 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)
|
||||
date_filter = lambda t: q == t.date
|
||||
any_filter = lambda t: (
|
||||
track_filter(t) or album_filter(t) or
|
||||
artist_filter(t) or uri_filter(t))
|
||||
@ -63,6 +64,8 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
result_tracks = filter(album_filter, result_tracks)
|
||||
elif field == 'artist':
|
||||
result_tracks = filter(artist_filter, result_tracks)
|
||||
elif field == 'date':
|
||||
result_tracks = filter(date_filter, result_tracks)
|
||||
elif field == 'any':
|
||||
result_tracks = filter(any_filter, result_tracks)
|
||||
else:
|
||||
@ -86,6 +89,7 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
t, 'album', Album()).name.lower()
|
||||
artist_filter = lambda t: filter(
|
||||
lambda a: q in a.name.lower(), t.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)
|
||||
|
||||
@ -97,6 +101,8 @@ class LocalLibraryProvider(base.BaseLibraryProvider):
|
||||
result_tracks = filter(album_filter, result_tracks)
|
||||
elif field == 'artist':
|
||||
result_tracks = filter(artist_filter, result_tracks)
|
||||
elif field == 'date':
|
||||
result_tracks = filter(date_filter, result_tracks)
|
||||
elif field == 'any':
|
||||
result_tracks = filter(any_filter, result_tracks)
|
||||
else:
|
||||
|
||||
@ -16,11 +16,12 @@ class LibraryControllerTest(object):
|
||||
Album()]
|
||||
tracks = [
|
||||
Track(
|
||||
name='track1', length=4000, artists=artists[:1],
|
||||
album=albums[0], uri='file://' + path_to_data_dir('uri1')),
|
||||
uri='file://' + path_to_data_dir('uri1'), name='track1',
|
||||
artists=artists[:1], album=albums[0], date='2001-02-03',
|
||||
length=4000),
|
||||
Track(
|
||||
name='track2', length=4000, artists=artists[1:2],
|
||||
album=albums[1], uri='file://' + path_to_data_dir('uri2')),
|
||||
uri='file://' + path_to_data_dir('uri2'), name='track2',
|
||||
artists=artists[1:2], album=albums[1], date='2002', length=4000),
|
||||
Track()]
|
||||
|
||||
def setUp(self):
|
||||
@ -90,6 +91,16 @@ class LibraryControllerTest(object):
|
||||
result = self.library.find_exact(album=['album2'])
|
||||
self.assertEqual(result, self.tracks[1:2])
|
||||
|
||||
def test_find_exact_date(self):
|
||||
result = self.library.find_exact(date=['2001'])
|
||||
self.assertEqual(result, [])
|
||||
|
||||
result = self.library.find_exact(date=['2001-02-03'])
|
||||
self.assertEqual(result, self.tracks[:1])
|
||||
|
||||
result = self.library.find_exact(date=['2002'])
|
||||
self.assertEqual(result, self.tracks[1:2])
|
||||
|
||||
def test_find_exact_wrong_type(self):
|
||||
test = lambda: self.library.find_exact(wrong=['test'])
|
||||
self.assertRaises(LookupError, test)
|
||||
@ -148,6 +159,19 @@ class LibraryControllerTest(object):
|
||||
result = self.library.search(album=['Bum2'])
|
||||
self.assertEqual(result, self.tracks[1:2])
|
||||
|
||||
def test_search_date(self):
|
||||
result = self.library.search(date=['2001'])
|
||||
self.assertEqual(result, self.tracks[:1])
|
||||
|
||||
result = self.library.search(date=['2001-02-03'])
|
||||
self.assertEqual(result, self.tracks[:1])
|
||||
|
||||
result = self.library.search(date=['2001-02-04'])
|
||||
self.assertEqual(result, [])
|
||||
|
||||
result = self.library.search(date=['2002'])
|
||||
self.assertEqual(result, self.tracks[1:2])
|
||||
|
||||
def test_search_any(self):
|
||||
result = self.library.search(any=['Tist1'])
|
||||
self.assertEqual(result, self.tracks[:1])
|
||||
|
||||
@ -8,12 +8,14 @@ file: /uri1
|
||||
Artist: artist1
|
||||
Title: track1
|
||||
Album: album1
|
||||
Date: 2001-02-03
|
||||
Time: 4
|
||||
key: uri2
|
||||
file: /uri2
|
||||
Artist: artist2
|
||||
Title: track2
|
||||
Album: album2
|
||||
Date: 2002
|
||||
Time: 4
|
||||
key: uri3
|
||||
file: /uri3
|
||||
|
||||
Loading…
Reference in New Issue
Block a user