2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2009,2010,2012,2019 kaliko <kaliko@azylum.org>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from os.path import basename
30 class Crop(musicpd.MPDClient):
32 'prog': basename(__file__),
33 'description': 'Keep <n> tracks before currently played, removed others. Default is to keep 6 tracks.',
34 'epilog': 'Set MPD host/port in env. var'
39 musicpd.MPDClient.__init__(self)
46 parser = argparse.ArgumentParser(**self.__class__.script_info)
47 parser.add_argument('--version', action='version',
48 version='v%s' % VERSION)
49 parser.add_argument('n', type=int, nargs='?',
50 help='how many titles to crop')
51 args = parser.parse_args()
53 self.nb_tracks = args.n
58 current_pos = int(self.currentsong().get('pos', 0))
59 if current_pos <= self.nb_tracks:
62 print('Keeping %i tracks' % self.nb_tracks)
63 while current_pos > self.nb_tracks:
65 current_pos = int(self.currentsong().get('pos', 0))
71 if __name__ == '__main__':
74 except KeyboardInterrupt:
75 sys.stdout.write('exit')
78 # vim: ai ts=4 sw=4 sts=4 expandtab