From 579a93437f8eda28bd9eb126cc8f247406be8247 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 9 Jul 2013 11:48:11 +0200 Subject: [PATCH] mpd: Allow full MPD queries to 'count' Fix hechtus/mopidy-gmusic#1 --- mopidy/frontends/mpd/protocol/music_db.py | 5 +++-- tests/frontends/mpd/protocol/music_db_test.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index 4eb0e47d..8e31dbf8 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -39,8 +39,8 @@ def _artist_as_track(artist): artists=[artist]) -@handle_request(r'^count "?(?P[^"]+)"? "(?P[^"]*)"$') -def count(context, tag, needle): +@handle_request(r'^count ' + QUERY_RE) +def count(context, mpd_query): """ *musicpd.org, music database section:* @@ -52,6 +52,7 @@ def count(context, tag, needle): *GMPC:* - does not add quotes around the tag argument. + - use multiple tag-needle pairs to make more specific searches. """ return [('songs', 0), ('playtime', 0)] # TODO diff --git a/tests/frontends/mpd/protocol/music_db_test.py b/tests/frontends/mpd/protocol/music_db_test.py index a155072e..fa909bab 100644 --- a/tests/frontends/mpd/protocol/music_db_test.py +++ b/tests/frontends/mpd/protocol/music_db_test.py @@ -7,13 +7,19 @@ from tests.frontends.mpd import protocol class MusicDatabaseHandlerTest(protocol.BaseTestCase): def test_count(self): - self.sendRequest('count "tag" "needle"') + self.sendRequest('count "artist" "needle"') self.assertInResponse('songs: 0') self.assertInResponse('playtime: 0') self.assertInResponse('OK') def test_count_without_quotes(self): - self.sendRequest('count tag "needle"') + self.sendRequest('count artist "needle"') + self.assertInResponse('songs: 0') + self.assertInResponse('playtime: 0') + self.assertInResponse('OK') + + def test_count_with_multiple_pairs(self): + self.sendRequest('count "artist" "foo" "album" "bar"') self.assertInResponse('songs: 0') self.assertInResponse('playtime: 0') self.assertInResponse('OK')