From: kaliko Date: Sun, 1 Dec 2013 18:11:53 +0000 (+0100) Subject: Add configuration for crop plugin X-Git-Tag: mpd-sima/0.12.0pr2~22 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=6893eb469c11924c9480b15385cedaf37908dd02;p=mpd-sima.git Add configuration for crop plugin --- diff --git a/doc/examples/all_settings.cfg b/doc/examples/all_settings.cfg index bb5273b..ab6609f 100644 --- a/doc/examples/all_settings.cfg +++ b/doc/examples/all_settings.cfg @@ -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 diff --git a/sima/plugins/internal/crop.py b/sima/plugins/internal/crop.py index 8ea889e..d4df0c3 100644 --- a/sima/plugins/internal/crop.py +++ b/sima/plugins/internal/crop.py @@ -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()