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 random import choice
24 from os.path import basename
32 class WakeUp(musicpd.MPDClient):
34 'prog': basename(__file__),
35 'description': 'Queues and plays an album chosen at random from a list. Albums list provided from CLI or text file.',
36 'epilog': 'Set MPD host/port in env. var'
40 musicpd.MPDClient.__init__(self)
44 parser = argparse.ArgumentParser(**self.__class__.script_info)
45 parser.add_argument('--version', action='version',
46 version='v%s' % VERSION)
47 parser.add_argument('-f', type=argparse.FileType('r'), dest='albumf',
48 help='text file, one album per line', nargs='?')
49 parser.add_argument('album', type=str,
50 nargs='*', help='album name')
51 args = parser.parse_args()
53 args.album.extend([line.rstrip(' \n')
54 for line in args.albumf.readlines()])
58 'No album names found on CLI, run "{} -h" for usage'.format(sys.argv[0]))
63 albums_list = self._get_args()
64 album = choice(albums_list)
65 print('Queueing "%s"' % album)
67 tracks = self.search('album', album)
69 print('No tracks found for "%s"' % album)
72 self.searchadd('album', album)
78 if __name__ == '__main__':
81 except KeyboardInterrupt:
85 # vim: ai ts=4 sw=4 sts=4 expandtab