2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2009, 2010 Efrim <efrim@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/>.
24 from random import choice
26 from lib.mpdclass import MPDClass
27 from lib.startop import StartOpt
31 USAGE = 'USAGE: %prog --help | AlbumA AlbumB "The Album C" | -f file'
35 'sw': ['-f', '--file'],
38 'metavar': 'filename',
39 'help': 'filemame to read album list from. An album name on each line'},
43 class WakeUp(StartOpt, MPDClass):
49 'description': 'Queue and play an album chosen at random from a list. Albums list provided from CLI or text file.',
55 StartOpt.__init__(self, self.__class__.script_info, WAKEUP_OPTS)
56 MPDClass.__init__(self)
62 if self.cli_options.file:
63 # TODO: handle encoding reading file!
64 print 'reading from file, assuming %s encoding' % self.localencoding
66 with open(self.cli_options.file) as f:
67 self.albums_list = [line.rstrip('\n') for line in f.readlines()]
70 print 'ERROR: "%s": %s' % (self.cli_options.file, err[1])
73 print 'WARNING: ignoring "%s"' % self.cli_args
76 self.albums_list = self.cli_args
78 self.parser.print_usage()
79 print "ERROR: Need at least an argument!"
84 print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port)
86 album = choice(self.albums_list)
87 print 'Queueing "%s"' % album
88 tracks = self.client.find('album', self._u8_convert(album))
90 print 'No tracks found for "%s"' % album
91 self.client.disconnect()
94 self.client.add(track.get('file'))
95 self.client.disconnect()
100 if __name__ == '__main__':
103 except KeyboardInterrupt:
104 sys.stdout.write('exit')
107 # vim: ai ts=4 sw=4 sts=4 expandtab