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.core = core
|
||||||
self.events = set()
|
self.events = set()
|
||||||
self.subscriptions = set()
|
self.subscriptions = set()
|
||||||
self.to_uri = dict()
|
self.to_uri = {}
|
||||||
self.from_uri = dict()
|
self.from_uri = {}
|
||||||
self.refresh_maps()
|
self.refresh_playlists_mapping()
|
||||||
|
|
||||||
def refresh_maps(self):
|
def refresh_playlists_mapping(self):
|
||||||
self.to_uri.clear()
|
if self.core is not None:
|
||||||
self.from_uri.clear()
|
self.to_uri.clear()
|
||||||
for playlist in self.core.playlists.playlists.get():
|
self.from_uri.clear()
|
||||||
if not playlist.name:
|
for playlist in self.core.playlists.playlists.get():
|
||||||
continue
|
if not playlist.name:
|
||||||
name = playlist.name
|
continue
|
||||||
i = 1
|
name = playlist.name
|
||||||
while name in self.to_uri:
|
i = 1
|
||||||
name = '%s [%d]' % playlist.name % i
|
while name in self.to_uri:
|
||||||
i += 1
|
name = '%s [%d]' % playlist.name % i
|
||||||
self.to_uri[name] = playlist.uri
|
i += 1
|
||||||
self.from_uri[playlist.uri] = name
|
self.to_uri[name] = playlist.uri
|
||||||
|
self.from_uri[playlist.uri] = name
|
||||||
|
|||||||
@ -381,8 +381,11 @@ def searchaddpl(context, playlist_name, mpd_query):
|
|||||||
return
|
return
|
||||||
results = context.core.library.search(**query).get()
|
results = context.core.library.search(**query).get()
|
||||||
|
|
||||||
|
if len(context.to_uri) == 0:
|
||||||
|
context.refresh_playlists_mapping()
|
||||||
|
|
||||||
if playlist_name in context.to_uri:
|
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:
|
else:
|
||||||
playlist = context.core.playlists.create(playlist_name).get()
|
playlist = context.core.playlists.create(playlist_name).get()
|
||||||
tracks = list(playlist.tracks) + _get_tracks(results)
|
tracks = list(playlist.tracks) + _get_tracks(results)
|
||||||
|
|||||||
@ -81,7 +81,7 @@ def listplaylists(context):
|
|||||||
if not playlist.name:
|
if not playlist.name:
|
||||||
continue
|
continue
|
||||||
if playlist.uri not in context.from_uri:
|
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]))
|
result.append(('playlist', context.from_uri[playlist.uri]))
|
||||||
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