mpd: Move playlist.lookup() out of helper
This commit is contained in:
parent
e06c7708a7
commit
f48a8ad938
@ -245,11 +245,11 @@ class MpdContext(object):
|
||||
self.subscriptions = set()
|
||||
self._uri_map = uri_map
|
||||
|
||||
def lookup_playlist_from_name(self, name):
|
||||
def lookup_playlist_uri_from_name(self, name):
|
||||
"""
|
||||
Helper function to retrieve a playlist from its unique MPD name.
|
||||
"""
|
||||
return self._uri_map.playlist_from_name(name)
|
||||
return self._uri_map.playlist_uri_from_name(name)
|
||||
|
||||
def lookup_playlist_name_from_uri(self, uri):
|
||||
"""
|
||||
|
||||
@ -465,7 +465,8 @@ def searchaddpl(context, *args):
|
||||
return
|
||||
results = context.core.library.search(**query).get()
|
||||
|
||||
playlist = context.lookup_playlist_from_name(playlist_name)
|
||||
uri = context.lookup_playlist_uri_from_name(playlist_name)
|
||||
playlist = uri is not None and context.core.playlists.lookup(uri).get()
|
||||
if not playlist:
|
||||
playlist = context.core.playlists.create(playlist_name).get()
|
||||
tracks = list(playlist.tracks) + _get_tracks(results)
|
||||
|
||||
@ -20,7 +20,8 @@ def listplaylist(context, name):
|
||||
file: relative/path/to/file2.ogg
|
||||
file: relative/path/to/file3.mp3
|
||||
"""
|
||||
playlist = context.lookup_playlist_from_name(name)
|
||||
uri = context.lookup_playlist_uri_from_name(name)
|
||||
playlist = uri is not None and context.core.playlists.lookup(uri).get()
|
||||
if not playlist:
|
||||
raise exceptions.MpdNoExistError('No such playlist')
|
||||
return ['file: %s' % t.uri for t in playlist.tracks]
|
||||
@ -40,7 +41,8 @@ def listplaylistinfo(context, name):
|
||||
Standard track listing, with fields: file, Time, Title, Date,
|
||||
Album, Artist, Track
|
||||
"""
|
||||
playlist = context.lookup_playlist_from_name(name)
|
||||
uri = context.lookup_playlist_uri_from_name(name)
|
||||
playlist = uri is not None and context.core.playlists.lookup(uri).get()
|
||||
if not playlist:
|
||||
raise exceptions.MpdNoExistError('No such playlist')
|
||||
return translator.playlist_to_mpd_format(playlist)
|
||||
@ -121,7 +123,8 @@ def load(context, name, playlist_slice=slice(0, None)):
|
||||
- MPD 0.17.1 does not fail if the specified range is outside the playlist,
|
||||
in either or both ends.
|
||||
"""
|
||||
playlist = context.lookup_playlist_from_name(name)
|
||||
uri = context.lookup_playlist_uri_from_name(name)
|
||||
playlist = uri is not None and context.core.playlists.lookup(uri).get()
|
||||
if not playlist:
|
||||
raise exceptions.MpdNoExistError('No such playlist')
|
||||
context.core.tracklist.add(playlist.tracks[playlist_slice])
|
||||
|
||||
@ -59,16 +59,13 @@ class MpdUriMapper(object):
|
||||
name = self._invalid_playlist_chars.sub('|', playlist.name)
|
||||
self.insert(name, playlist.uri)
|
||||
|
||||
def playlist_from_name(self, name):
|
||||
def playlist_uri_from_name(self, name):
|
||||
"""
|
||||
Helper function to retrieve a playlist from its unique MPD name.
|
||||
Helper function to retrieve a playlist URI from its unique MPD name.
|
||||
"""
|
||||
if not self._uri_from_name:
|
||||
self.refresh_playlists_mapping()
|
||||
if name not in self._uri_from_name:
|
||||
return None
|
||||
uri = self._uri_from_name[name]
|
||||
return self.core.playlists.lookup(uri).get()
|
||||
return self._uri_from_name.get(name)
|
||||
|
||||
def playlist_name_from_uri(self, uri):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user