Add get_by_id() and get_by_uri() to BaseCurrentPlaylistController

This commit is contained in:
Stein Magnus Jodal 2010-02-07 23:36:53 +01:00
parent 2a30d40ed5
commit acdfff5b61
2 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,20 @@
Clear the current playlist.
.. method:: get_by_id(id)
Get track by ID. Raises :class:`KeyError` if not found.
:param id: track ID
:type id: int
.. method:: get_by_uri(uri)
Get track by URI. Raises :class:`KeyError` if not found.
:param uri: track URI
:type uri: string
.. method:: load(playlist)
Replace the current playlist with the given playlist.

View File

@ -37,6 +37,20 @@ class BaseCurrentPlaylistController(object):
self.backend.playback.stop()
self.playlist = Playlist()
def get_by_id(self, id):
matches = filter(lambda t: t.id == id, self._playlist.tracks)
if matches:
return matches[0]
else:
raise KeyError('Track with ID "%s" not found' % id)
def get_by_uri(self, uri):
matches = filter(lambda t: t.uri == uri, self._playlist.tracks)
if matches:
return matches[0]
else:
raise KeyError('Track with URI "%s" not found' % uri)
def load(self, playlist):
self.playlist = playlist
self.version = 0