diff --git a/mopidy/backends/__init__.py b/mopidy/backends/__init__.py index f0d700c9..e10dd120 100644 --- a/mopidy/backends/__init__.py +++ b/mopidy/backends/__init__.py @@ -430,6 +430,10 @@ class BaseStoredPlaylistsController(object): """List of :class:`mopidy.models.Playlist`.""" return copy(self._playlists) + @playlists.setter + def playlists(self, playlists): + self._playlists = playlists + def create(self, name): """ Create a new playlist. @@ -449,6 +453,24 @@ class BaseStoredPlaylistsController(object): """ raise NotImplementedError + def get_by_name(self, name): + """ + Get playlist with given name from the set of stored playlists. + + Raises :exc:`KeyError` if not a unique match is found. + + :param name: playlist name + :type name: string + :rtype: :class:`mopidy.models.Playlist` + """ + matches = filter(lambda p: name == p.name, self._playlists) + if len(matches) == 1: + return matches[0] + elif len(matches) == 0: + raise KeyError('Name "%s" not found' % name) + else: + raise KeyError('Name "%s" matched multiple elements' % name) + def lookup(self, uri): """ Lookup playlist with given URI in both the set of stored playlists and