X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fwebserv.py;h=8201964bdf1da71dbb9fa33e16fa590c497bb0bc;hb=2f23824849643b60e24ca0f838efaad41d5e0727;hp=ca6b1f095b9b2d6499c9a384ca73218a0f348338;hpb=af5f8a1cbde1e61ec1b44da676fae89c4358d184;p=mpd-sima.git diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index ca6b1f0..8201964 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2020 kaliko +# Copyright (c) 2009-2021 kaliko # Copyright (c) 2019 sacha # # This file is part of sima @@ -81,8 +81,8 @@ class WebService(AdvancedPlugin): self.log.info('%s: Flushing cache!', name) else: self.log.info('%s: Initialising cache!', name) - self._cache = {'asearch': dict(), - 'tsearch': dict()} + self._cache = {'asearch': {}, + 'tsearch': {}} def _cleanup_cache(self): """Avoid bloated cache @@ -101,9 +101,9 @@ class WebService(AdvancedPlugin): dynamic = self.plugin_conf.getint('max_art') if dynamic <= 0: dynamic = 100 - results = list() + results = [] similarities.reverse() - while (len(results) < dynamic and similarities): + while (len(results) < dynamic+1 and similarities): art_pop = similarities.pop() res = self.player.search_artist(art_pop) if res: @@ -156,8 +156,8 @@ class WebService(AdvancedPlugin): history = self.player.queue + history history = deque(history) last_trk = history.popleft() # remove - extra_arts = list() - ret_extra = list() + extra_arts = [] + ret_extra = [] depth = 0 while depth < self.plugin_conf.getint('depth'): if not history: @@ -250,7 +250,7 @@ class WebService(AdvancedPlugin): def find_album(self, artists): """Find albums to queue. """ - to_add = list() + to_add = [] nb_album_add = 0 target_album_to_add = self.plugin_conf.getint('album_to_add') for artist in artists: @@ -259,6 +259,8 @@ class WebService(AdvancedPlugin): continue nb_album_add += 1 candidates = self.player.find_tracks(album) + if not candidates: + continue if self.plugin_conf.getboolean('shuffle_album'): random.shuffle(candidates) # this allows to select a maximum number of track from the album @@ -269,20 +271,21 @@ class WebService(AdvancedPlugin): to_add.extend(candidates) if nb_album_add == target_album_to_add: return to_add + return to_add def find_top(self, artists): """ find top tracks for artists in artists list. """ - to_add = list() + to_add = [] nbtracks_target = self.plugin_conf.getint('track_to_add') for artist in artists: if len(to_add) == nbtracks_target: - return to_add + break self.log.info('Looking for a top track for %s', artist) titles = deque() try: - titles = [t for t in self.ws.get_toptrack(artist)] + titles = list(self.ws.get_toptrack(artist)) except WSError as err: self.log.warning('%s: %s', self.ws.name, err) continue @@ -294,6 +297,7 @@ class WebService(AdvancedPlugin): if top_trk: to_add.append(top_trk) break + return to_add def _track(self): """Get some tracks for track queue mode @@ -349,7 +353,7 @@ class WebService(AdvancedPlugin): self.log.debug(repr(self.player.current)) return None candidates = self.queue_mode() - msg = ' '.join(['{0}: {1:>3d}'.format(k, v) for + msg = ' '.join([f'{k}: {v:>3d}' for k, v in sorted(self.ws.stats.items())]) self.log.debug('http stats: ' + msg) if not candidates: