]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/webserv.py
Set max_art default value to 20
[mpd-sima.git] / sima / lib / webserv.py
index ca6b1f095b9b2d6499c9a384ca73218a0f348338..8201964bdf1da71dbb9fa33e16fa590c497bb0bc 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Copyright (c) 2009-2020 kaliko <kaliko@azylum.org>
+# Copyright (c) 2009-2021 kaliko <kaliko@azylum.org>
 # Copyright (c) 2019 sacha <sachahony@gmail.com>
 #
 #  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: