From bf0560231827f5f9fcb4210810617078fcdc5524 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 22 Mar 2010 22:09:00 +0100 Subject: [PATCH] Add support for 'playlistfind filename ...' --- mopidy/mpd/frontend.py | 11 +++++++++++ tests/mpd/frontendtest.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/mopidy/mpd/frontend.py b/mopidy/mpd/frontend.py index 8ffa08ab..7a402ebe 100644 --- a/mopidy/mpd/frontend.py +++ b/mopidy/mpd/frontend.py @@ -371,6 +371,7 @@ class MpdFrontend(object): """ return self._current_playlist_playlistinfo() + @handle_pattern(r'^playlistfind (?P[^"]+) "(?P[^"]+)"$') @handle_pattern(r'^playlistfind "(?P[^"]+)" "(?P[^"]+)"$') def _current_playlist_playlistfind(self, tag, needle): """ @@ -379,7 +380,17 @@ class MpdFrontend(object): ``playlistfind {TAG} {NEEDLE}`` Finds songs in the current playlist with strict matching. + + *GMPC:* + + - does not add quotes around the tag. """ + if tag == 'filename': + try: + track = self.backend.current_playlist.get_by_uri(needle) + return track.mpd_format() + except KeyError: + return None raise MpdNotImplemented # TODO @handle_pattern(r'^playlistid( "(?P\d+)")*$') diff --git a/tests/mpd/frontendtest.py b/tests/mpd/frontendtest.py index 56c8f830..881ee181 100644 --- a/tests/mpd/frontendtest.py +++ b/tests/mpd/frontendtest.py @@ -652,6 +652,21 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): result = self.h.handle_request(u'playlistfind "tag" "needle"') self.assert_(u'ACK Not implemented' in result) + def test_playlistfind_by_filename(self): + result = self.h.handle_request(u'playlistfind "filename" "file:///dev/null"') + self.assert_(u'OK' in result) + + def test_playlistfind_by_filename_without_quotes(self): + result = self.h.handle_request(u'playlistfind filename "file:///dev/null"') + self.assert_(u'OK' in result) + + def test_playlistfind_by_filename_in_current_playlist(self): + self.b.current_playlist.playlist = Playlist(tracks=[ + Track(uri='file:///exists')]) + result = self.h.handle_request(u'playlistfind filename "file:///exists"') + self.assert_(u'file: file:///exists' in result) + self.assert_(u'OK' in result) + def test_playlistid_without_songid(self): self.b.current_playlist.load(Playlist( tracks=[Track(name='a', id=33), Track(name='b', id=38)]))