X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fwebserv.py;h=c6a906fce7f5a92091f426a18f266856e6d04d42;hb=ee218f16c2a449c6d72d550807114676e1e96d94;hp=734a5f0b40a39b4e895ebc277f2a73691265aaab;hpb=8870413a27f675d121ed8c841e8673b597ab15c3;p=mpd-sima.git diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index 734a5f0..c6a906f 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -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: