From: kaliko Date: Tue, 4 May 2021 13:37:44 +0000 (+0200) Subject: Update simadb API X-Git-Tag: 0.18.0~63 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=45cf8271f3d364c33dd3c6fa2bcceca494176c0d;p=mpd-sima.git Update simadb API --- diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 96767b0..bccdb97 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -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" diff --git a/sima/plugins/internal/random.py b/sima/plugins/internal/random.py index 99e0599..5af0ba1 100644 --- a/sima/plugins/internal/random.py +++ b/sima/plugins/internal/random.py @@ -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)