mpd: Allow 'file' key to 'search' and 'find'
This commit is contained in:
parent
344d5bd49d
commit
4f0a708411
@ -99,6 +99,9 @@ backends:
|
||||
- The settings validator will now allow any setting prefixed with ``CUSTOM_``
|
||||
to exist in the settings file.
|
||||
|
||||
- The MPD commands ``search`` and ``find`` now allows the key ``file``, which
|
||||
is used by ncmpcpp instead of ``filename``.
|
||||
|
||||
**Bug fixes**
|
||||
|
||||
- :issue:`218`: The MPD commands ``listplaylist`` and ``listplaylistinfo`` now
|
||||
|
||||
@ -13,10 +13,10 @@ def _build_query(mpd_query):
|
||||
Parses a MPD query string and converts it to the Mopidy query format.
|
||||
"""
|
||||
query_pattern = (
|
||||
r'"?(?:[Aa]lbum|[Aa]rtist|[Ff]ilename|[Tt]itle|[Aa]ny)"? "[^"]+"')
|
||||
r'"?(?:[Aa]lbum|[Aa]rtist|[Ff]ile[name]*|[Tt]itle|[Aa]ny)"? "[^"]+"')
|
||||
query_parts = re.findall(query_pattern, mpd_query)
|
||||
query_part_pattern = (
|
||||
r'"?(?P<field>([Aa]lbum|[Aa]rtist|[Ff]ilename|[Tt]itle|[Aa]ny))"? '
|
||||
r'"?(?P<field>([Aa]lbum|[Aa]rtist|[Ff]ile[name]*|[Tt]itle|[Aa]ny))"? '
|
||||
r'"(?P<what>[^"]+)"')
|
||||
query = {}
|
||||
for query_part in query_parts:
|
||||
@ -24,6 +24,8 @@ def _build_query(mpd_query):
|
||||
field = m.groupdict()['field'].lower()
|
||||
if field == 'title':
|
||||
field = 'track'
|
||||
elif field == 'file':
|
||||
field = 'filename'
|
||||
field = str(field) # Needed for kwargs keys on OS X and Windows
|
||||
what = m.groupdict()['what'].lower()
|
||||
if field in query:
|
||||
@ -47,7 +49,7 @@ def count(context, tag, needle):
|
||||
|
||||
|
||||
@handle_request(
|
||||
r'^find (?P<mpd_query>("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ilename|'
|
||||
r'^find (?P<mpd_query>("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ile[name]*|'
|
||||
r'[Tt]itle|[Aa]ny)"? "[^"]+"\s?)+)$')
|
||||
def find(context, mpd_query):
|
||||
"""
|
||||
@ -72,6 +74,7 @@ def find(context, mpd_query):
|
||||
*ncmpcpp:*
|
||||
|
||||
- also uses the search type "date".
|
||||
- uses "file" instead of "filename".
|
||||
"""
|
||||
query = _build_query(mpd_query)
|
||||
return playlist_to_mpd_format(
|
||||
@ -320,7 +323,7 @@ def rescan(context, uri=None):
|
||||
|
||||
|
||||
@handle_request(
|
||||
r'^search (?P<mpd_query>("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ilename|'
|
||||
r'^search (?P<mpd_query>("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ile[name]*|'
|
||||
r'[Tt]itle|[Aa]ny)"? "[^"]+"\s?)+)$')
|
||||
def search(context, mpd_query):
|
||||
"""
|
||||
@ -348,6 +351,7 @@ def search(context, mpd_query):
|
||||
*ncmpcpp:*
|
||||
|
||||
- also uses the search type "date".
|
||||
- uses "file" instead of "filename".
|
||||
"""
|
||||
query = _build_query(mpd_query)
|
||||
return playlist_to_mpd_format(
|
||||
|
||||
@ -75,6 +75,22 @@ class MusicDatabaseFindTest(protocol.BaseTestCase):
|
||||
self.sendRequest('find artist "what"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_find_filename(self):
|
||||
self.sendRequest('find "filename" "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_find_filename_without_quotes(self):
|
||||
self.sendRequest('find filename "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_find_file(self):
|
||||
self.sendRequest('find "file" "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_find_file_without_quotes(self):
|
||||
self.sendRequest('find file "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_find_title(self):
|
||||
self.sendRequest('find "title" "what"')
|
||||
self.assertInResponse('OK')
|
||||
@ -313,6 +329,14 @@ class MusicDatabaseSearchTest(protocol.BaseTestCase):
|
||||
self.sendRequest('search filename "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_search_file(self):
|
||||
self.sendRequest('search "file" "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_search_file_without_quotes(self):
|
||||
self.sendRequest('search file "afilename"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
def test_search_title(self):
|
||||
self.sendRequest('search "title" "atitle"')
|
||||
self.assertInResponse('OK')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user