diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index b04c86d0..ca0d1156 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -225,6 +225,7 @@ def playlistid(context, cpid=None): context.backend.current_playlist.cp_tracks.get()) @handle_request(r'^playlistinfo$') +@handle_request(r'^playlistinfo "-1"$') @handle_request(r'^playlistinfo "(?P-?\d+)"$') @handle_request(r'^playlistinfo "(?P\d+):(?P\d+)*"$') def playlistinfo(context, songpos=None, @@ -243,20 +244,10 @@ def playlistinfo(context, songpos=None, - uses negative indexes, like ``playlistinfo "-1"``, to request the entire playlist """ - if songpos == "-1": - songpos = None - if songpos is not None: songpos = int(songpos) - start = songpos - end = songpos + 1 - if start == -1: - end = None - else: - # Hot code path: Fetch a single track, while avoiding deep-copying - # the entire playlist - cp_track = context.backend.current_playlist.get(cpid=songpos).get() - return tracks_to_mpd_format([cp_track], 0, 1) + cp_track = context.backend.current_playlist.get(cpid=songpos).get() + return track_to_mpd_format(cp_track, position=songpos) else: if start is None: start = 0 @@ -267,8 +258,8 @@ def playlistinfo(context, songpos=None, end = int(end) if end > context.backend.current_playlist.length.get(): end = None - cp_tracks = context.backend.current_playlist.cp_tracks.get() - return tracks_to_mpd_format(cp_tracks, start, end) + cp_tracks = context.backend.current_playlist.cp_tracks.get() + return tracks_to_mpd_format(cp_tracks, start, end) @handle_request(r'^playlistsearch "(?P[^"]+)" "(?P[^"]+)"$') @handle_request(r'^playlistsearch (?P\S+) "(?P[^"]+)"$') diff --git a/tests/frontends/mpd/protocol/current_playlist_test.py b/tests/frontends/mpd/protocol/current_playlist_test.py index 343b230b..321fc6ee 100644 --- a/tests/frontends/mpd/protocol/current_playlist_test.py +++ b/tests/frontends/mpd/protocol/current_playlist_test.py @@ -271,11 +271,17 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.sendRequest(u'playlistinfo') self.assertInResponse(u'Title: a') + self.assertInResponse(u'Pos: 0') self.assertInResponse(u'Title: b') + self.assertInResponse(u'Pos: 1') self.assertInResponse(u'Title: c') + self.assertInResponse(u'Pos: 2') self.assertInResponse(u'Title: d') + self.assertInResponse(u'Pos: 3') self.assertInResponse(u'Title: e') + self.assertInResponse(u'Pos: 4') self.assertInResponse(u'Title: f') + self.assertInResponse(u'Pos: 5') self.assertInResponse(u'OK') def test_playlistinfo_with_songpos(self): @@ -286,11 +292,17 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.sendRequest(u'playlistinfo "4"') self.assertNotInResponse(u'Title: a') + self.assertNotInResponse(u'Pos: 0') self.assertNotInResponse(u'Title: b') + self.assertNotInResponse(u'Pos: 1') self.assertNotInResponse(u'Title: c') + self.assertNotInResponse(u'Pos: 2') self.assertNotInResponse(u'Title: d') + self.assertNotInResponse(u'Pos: 3') self.assertInResponse(u'Title: e') + self.assertInResponse(u'Pos: 4') self.assertNotInResponse(u'Title: f') + self.assertNotInResponse(u'Pos: 5') self.assertInResponse(u'OK') def test_playlistinfo_with_negative_songpos_same_as_playlistinfo(self): @@ -306,11 +318,17 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.sendRequest(u'playlistinfo "2:"') self.assertNotInResponse(u'Title: a') + self.assertNotInResponse(u'Pos: 0') self.assertNotInResponse(u'Title: b') + self.assertNotInResponse(u'Pos: 1') self.assertInResponse(u'Title: c') + self.assertInResponse(u'Pos: 2') self.assertInResponse(u'Title: d') + self.assertInResponse(u'Pos: 3') self.assertInResponse(u'Title: e') + self.assertInResponse(u'Pos: 4') self.assertInResponse(u'Title: f') + self.assertInResponse(u'Pos: 5') self.assertInResponse(u'OK') def test_playlistinfo_with_closed_range(self):