]> kaliko git repositories - mpd-sima.git/commitdiff
Update simadb API
authorkaliko <kaliko@azylum.org>
Sat, 1 May 2021 17:13:53 +0000 (19:13 +0200)
committerkaliko <kaliko@azylum.org>
Wed, 5 May 2021 15:31:17 +0000 (17:31 +0200)
sima/lib/plugin.py
sima/mpdclient.py
sima/plugins/core/history.py

index 49cd7f155d9c0ee057e0353aef4e27cf4e28f10f..1afafe5455297e5643fb0f977297bf5c3c0cf29c 100644 (file)
@@ -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:
index 7eeed94d86fa29e13b717081eba9ca2c2c46da86..96767b0e95562916f63ac67da74a8b6c11e07d41 100644 (file)
@@ -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)
index 6c3ad907ce6a5c19ed453f6a42dea50104656426..3380870754b84a12c775dd0075b40173e1f0c0c6 100644 (file)
@@ -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)