]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/webserv.py
Improved client's find_track method with mbids
[mpd-sima.git] / sima / lib / webserv.py
index 3a484c2fde86cfbe5915124a56f4185cd028abcc..dcc8707cb7a3f8dc43d3980e6149471bd6aca7a6 100644 (file)
@@ -168,7 +168,7 @@ class WebService(Plugin):
                 results.append(res)
         return results
 
-    def ws_similar_artists(self, artist=None):
+    def ws_similar_artists(self, artist):
         """
         Retrieve similar artists from WebServive.
         """
@@ -179,9 +179,13 @@ class WebService(Plugin):
         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))
+            if artist.mbid:
+                self.log.debug('Trying without MusicBrainzID')
+                try:
+                    return self.ws_similar_artists(Artist(name=artist.name))
+                except WSNotFound as err:
+                    self.log.debug('{}: {}'.format(self.ws.name, err))
         except WSError as err:
             self.log.warning('{}: {}'.format(self.ws.name, err))
         if as_art:
@@ -264,10 +268,9 @@ class WebService(Plugin):
         if not ret:
             self.log.warning('Got nothing from music library.')
             return []
-        # WARNING:
-        #   * operation on set will not match against aliases
-        #   * composite set w/ mbid set and whitout won't match either
         queued_artists = MetaContainer([trk.Artist for trk in self.player.queue])
+        self.log.trace('Already queued: {}'.format(queued_artists))
+        self.log.trace('Candidate: {}'.format(ret))
         if ret & queued_artists:
             self.log.debug('Removing already queued artists: '
                            '{0}'.format('/'.join(map(str, ret & queued_artists))))
@@ -365,7 +368,7 @@ class WebService(Plugin):
         artists = self.get_local_similar_artists()
         nbtracks_target = self.plugin_conf.getint('track_to_add')
         for artist in artists:
-            self.log.debug('Trying to find titles to add for "{}"'.format(
+            self.log.debug('Trying to find titles to add for "{!r}"'.format(
                            artist))
             found = self.player.find_track(artist)
             random.shuffle(found)