From c23e4560ba184403e94d41cbf0816ed9847406fc Mon Sep 17 00:00:00 2001 From: kaliko Date: Sat, 1 May 2021 19:13:53 +0200 Subject: [PATCH] Update simadb API --- sima/lib/plugin.py | 28 +++++++--------------------- sima/mpdclient.py | 4 ++-- sima/plugins/core/history.py | 16 +++++++++++----- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/sima/lib/plugin.py b/sima/lib/plugin.py index 49cd7f1..1afafe5 100644 --- a/sima/lib/plugin.py +++ b/sima/lib/plugin.py @@ -126,29 +126,15 @@ class AdvancedPlugin(Plugin): """ # Query History - def get_history(self, artist=False): - """Constructs Track list of already played artists. - - :param Artist artist: Artist object to look history for - """ + def get_history(self): + """Returns a Track list of already played artists.""" duration = self.main_conf.getint('sima', 'history_duration') - name = None - if artist: - name = artist.name - from_db = self.sdb.get_history(duration=duration, artist=name) - hist = [Track(artist=tr[0], album=tr[1], title=tr[2], - file=tr[3]) for tr in from_db] - return hist + return self.sdb.fetch_history(duration=duration) def get_album_history(self, artist): """Retrieve album history""" - hist = [] - tracks_from_db = self.get_history(artist=artist) - for trk in tracks_from_db: - if trk.album and trk.album in hist: - continue - hist.append(Album(name=trk.album, artist=Artist(trk.artist))) - return hist + duration = self.main_conf.getint('sima', 'history_duration') + return self.sdb.fetch_albums_history(needle=artist, duration=duration) def get_reorg_artists_list(self, alist): """ @@ -162,7 +148,7 @@ class AdvancedPlugin(Plugin): not_queued_artist = alist - queued_artist duration = self.main_conf.getint('sima', 'history_duration') hist = [] - for art in self.sdb.get_artists_history(alist, duration=duration): + for art in self.sdb.fetch_artists_history(alist, duration=duration): if art not in hist: if art not in queued_artist: hist.insert(0, art) @@ -230,7 +216,7 @@ class AdvancedPlugin(Plugin): deny_list = self.player.playlist else: deny_list = self.player.queue - not_in_hist = list(set(tracks) - set(self.get_history(artist=artist))) + not_in_hist = list(set(tracks) - set(self.sdb.fetch_history(artist=artist))) if not not_in_hist: self.log.debug('All tracks already played for "%s"', artist) if unplayed: diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 7eeed94..96767b0 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -92,10 +92,10 @@ def blacklist(artist=False, album=False, track=False): #cls.log.debug('using {0} as bl filter'.format(bl_getter.__name__)) results = list() for elem in func(*args, **kwargs): - if bl_getter(elem, add_not=True): + if bl_getter(elem, add=False): #cls.log.debug('Blacklisted "{0}"'.format(elem)) continue - if track and cls.database.get_bl_album(elem, add_not=True): + 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) diff --git a/sima/plugins/core/history.py b/sima/plugins/core/history.py index 6c3ad90..3380870 100644 --- a/sima/plugins/core/history.py +++ b/sima/plugins/core/history.py @@ -39,15 +39,21 @@ class History(Plugin): def shutdown(self): self.log.info('Cleaning database') self.sdb.purge_history() - self.sdb.clean_database() + + def _h_tip(self): + hist = self.sdb.fetch_history() + if hist: + return hist[0] + return None def callback_player(self): current = self.player.current - last_hist = next(self.sdb.get_history(), None) - if last_hist and last_hist[3] == current.file: - return if not current: - self.log.debug('Cannot add "%s" to history (empty or missing file)', current) + if self.player.state == 'play': + self.log.debug('Cannot add "%s" to history (empty or missing file)', current) + return + last_hist = self._h_tip() + if last_hist and last_hist == current: return self.log.debug('add history: "%s"', current) self.sdb.add_history(current) -- 2.39.2