]> kaliko git repositories - mpd-sima.git/blobdiff - sima/lib/plugin.py
Big cleanup, pyling warning, style, error
[mpd-sima.git] / sima / lib / plugin.py
index 1afafe5455297e5643fb0f977297bf5c3c0cf29c..2cc284ff1eb043e1a6a0e58b74bb940ffee14d88 100644 (file)
@@ -23,8 +23,7 @@ Plugin object to derive from
 
 import random
 
-from .track import Track
-from .meta import Album, Artist, MetaContainer
+from .meta import Artist, MetaContainer
 
 
 class Plugin:
@@ -171,7 +170,7 @@ class AdvancedPlugin(Plugin):
         albums = self.player.search_albums(artist)
         if not albums:
             return None
-        self.log.debug('Albums candidates: %s', albums)
+        self.log.debug('Albums to choose from: %s', albums)
         albums_hist = self.get_album_history(artist)
         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]
@@ -182,16 +181,17 @@ class AdvancedPlugin(Plugin):
                 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)
+        self.log.trace('Album candidates: %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}:
+            if album in {t.Album.name for t in self.player.queue}:
                 self.log.debug('"%s" already queued, skipping!', album)
                 continue
             # In random play mode use complete playlist to filter
+            # Yes indeed, some users play in random with album mode :|
             if self.player.playmode.get('random'):
-                if album in {t.album for t in self.player.playlist}:
+                if album in {t.Album.name for t in self.player.playlist}:
                     self.log.debug('"%s" already in playlist, skipping!',
                                    album)
                     continue
@@ -204,11 +204,17 @@ class AdvancedPlugin(Plugin):
                       self.__class__.__name__, artist, album_to_queue)
         return album_to_queue
 
-    def filter_track(self, tracks, unplayed=False):
+    def filter_track(self, tracks, chosen=None, unplayed=False):
         """
         Extract one unplayed track from a Track object list.
             * not in history
             * not already in the queue
+
+        :param list(Track) tracks: List of tracks to chose from
+        :param list(Track) chosen: List of tracks previously chosen
+        :param bool unplayed: chose only unplayed (honoring history duration setting)
+        :return: A Track
+        :rtype: Track
         """
         artist = tracks[0].Artist
         # In random play mode use complete playlist to filter
@@ -226,8 +232,10 @@ class AdvancedPlugin(Plugin):
         for trk in [_ for _ in not_in_hist if _ not in deny_list]:
             # Should use albumartist heuristic as well
             if self.plugin_conf.getboolean('single_album', False):  # pylint: disable=no-member
-                if (trk.album == self.player.current.album or
-                        trk.album in [tr.album for tr in deny_list]):
+                albums = [tr.Album for tr in deny_list]
+                albums += [tr.Album for tr in chosen]
+                if (trk.Album == self.player.current.Album or
+                        trk.Album in albums):
                     self.log.debug('Found unplayed track ' +
                                    'but from an album already queued: %s', trk)
                     continue