mpd: fix style issues and type errors introduced in 87ce309
Tests are now OK
This commit is contained in:
parent
87ce309749
commit
698f505da6
@ -245,20 +245,21 @@ class MpdContext(object):
|
||||
self.core = core
|
||||
self.events = set()
|
||||
self.subscriptions = set()
|
||||
self.to_uri = dict()
|
||||
self.from_uri = dict()
|
||||
self.refresh_maps()
|
||||
self.to_uri = {}
|
||||
self.from_uri = {}
|
||||
self.refresh_playlists_mapping()
|
||||
|
||||
def refresh_maps(self):
|
||||
self.to_uri.clear()
|
||||
self.from_uri.clear()
|
||||
for playlist in self.core.playlists.playlists.get():
|
||||
if not playlist.name:
|
||||
continue
|
||||
name = playlist.name
|
||||
i = 1
|
||||
while name in self.to_uri:
|
||||
name = '%s [%d]' % playlist.name % i
|
||||
i += 1
|
||||
self.to_uri[name] = playlist.uri
|
||||
self.from_uri[playlist.uri] = name
|
||||
def refresh_playlists_mapping(self):
|
||||
if self.core is not None:
|
||||
self.to_uri.clear()
|
||||
self.from_uri.clear()
|
||||
for playlist in self.core.playlists.playlists.get():
|
||||
if not playlist.name:
|
||||
continue
|
||||
name = playlist.name
|
||||
i = 1
|
||||
while name in self.to_uri:
|
||||
name = '%s [%d]' % playlist.name % i
|
||||
i += 1
|
||||
self.to_uri[name] = playlist.uri
|
||||
self.from_uri[playlist.uri] = name
|
||||
|
||||
@ -381,8 +381,11 @@ def searchaddpl(context, playlist_name, mpd_query):
|
||||
return
|
||||
results = context.core.library.search(**query).get()
|
||||
|
||||
if len(context.to_uri) == 0:
|
||||
context.refresh_playlists_mapping()
|
||||
|
||||
if playlist_name in context.to_uri:
|
||||
playlist = context.core.playlists.lookup(context.to_uri[playlist_name])
|
||||
playlist = context.core.playlists.lookup(context.to_uri[playlist_name]).get()
|
||||
else:
|
||||
playlist = context.core.playlists.create(playlist_name).get()
|
||||
tracks = list(playlist.tracks) + _get_tracks(results)
|
||||
|
||||
@ -81,7 +81,7 @@ def listplaylists(context):
|
||||
if not playlist.name:
|
||||
continue
|
||||
if playlist.uri not in context.from_uri:
|
||||
context.refresh_maps() # the maps are not synced, we refresh them
|
||||
context.refresh_playlists_mapping() # the maps are not synced, we refresh them
|
||||
result.append(('playlist', context.from_uri[playlist.uri]))
|
||||
last_modified = (
|
||||
playlist.last_modified or dt.datetime.utcnow()).isoformat()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user