From 547aff383d4b0ab72174d451e4921f5c6e10a03d Mon Sep 17 00:00:00 2001 From: kaliko Date: Mon, 8 Jun 2020 17:11:56 +0200 Subject: [PATCH] =?utf8?q?Working=20around=20last.fm=20timeout=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sima/lib/webserv.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index 1f75c20..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'): -- 2.39.2