NAME = 'crop'
VERSION = '0.1'
-USAGE = """Usage:
-
-crop -S <server> -n <nb_tracks>
-"""
CROP_OPTS = list([
{
'sw': ['-n', '--nbtracks'],
'type': 'int',
'dest': 'nb_tracks',
- 'default': 3,
- 'help': 'Number of tracks to keep before the current one.'},
+ 'default': 60,
+ 'metavar': '<n>',
+ 'help': 'keep <n> tracks before currently played.'},
])
-class Crop(StartOpt):
+class Crop(StartOpt, MPDClass):
"""
"""
script_info = dict({
def __init__(self):
""""""
StartOpt.__init__(self, Crop.script_info, CROP_OPTS)
+ MPDClass.__init__(self)
self._run()
def _run(self):
""""""
- pass
-
- def crop(self):
- """"""
- NotImplemented
+ print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port)
+ self.mpdConnect({'host':self.cli_options.host, 'port':self.cli_options.port})
+ current_pos = int(self.client.currentsong().get('pos'))
+ if current_pos <= self.cli_options.nb_tracks:
+ self.client.disconnect()
+ sys.exit(0)
+ while current_pos > self.cli_options.nb_tracks:
+ self.client.delete(0)
+ current_pos = int(self.client.currentsong().get('pos'))
+ self.client.disconnect()
+ sys.exit(0)
# Script starts here