]> kaliko git repositories - mpd-sima.git/commitdiff
Add configuration for crop plugin
authorkaliko <efrim@azylum.org>
Sun, 1 Dec 2013 18:11:53 +0000 (19:11 +0100)
committerkaliko <efrim@azylum.org>
Sun, 1 Dec 2013 18:11:53 +0000 (19:11 +0100)
doc/examples/all_settings.cfg
sima/plugins/internal/crop.py

index bb5273b51c7f5f6785bcac8b485106091840c00c..ab6609fcc34837e709b60d2e3614c47c5df4eb2a 100644 (file)
@@ -68,6 +68,13 @@ verbosity = info
 [placeholder]
 key = Value
 
+#[crop]
+# type: integer
+# description: How many played tracks to keep in the playlist.
+#  Allow to maintain a fixed length playlist.
+#  Leave commented to keep all tracks
+#consume = 10
+
 [RandomFallback]
 # random falvour :
 #  * pure:     complete ramdom choice among all tracks available in the player media library
@@ -151,15 +158,6 @@ contrib = PlaceHolder
 history_duration = 8
 ##
 
-## CONSUME
-# type: integer
-# description: How many played tracks to keep in the playlist.
-#  Allow to maintain a fixed length playlist.
-#  set to 0 to keep all played tracks.
-#
-consume = 0
-##
-
 ## USER_DB # NOT IMPLEMENTED #
 # type: boolean
 # description: Load user database to find similar artists
index 8ea889e7810d08c7b88664c8b3bf86b87f087467..d4df0c3211abc7acc1b728265f074adba7c2a99d 100644 (file)
@@ -15,11 +15,25 @@ class Crop(Plugin):
     Crop playlist on next track
     kinda MPD's consume
     """
+    def __init__(self, daemon):
+        super().__init__(daemon)
+        self.target = None
+        if not self.plugin_conf:
+            return
+        target = self.plugin_conf.get('consume', None)
+        if not target:
+            return
+        if not target.isdigit():
+            self.log.warning('Bad value for consume, '
+                    'expecting an integer, not "{}"'.format(target))
+        else:
+            self.target = int(target)
 
     def callback_playlist(self):
+        if not self.target:
+            return
         player = self._Plugin__daemon.player
-        target_lengh = 10
-        while player.currentsong().pos > target_lengh:
+        while player.currentsong().pos > self.target:
             self.log.debug('cropping playlist')
             player.remove()