]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/webserv.py
Fixed search_albums
[mpd-sima.git] / sima / lib / webserv.py
index ffd516aae82388e237015daf23114df0279ce662..a1f6d99d36f92cdc069839190249f57fa1021f94 100644 (file)
@@ -33,7 +33,7 @@ from hashlib import md5
 from .plugin import Plugin
 from .track import Track
 from .meta import Artist
-from ..utils.utils import WSError
+from ..utils.utils import WSError, WSNotFound
 
 def cache(func):
     """Caching decorator"""
@@ -179,6 +179,10 @@ class WebService(Plugin):
         self.log.debug('Requesting {} for {!r}'.format(self.ws.name, artist))
         try:
             [as_art.append(art) for art in as_artists]
+        except WSNotFound as err:
+            if artist.mbid:
+                return self.ws_similar_artists(Artist(name=artist.name))
+            self.log.warning('{}: {}'.format(self.ws.name, err))
         except WSError as err:
             self.log.warning('{}: {}'.format(self.ws.name, err))
         if as_art:
@@ -222,6 +226,7 @@ class WebService(Plugin):
             return []
         tolookfor = self.player.playlist[-1].Artist
         self.log.info('Looking for artist similar to "{}"'.format(tolookfor))
+        self.log.debug(repr(tolookfor))
         similar = self.ws_similar_artists(tolookfor)
         if not similar:
             self.log.info('Got nothing from {0}!'.format(self.ws.name))
@@ -240,15 +245,15 @@ class WebService(Plugin):
             self.log.warning('Got nothing from music library.')
             self.log.warning('Try running in debug mode to guess why...')
             return []
-        queued_artists = { trk.Artist for trk in self.player.queue }
-        for art in queued_artists:
-            if art in ret:
-                self.log.debug('Removing already queued artist: {0}'.format(art))
-        ret = ret - queued_artists
+        # WARNING:
+        #   * operation on set will not match against aliases
+        #   * composite set w/ mbid set and whitout won't match either
+        queued_artists = {trk.Artist for trk in self.player.queue}
         if ret & queued_artists:
-            self.log.debug('Removing already queued artist: {0}'.format(ret & queued_artists))
+            self.log.debug('Removing already queued artists: '
+                           '{0}'.format(ret & queued_artists))
             ret = ret - queued_artists
-        if self.player.current.Artist in ret:
+        if self.player.current and self.player.current.Artist in ret:
             self.log.debug('Removing current artist: {0}'.format(self.player.current.Artist))
             ret = ret - {self.player.current.Artist}
         # Move around similars items to get in unplayed|not recently played
@@ -325,10 +330,8 @@ class WebService(Plugin):
                 titles = [t for t in self.ws.get_toptrack(artist)]
             except WSError as err:
                 self.log.warning('{0}: {1}'.format(self.ws.name, err))
-            if self.ws.ratelimit:
-                self.log.info('{0.name} ratelimit: {0.ratelimit}'.format(self.ws))
             for trk in titles:
-                found = self.player.fuzzy_find_track(artist.name, trk.title)
+                found = self.player.fuzzy_find_track(artist, trk.title)
                 random.shuffle(found)
                 if found:
                     self.log.debug('{0}'.format(found[0]))
@@ -384,7 +387,7 @@ class WebService(Plugin):
         self.queue_mode()
         msg = ' '.join(['{0}: {1:>3d}'.format(k, v) for
                         k, v in sorted(self.ws.stats.items())])
-        self.log.debug(msg)
+        self.log.debug('http stats: ' + msg)
         candidates = self.to_add
         self.to_add = list()
         if self.plugin_conf.get('queue_mode') != 'album':