]> kaliko git repositories - mpd-sima.git/commitdiff
Fixed issues in reorg and album_candidate
authorkaliko <kaliko@azylum.org>
Sun, 20 Dec 2020 17:52:12 +0000 (18:52 +0100)
committerkaliko <kaliko@azylum.org>
Sun, 20 Dec 2020 17:52:12 +0000 (18:52 +0100)
sima/lib/plugin.py
sima/plugins/internal/tags.py

index 83c28b5fda38ad642df9ea4251de48a664e30f2e..c38683af971e6aad172fe87cbfbe20750be7499b 100644 (file)
@@ -46,7 +46,7 @@ class Plugin:
         if cls.__doc__:
             doc = cls.__doc__.strip(' \n').splitlines()[0]
         return {'name': cls.__name__,
-                'doc': doc,}
+                'doc': doc}
 
     def __init__(self, daemon):
         self.log = daemon.log
@@ -160,17 +160,24 @@ class AdvancedPlugin(Plugin):
 
     def get_reorg_artists_list(self, alist):
         """
-        Move around items in artists_list in order to play first not recently
-        played artists
+        Move around items in alist in order to have first not recently
+        played (or about to be played) artists.
 
-        :param list(str) alist:
+        :param list(str) alist: artist name list (Not an Artist object)
         """
-        hist = list()
+        queued_artist = {_.artist for _ in self.player.queue}
+        not_queued_artist = set(alist) - queued_artist
         duration = self.main_conf.getint('sima', 'history_duration')
-        for art in self.sdb.get_artists_history(alist, duration=duration):
+        hist = []
+        for art in self.sdb.get_artists_history(alist,
+                                                duration=duration):
             if art not in hist:
-                hist.insert(0, art)
-        reorg = [art for art in alist if art not in hist]
+                if art not in queued_artist:
+                    hist.insert(0, art)
+                else:
+                    hist.append(art)
+        # Find not recently played (not in history)
+        reorg = [art for art in not_queued_artist if art not in hist]
         reorg.extend(hist)
         return reorg
     # /Query History
@@ -185,34 +192,35 @@ class AdvancedPlugin(Plugin):
         self.log.info('Searching an album for "%s"...' % artist)
         albums = self.player.search_albums(artist)
         if not albums:
-            return []
-        self.log.debug('Albums candidate: %s', albums)
+            return None
+        self.log.debug('Albums candidates: %s', albums)
         albums_hist = self.get_album_history(artist)
-        self.log.debug('Albums history: %s', [a.name for a in albums_hist])
+        self.log.trace('Albums history: %s', [a.name for a in albums_hist])
         albums_not_in_hist = [a for a in albums if a.name not in albums_hist]
         # Get to next artist if there are no unplayed albums
         if not albums_not_in_hist:
             self.log.info('No unplayed album found for "%s"' % artist)
             if unplayed:
-                return []
+                return None
         random.shuffle(albums_not_in_hist)
         albums_not_in_hist.extend(albums_hist)
+        self.log.debug('Albums candidate: %s', albums_not_in_hist)
         album_to_queue = []
         for album in albums_not_in_hist:
             # Controls the album found is not already queued
             if album in {t.album for t in self.player.queue}:
                 self.log.debug('"%s" already queued, skipping!', album)
-                return []
+                continue
             # In random play mode use complete playlist to filter
             if self.player.playmode.get('random'):
                 if album in {t.album for t in self.player.playlist}:
                     self.log.debug('"%s" already in playlist, skipping!',
                                    album)
-                    return []
+                    continue
             album_to_queue = album
         if not album_to_queue:
             self.log.info('No album found for "%s"', artist)
-            return []
+            return None
         self.log.info('%s album candidate: %s - %s', self.__class__.__name__,
                       artist, album_to_queue)
         return album_to_queue
index 949b3878a1c6ce47c6dd0c02f4d17cf0ee95f5fd..ad326ef3a1f3f587c3ba6c89332a847aaa072426 100644 (file)
@@ -118,16 +118,15 @@ class Tags(AdvancedPlugin):
         artists = self.player.list('artist', self.mpd_filter)
         random.shuffle(artists)
         artists = self.get_reorg_artists_list(artists)
-        self.log.debug('Tags candidates: %s', ' / '.join(artists))
+        self.log.debug('Tags artists found: %s', ' / '.join(artists))
         for artist in artists:
-            if artist in {t.Artist for t in self.player.queue}:
-                continue
             self.log.debug('looking for %s', artist)
-            trk = self.filter_track(self.player.find_tracks(Artist(name=artist)))
+            tracks = self.player.find_tracks(Artist(name=artist))
+            trk = self.filter_track(tracks)
             if not trk:
                 continue
             if queue_mode == 'track':
-                self.log.info('Tags candidate: {}'.format(trk))
+                self.log.info('Tags plugin chose: {}'.format(trk))
                 candidates.append(trk)
                 if len(candidates) == target:
                     break