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 random import choice
25 from lib.goodies import Goodie
30 USAGE = 'USAGE: %prog --help | AlbumA AlbumB "The Album C" | -f file'
34 'sw': ['-f', '--file'],
37 'metavar': 'filename',
38 'help': 'filemame to read album list from. An album name on each line'},
48 'description': 'Queue and play an album chosen at random from a list. Albums list provided from CLI or text file.',
54 Goodie.__init__(self, self.__class__.script_info,
55 extra_options=WAKEUP_OPTS)
61 if self.cli_options.file:
62 # TODO: handle encoding reading file!
63 print 'reading from file, assuming %s encoding' % self.localencoding
65 with open(self.cli_options.file) as f:
66 self.albums_list = [line.rstrip('\n') for line in f.readlines()]
69 print 'ERROR: "%s": %s' % (self.cli_options.file, err[1])
72 print 'WARNING: ignoring "%s"' % self.cli_args
75 self.albums_list = self.cli_args
77 self.parser.print_usage()
78 print "ERROR: Need at least an argument!"
83 print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port)
85 album = choice(self.albums_list)
86 print 'Queueing "%s"' % album
87 tracks = self.client.find('album', self._u8_convert(album))
89 print 'No tracks found for "%s"' % album
90 self.client.disconnect()
93 self.client.add(track.get('file'))
94 self.client.disconnect()
99 if __name__ == '__main__':
102 except KeyboardInterrupt:
103 sys.stdout.write('exit')
106 # vim: ai ts=4 sw=4 sts=4 expandtab