]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/webserv.py
Fixed some code style and comment
[mpd-sima.git] / sima / lib / webserv.py
index 734a5f0b40a39b4e895ebc277f2a73691265aaab..c6a906fce7f5a92091f426a18f266856e6d04d42 100644 (file)
@@ -34,7 +34,7 @@ from hashlib import md5
 from .plugin import Plugin
 from .track import Track
 from .meta import Artist, MetaContainer
-from ..utils.utils import WSError, WSNotFound
+from ..utils.utils import WSError, WSNotFound, WSTimeout
 
 def cache(func):
     """Caching decorator"""
@@ -74,6 +74,7 @@ class WebService(Plugin):
                    'album': self._album}
         self.queue_mode = wrapper.get(self.plugin_conf.get('queue_mode'))
         self.ws = None
+        self.ws_retry = 0
 
     def _flush_cache(self):
         """
@@ -189,6 +190,15 @@ class WebService(Plugin):
                     return self.ws_similar_artists(Artist(name=artist.name))
                 except WSNotFound as err:
                     self.log.debug('%s: %s', self.ws.name, err)
+        except WSTimeout as err:
+            self.log.warning('%s: %s', self.ws.name, err)
+            if self.ws_retry < 3:
+                self.ws_retry += 1
+                self.log.warning('%s: retrying', self.ws.name)
+                as_art = self.ws_similar_artists(artist)
+            else:
+                self.log.warning('%s: stop retrying', self.ws.name)
+            self.ws_retry = 0
         except WSError as err:
             self.log.warning('%s: %s', self.ws.name, err)
         if as_art:
@@ -199,7 +209,7 @@ class WebService(Plugin):
         """Check against local player for similar artists (recursive w/ history)
         """
         if not self.player.playlist:
-            return
+            return []
         history = list(self.history)
         # In random play mode use complete playlist to filter
         if self.player.playmode.get('random'):
@@ -243,7 +253,7 @@ class WebService(Plugin):
             return []
         tolookfor = self.player.playlist[-1].Artist
         self.log.info('Looking for artist similar to "%s"', tolookfor)
-        self.log.debug(repr(tolookfor))
+        self.log.debug('%r', tolookfor)
         similar = self.ws_similar_artists(tolookfor)
         if not similar:
             self.log.info('Got nothing from %s!', self.ws.name)
@@ -303,7 +313,9 @@ class WebService(Plugin):
         """Retrieve album history"""
         albums_list = set()
         for trk in self.get_history(artist=artist.name):
-            albums_list.add(trk[1])
+            if not trk.album:
+                continue
+            albums_list.add(trk.album)
         return albums_list
 
     def find_album(self, artists):
@@ -370,6 +382,7 @@ class WebService(Plugin):
                 titles = [t for t in self.ws.get_toptrack(artist)]
             except WSError as err:
                 self.log.warning('%s: %s', self.ws.name, err)
+                continue
             for trk in titles:
                 found = self.player.search_track(artist, trk.title)
                 if found: