X-Git-Url: http://git.kaliko.me/?p=mpd-goodies.git;a=blobdiff_plain;f=bin%2Fwakeup;fp=bin%2Fwakeup;h=f938473b11dbfc0145fe113d759ebb0720a218a9;hp=0000000000000000000000000000000000000000;hb=3b6737cd15bf7dab6595cdaade2bf4b3a1f530a5;hpb=ec7480efdd506097843e12353a43e1e4a0e43645 diff --git a/bin/wakeup b/bin/wakeup new file mode 100755 index 0000000..f938473 --- /dev/null +++ b/bin/wakeup @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (c) 2009,2010,2012,2019 kaliko +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import argparse +import sys + +from random import choice +from os.path import basename + +import musicpd + + +VERSION = '0.2' + + +class WakeUp(musicpd.MPDClient): + script_info = dict({ + 'prog': basename(__file__), + 'description': 'Queues and plays an album chosen at random from a list. Albums list provided from CLI or text file.', + 'epilog': 'Set MPD host/port in env. var' + }) + + def __init__(self): + musicpd.MPDClient.__init__(self) + self._run() + + def _get_args(self): + parser = argparse.ArgumentParser(**self.__class__.script_info) + parser.add_argument('--version', action='version', + version='v%s' % VERSION) + parser.add_argument('-f', type=argparse.FileType('r'), dest='albumf', + help='text file, one album per line', nargs='?') + parser.add_argument('album', type=str, + nargs='*', help='album name') + args = parser.parse_args() + if args.albumf: + args.album.extend([line.rstrip(' \n') + for line in args.albumf.readlines()]) + if not args.album: + # parser.print_help() + print( + 'No album names found on CLI, run "{} -h" for usage'.format(sys.argv[0])) + sys.exit(1) + return args.album + + def _run(self): + albums_list = self._get_args() + album = choice(albums_list) + print('Queueing "%s"' % album) + self.connect() + tracks = self.search('album', album) + if not tracks: + print('No tracks found for "%s"' % album) + self.disconnect() + sys.exit(1) + self.searchadd('album', album) + self.disconnect() + sys.exit(0) + + +# Script starts here +if __name__ == '__main__': + try: + WakeUp() + except KeyboardInterrupt: + print('exit') + +# VIM MODLINE +# vim: ai ts=4 sw=4 sts=4 expandtab