X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fwebserv.py;h=35835c31b08d1a4fbd25bb7a0beddb80f3adf1ce;hb=547aff383d4b0ab72174d451e4921f5c6e10a03d;hp=734a5f0b40a39b4e895ebc277f2a73691265aaab;hpb=8870413a27f675d121ed8c841e8673b597ab15c3;p=mpd-sima.git diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index 734a5f0..35835c3 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'): @@ -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: