]> kaliko git repositories - mpd-sima.git/blobdiff - sima/plugins/internal/random.py
Update simadb API
[mpd-sima.git] / sima / plugins / internal / random.py
index 815824358b8975369ee97ee2bc8cec7bd0a6c1de..5af0ba1a42e509a90dc460da5b4eb12568d002bd 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Copyright (c) 2013-2015, 2020 kaliko <kaliko@azylum.org>
+# Copyright (c) 2013-2015, 2020-2021 kaliko <kaliko@azylum.org>
 #
 #  This file is part of sima
 #
@@ -46,12 +46,10 @@ class Random(Plugin):
         self.candidates = []
 
     def get_played_artist(self,):
-        """Constructs list of already played artists.
-        """
+        """Constructs list of already played artists."""
         duration = self.main_conf.getint('sima', 'history_duration')
-        tracks_from_db = self.sdb.get_history(duration=duration)
-        artists = [tr[0] for tr in tracks_from_db]
-        return set(artists)
+        artists = self.sdb.fetch_artists_history(duration=duration)
+        return artists
 
     def filtered_artist(self, artist):
         """Filters artists:
@@ -59,11 +57,11 @@ class Random(Plugin):
 
         If sensible random is set:
          * not in recent history
-         * not blacklisted
+         * not in blocklist
         """
         if self.mode == 'sensible':
-            if self.sdb.get_bl_artist(artist, add_not=True):
-                self.log.debug('Random: Blacklisted "%s"', artist)
+            if self.sdb.get_bl_artist(Artist(artist), add=False):
+                self.log.debug('Random plugin: Blacklisted "%s"', artist)
                 return True
             if artist in self.get_played_artist():
                 return True
@@ -77,9 +75,9 @@ class Random(Plugin):
         self.candidates = []
         trks = []
         target = self.plugin_conf.getint('track_to_add')
-        artists = self.player.list('artist')
+        artists = self.player.list('artist', '( artist != "")')
         random.shuffle(artists)
-        for art in artists:
+        for art in artists:  # artists is a list of strings here
             if self.filtered_artist(art):
                 continue
             self.log.debug('Random art: %s', art)