def playlistinfo(context, parameter=None): """ *musicpd.org, current playlist section:* ``playlistinfo [[SONGPOS] | [START:END]]`` Displays a list of all songs in the playlist, or if the optional argument is given, displays information only for the song ``SONGPOS`` or the range of songs ``START:END``. *ncmpc and mpc:* - uses negative indexes, like ``playlistinfo "-1"``, to request the entire playlist """ if parameter is None or parameter == '-1': start, end = 0, None else: tracklist_slice = protocol.RANGE(parameter) start, end = tracklist_slice.start, tracklist_slice.stop tl_tracks = context.core.tracklist.tl_tracks.get() if start and start > len(tl_tracks): raise exceptions.MpdArgError('Bad song index') if end and end > len(tl_tracks): end = None return translator.tracks_to_mpd_format(tl_tracks, start, end)
def test_range(self): self.assertEqual(slice(1, 2), protocol.RANGE('1')) self.assertEqual(slice(0, 1), protocol.RANGE('0')) self.assertEqual(slice(0, None), protocol.RANGE('0:')) self.assertEqual(slice(1, 3), protocol.RANGE('1:3')) self.assertRaises(ValueError, protocol.RANGE, '3.14') self.assertRaises(ValueError, protocol.RANGE, '1:abc') self.assertRaises(ValueError, protocol.RANGE, 'abc:1') self.assertRaises(ValueError, protocol.RANGE, '2:1') self.assertRaises(ValueError, protocol.RANGE, '-1:2') self.assertRaises(ValueError, protocol.RANGE, '1 : 2') self.assertRaises(ValueError, protocol.RANGE, '') self.assertRaises(ValueError, protocol.RANGE, 'true') self.assertRaises(ValueError, protocol.RANGE, 'false') self.assertRaises(ValueError, protocol.RANGE, 'abc') self.assertRaises(ValueError, protocol.RANGE, '12 34')