]> kaliko git repositories - mpd-sima.git/blob - sima/plugins/internal/crop.py
2ecbfc10a61edc94eaeb40ae902afa321dd0bb1c
[mpd-sima.git] / sima / plugins / internal / crop.py
1 # -*- coding: utf-8 -*-
2 """Crops playlist
3 """
4
5 # standard library import
6 #from select import select
7
8 # third parties components
9
10 # local import
11 from ...lib.plugin import Plugin
12
13 class Crop(Plugin):
14     """
15     Crop playlist on next track
16     kinda MPD's consume
17     """
18     def __init__(self, daemon):
19         super().__init__(daemon)
20         self.target = None
21         if not self.plugin_conf:
22             return
23         target = self.plugin_conf.get('consume', None)
24         if not target:
25             return
26         if not target.isdigit():
27             self.log.warning('Bad value for consume, '
28                     'expecting an integer, not "{}"'.format(target))
29         else:
30             self.target = int(target)
31
32     def callback_next_song(self):
33         if not self.target:
34             return
35         player = self._Plugin__daemon.player
36         if player.currentsong().pos > self.target:
37             self.log.debug('cropping playlist')
38         while player.currentsong().pos > self.target:
39             player.remove()
40
41
42 # VIM MODLINE
43 # vim: ai ts=4 sw=4 sts=4 expandtab