Add get_by_id() and get_by_uri() to BaseCurrentPlaylistController
This commit is contained in:
parent
2a30d40ed5
commit
acdfff5b61
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user