Access playlist_name_from_uri mapping through helper function and make dict private
This commit is contained in:
parent
28b00dbea1
commit
fd03acb463
@ -236,9 +236,6 @@ class MpdContext(object):
|
|||||||
#: The subsytems that we want to be notified about in idle mode.
|
#: The subsytems that we want to be notified about in idle mode.
|
||||||
subscriptions = None
|
subscriptions = None
|
||||||
|
|
||||||
_playlist_uri_from_name = None
|
|
||||||
playlist_name_from_uri = None
|
|
||||||
|
|
||||||
def __init__(self, dispatcher, session=None, config=None, core=None):
|
def __init__(self, dispatcher, session=None, config=None, core=None):
|
||||||
self.dispatcher = dispatcher
|
self.dispatcher = dispatcher
|
||||||
self.session = session
|
self.session = session
|
||||||
@ -247,7 +244,7 @@ class MpdContext(object):
|
|||||||
self.events = set()
|
self.events = set()
|
||||||
self.subscriptions = set()
|
self.subscriptions = set()
|
||||||
self._playlist_uri_from_name = {}
|
self._playlist_uri_from_name = {}
|
||||||
self.playlist_name_from_uri = {}
|
self._playlist_name_from_uri = {}
|
||||||
self.refresh_playlists_mapping()
|
self.refresh_playlists_mapping()
|
||||||
|
|
||||||
def create_unique_name(self, playlist_name):
|
def create_unique_name(self, playlist_name):
|
||||||
@ -265,13 +262,13 @@ class MpdContext(object):
|
|||||||
"""
|
"""
|
||||||
if self.core is not None:
|
if self.core is not None:
|
||||||
self._playlist_uri_from_name.clear()
|
self._playlist_uri_from_name.clear()
|
||||||
self.playlist_name_from_uri.clear()
|
self._playlist_name_from_uri.clear()
|
||||||
for playlist in self.core.playlists.playlists.get():
|
for playlist in self.core.playlists.playlists.get():
|
||||||
if not playlist.name:
|
if not playlist.name:
|
||||||
continue
|
continue
|
||||||
name = self.create_unique_name(playlist.name)
|
name = self.create_unique_name(playlist.name)
|
||||||
self._playlist_uri_from_name[name] = playlist.uri
|
self._playlist_uri_from_name[name] = playlist.uri
|
||||||
self.playlist_name_from_uri[playlist.uri] = name
|
self._playlist_name_from_uri[playlist.uri] = name
|
||||||
|
|
||||||
def lookup_playlist_from_name(self, name):
|
def lookup_playlist_from_name(self, name):
|
||||||
"""
|
"""
|
||||||
@ -283,3 +280,11 @@ class MpdContext(object):
|
|||||||
return None
|
return None
|
||||||
uri = self._playlist_uri_from_name[name]
|
uri = self._playlist_uri_from_name[name]
|
||||||
return self.core.playlists.lookup(uri).get()
|
return self.core.playlists.lookup(uri).get()
|
||||||
|
|
||||||
|
def lookup_playlist_name_from_uri(self, uri):
|
||||||
|
"""
|
||||||
|
Helper function to retrieve the unique MPD playlist name from its uri.
|
||||||
|
"""
|
||||||
|
if uri not in self._playlist_name_from_uri:
|
||||||
|
self.refresh_playlists_mapping()
|
||||||
|
return self._playlist_name_from_uri[uri]
|
||||||
|
|||||||
@ -80,10 +80,7 @@ def listplaylists(context):
|
|||||||
for playlist in context.core.playlists.playlists.get():
|
for playlist in context.core.playlists.playlists.get():
|
||||||
if not playlist.name:
|
if not playlist.name:
|
||||||
continue
|
continue
|
||||||
if playlist.uri not in context.playlist_name_from_uri:
|
name = context.lookup_playlist_name_from_uri(playlist.uri)
|
||||||
# the maps are not synced, we refresh them
|
|
||||||
context.refresh_playlists_mapping()
|
|
||||||
name = context.playlist_name_from_uri[playlist.uri]
|
|
||||||
result.append(('playlist', name))
|
result.append(('playlist', name))
|
||||||
last_modified = (
|
last_modified = (
|
||||||
playlist.last_modified or dt.datetime.utcnow()).isoformat()
|
playlist.last_modified or dt.datetime.utcnow()).isoformat()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user