mpd: fix style issues and type errors introduced in 87ce309

Tests are now OK
This commit is contained in:
Thomas Refis 2013-04-07 14:17:28 +02:00
parent 87ce309749
commit 698f505da6
3 changed files with 22 additions and 18 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()