From 255d70d1ae105cf5fb9131a84546d7ee16c19e68 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 12:20:14 +0200 Subject: [PATCH 1/2] MPD: Support 'plchanges "-1"' to work better with MPDroid --- docs/changes.rst | 1 + mopidy/frontends/mpd/protocol/current_playlist.py | 6 +++++- tests/frontends/mpd/current_playlist_test.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index c8e4c912..6f806425 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -23,6 +23,7 @@ Another great release. - Split gigantic protocol implementation into eleven modules. - Search improvements, including support for multi-word search. - Fixed ``play "-1"`` and ``playid "-1"`` behaviour when playlist is empty. + - Support ``plchanges "-1"`` to work better with MPDroid. - Backend API: diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index da052fff..76ae62ef 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -257,7 +257,7 @@ def playlistsearch(frontend, tag, needle): """ raise MpdNotImplemented # TODO -@handle_pattern(r'^plchanges "(?P\d+)"$') +@handle_pattern(r'^plchanges "(?P-?\d+)"$') def plchanges(frontend, version): """ *musicpd.org, current playlist section:* @@ -268,6 +268,10 @@ def plchanges(frontend, version): To detect songs that were deleted at the end of the playlist, use ``playlistlength`` returned by status command. + + *MPDroid:* + + - Calls ``plchanges "-1"`` two times per second to get the entire playlist. """ # XXX Naive implementation that returns all tracks as changed if int(version) < frontend.backend.current_playlist.version: diff --git a/tests/frontends/mpd/current_playlist_test.py b/tests/frontends/mpd/current_playlist_test.py index ce1e4069..062da6d4 100644 --- a/tests/frontends/mpd/current_playlist_test.py +++ b/tests/frontends/mpd/current_playlist_test.py @@ -321,6 +321,15 @@ class CurrentPlaylistHandlerTest(unittest.TestCase): self.assert_(u'Title: c' in result) self.assert_(u'OK' in result) + def test_plchanges_with_minus_one_returns_entire_playlist(self): + self.b.current_playlist.load( + [Track(name='a'), Track(name='b'), Track(name='c')]) + result = self.h.handle_request(u'plchanges "-1"') + self.assert_(u'Title: a' in result) + self.assert_(u'Title: b' in result) + self.assert_(u'Title: c' in result) + self.assert_(u'OK' in result) + def test_plchangesposid(self): self.b.current_playlist.load([Track(), Track(), Track()]) result = self.h.handle_request(u'plchangesposid "0"') From a3fb8a1f72474414876e20d0573210594a77105d Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 13 Aug 2010 12:26:34 +0200 Subject: [PATCH 2/2] MPD: Support 'pause' without args to work with MPDroid --- docs/changes.rst | 1 + mopidy/frontends/mpd/protocol/playback.py | 16 ++++++++++++++-- tests/frontends/mpd/playback_test.py | 21 +++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 6f806425..70d9390f 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -24,6 +24,7 @@ Another great release. - Search improvements, including support for multi-word search. - Fixed ``play "-1"`` and ``playid "-1"`` behaviour when playlist is empty. - Support ``plchanges "-1"`` to work better with MPDroid. + - Support ``pause`` without arguments to work better with MPDroid. - Backend API: diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 719bd8b5..53cc2bbc 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -86,16 +86,28 @@ def next_(frontend): """ return frontend.backend.playback.next() +@handle_pattern(r'^pause$') @handle_pattern(r'^pause "(?P[01])"$') -def pause(frontend, state): +def pause(frontend, state=None): """ *musicpd.org, playback section:* ``pause {PAUSE}`` Toggles pause/resumes playing, ``PAUSE`` is 0 or 1. + + *MPDroid:* + + - Calls ``pause`` without any arguments to toogle pause. """ - if int(state): + if state is None: + if (frontend.backend.playback.state == + frontend.backend.playback.PLAYING): + frontend.backend.playback.pause() + elif (frontend.backend.playback.state == + frontend.backend.playback.PAUSED): + frontend.backend.playback.resume() + elif int(state): frontend.backend.playback.pause() else: frontend.backend.playback.resume() diff --git a/tests/frontends/mpd/playback_test.py b/tests/frontends/mpd/playback_test.py index aee05d6c..e76cb9df 100644 --- a/tests/frontends/mpd/playback_test.py +++ b/tests/frontends/mpd/playback_test.py @@ -136,8 +136,7 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assert_(u'OK' in result) def test_pause_off(self): - track = Track() - self.b.current_playlist.load([track]) + self.b.current_playlist.load([Track()]) self.h.handle_request(u'play "0"') self.h.handle_request(u'pause "1"') result = self.h.handle_request(u'pause "0"') @@ -145,16 +144,26 @@ class PlaybackControlHandlerTest(unittest.TestCase): self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) def test_pause_on(self): - track = Track() - self.b.current_playlist.load([track]) + self.b.current_playlist.load([Track()]) self.h.handle_request(u'play "0"') result = self.h.handle_request(u'pause "1"') self.assert_(u'OK' in result) self.assertEqual(self.b.playback.PAUSED, self.b.playback.state) + def test_pause_toggle(self): + self.b.current_playlist.load([Track()]) + result = self.h.handle_request(u'play "0"') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) + result = self.h.handle_request(u'pause') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PAUSED, self.b.playback.state) + result = self.h.handle_request(u'pause') + self.assert_(u'OK' in result) + self.assertEqual(self.b.playback.PLAYING, self.b.playback.state) + def test_play_without_pos(self): - track = Track() - self.b.current_playlist.load([track]) + self.b.current_playlist.load([Track()]) self.b.playback.state = self.b.playback.PAUSED result = self.h.handle_request(u'play') self.assert_(u'OK' in result)