2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2009, 2010, 2012 Kaliko Jack <kaliko.jack@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 import(access, W_OK)
24 from os.path import (dirname, isfile, basename)
26 from lib.goodies import Goodie
31 USAGE = 'USAGE: %prog [--help] | /path/to/the/playlist/file/'
40 'description': 'Save currently played track into your playlists',
46 Goodie.__init__(self, self.__class__.script_info)
52 if len(self.cli_args) != 1:
53 self.parser.error('need at least a playlist file name!')
54 self.playlist = self.cli_args[0]
55 if (isfile(self.playlist) and
56 access(self.playlist, W_OK)):
58 if not access(dirname(self.playlist), W_OK):
59 self.parser.error('not writable: %s' % dirname(self.playlist))
61 def _check_dupes(self):
62 """Controls the file is not already in the playlist"""
63 fd = open(self.playlist)
64 lines = fd.readlines()
66 if self.current_song.get('file') + '\n' in lines:
67 print 'File already in the playlist.'
72 if not isfile(self.playlist):
73 # TODO: add M3U header
74 print >> sys.stdout, ('Create new playlist: %s' % self.playlist)
75 open(self.playlist, 'a').close()
78 fd = open(self.playlist, 'a')
79 fd.write(self.current_song.get('file') + '\n')
84 print 'Connecting %s:%i' % (self.cli_options.host,
85 self.cli_options.port)
87 self.current_song = self.client.currentsong()
88 self.client.disconnect()
90 print 'Will try to add "%s" to "%s"' % (
91 basename(self.current_song.get('file')),
99 if __name__ == '__main__':
102 except KeyboardInterrupt:
103 sys.stdout.write('exit')
106 # vim: ai ts=4 sw=4 sts=4 expandtab