X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Fwebserv.py;h=18414e7d2fd06d8edf7876e065b9c3c6bdf20b41;hb=a260ebea93f23d72aa6e0178744b0f64c469b7ba;hp=a0b899a3f624f82fdbc2f1b45f9e956574b82d9b;hpb=61d5b735d5967d10447eb1c7a2f9fe683d9736bd;p=mpd-sima.git diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index a0b899a..18414e7 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,7 +101,7 @@ 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): art_pop = similarities.pop() @@ -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: @@ -271,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 @@ -296,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 @@ -351,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: