Implement _current_playlist_playlistid when songid argument is given

This commit is contained in:
Stein Magnus Jodal 2010-02-28 22:15:15 +01:00
parent 2dea0820b2
commit e3b407c709
2 changed files with 29 additions and 4 deletions

View File

@ -373,7 +373,7 @@ class MpdHandler(object):
""" """
raise MpdNotImplemented # TODO raise MpdNotImplemented # TODO
@handle_pattern(r'^playlistid( "(?P<songid>\S+)")*$') @handle_pattern(r'^playlistid( "(?P<songid>\d+)")*$')
def _current_playlist_playlistid(self, songid=None): def _current_playlist_playlistid(self, songid=None):
""" """
*musicpd.org, current playlist section:* *musicpd.org, current playlist section:*
@ -383,8 +383,15 @@ class MpdHandler(object):
Displays a list of songs in the playlist. ``SONGID`` is optional Displays a list of songs in the playlist. ``SONGID`` is optional
and specifies a single song to display info for. and specifies a single song to display info for.
""" """
# TODO Limit selection to songid if songid is not None:
return self.backend.current_playlist.playlist.mpd_format() try:
songid = int(songid)
track = self.backend.current_playlist.get_by_id(songid)
return track.mpd_format()
except KeyError, e:
raise MpdAckError(e)
else:
return self.backend.current_playlist.playlist.mpd_format()
@handle_pattern(r'^playlistinfo$') @handle_pattern(r'^playlistinfo$')
@handle_pattern(r'^playlistinfo "(?P<songpos>\d+)"$') @handle_pattern(r'^playlistinfo "(?P<songpos>\d+)"$')

View File

@ -653,13 +653,31 @@ class CurrentPlaylistHandlerTest(unittest.TestCase):
self.assert_(u'ACK Not implemented' in result) self.assert_(u'ACK Not implemented' in result)
def test_playlistid_without_songid(self): def test_playlistid_without_songid(self):
self.b.current_playlist.load(Playlist(
tracks=[Track(name='a', id=33), Track(name='b', id=38)]))
result = self.h.handle_request(u'playlistid') result = self.h.handle_request(u'playlistid')
self.assert_(u'Title: a' in result)
self.assert_(u'Id: 33' in result)
self.assert_(u'Title: b' in result)
self.assert_(u'Id: 38' in result)
self.assert_(u'OK' in result) self.assert_(u'OK' in result)
def test_playlistid_with_songid(self): def test_playlistid_with_songid(self):
result = self.h.handle_request(u'playlistid "10"') self.b.current_playlist.load(Playlist(
tracks=[Track(name='a', id=33), Track(name='b', id=38)]))
result = self.h.handle_request(u'playlistid "38"')
self.assert_(u'Title: a' not in result)
self.assert_(u'Id: 33' not in result)
self.assert_(u'Title: b' in result)
self.assert_(u'Id: 38' in result)
self.assert_(u'OK' in result) self.assert_(u'OK' in result)
def test_playlistid_with_not_existing_songid_fails(self):
self.b.current_playlist.load(Playlist(
tracks=[Track(name='a', id=33), Track(name='b', id=38)]))
result = self.h.handle_request(u'playlistid "25"')
self.assert_(u'ACK Track with ID "25" not found' in result)
def test_playlistinfo_without_songpos_or_range(self): def test_playlistinfo_without_songpos_or_range(self):
result = self.h.handle_request(u'playlistinfo') result = self.h.handle_request(u'playlistinfo')
self.assert_(u'OK' in result) self.assert_(u'OK' in result)