]> kaliko git repositories - mpd-sima.git/commitdiff
Update simadb API
authorkaliko <kaliko@azylum.org>
Tue, 4 May 2021 13:37:44 +0000 (15:37 +0200)
committerkaliko <kaliko@azylum.org>
Fri, 7 May 2021 16:24:20 +0000 (18:24 +0200)
sima/mpdclient.py
sima/plugins/internal/random.py

index 96767b0e95562916f63ac67da74a8b6c11e07d41..bccdb97c7f83790e7541c0765cfe567b72ad724f 100644 (file)
@@ -48,8 +48,9 @@ def bl_artist(func):
             return None
         names = list()
         for art in result.names:
-            if cls.database.get_bl_artist(art, add_not=True):
-                cls.log.debug('Blacklisted "%s"', art)
+            artist = Artist(name=art, mbid=result.mbid)
+            if cls.database.get_bl_artist(artist, add=False):
+                cls.log.debug('Artist "%s" in blocklist!', artist)
                 continue
             names.append(art)
         if not names:
@@ -75,7 +76,7 @@ def tracks_wrapper(func):
 # / decorators
 
 
-def blacklist(artist=False, album=False, track=False):
+def blocklist(album=False, track=False):
     # pylint: disable=C0111,W0212
     field = (album, track)
 
@@ -98,7 +99,7 @@ def blacklist(artist=False, album=False, track=False):
                 if track and cls.database.get_bl_album(elem, add=False):
                     # filter album as well in track mode
                     # (artist have already been)
-                    cls.log.debug('Blacklisted alb. "%s"', elem)
+                    cls.log.debug('Album "%s" in blocklist', elem)
                     continue
                 results.append(elem)
             return results
@@ -437,7 +438,7 @@ class MPD(MPDClient):
             return artist
         return None
 
-    @blacklist(track=True)
+    @blocklist(track=True)
     def search_track(self, artist, title):
         """Fuzzy search of title by an artist
         """
@@ -467,7 +468,7 @@ class MPD(MPDClient):
                                mtitle, title, leven)
         return tracks
 
-    @blacklist(album=True)
+    @blocklist(album=True)
     def search_albums(self, artist):
         """Find potential albums for "artist"
 
index 99e0599ff63f178a5fc37faf0b421771acd82dc8..5af0ba1a42e509a90dc460da5b4eb12568d002bd 100644 (file)
@@ -46,11 +46,9 @@ 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}
+        artists = self.sdb.fetch_artists_history(duration=duration)
         return artists
 
     def filtered_artist(self, artist):
@@ -59,10 +57,10 @@ 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):
+            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():
@@ -79,7 +77,7 @@ class Random(Plugin):
         target = self.plugin_conf.getint('track_to_add')
         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)