X-Git-Url: http://git.kaliko.me/?p=mpd-goodies.git;a=blobdiff_plain;f=src%2Fwakeup;fp=src%2Fwakeup;h=0000000000000000000000000000000000000000;hp=79013f075cfd9ff9a09f2ab1b710195f8361d31c;hb=3b6737cd15bf7dab6595cdaade2bf4b3a1f530a5;hpb=ec7480efdd506097843e12353a43e1e4a0e43645 diff --git a/src/wakeup b/src/wakeup deleted file mode 100755 index 79013f0..0000000 --- a/src/wakeup +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Copyright (c) 2009, 2010, 2012 Kaliko Jack -# -# 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 sys - -from random import choice - -from lib.goodies import Goodie - - -NAME = 'wakeup' -VERSION = '0.1' -USAGE = 'USAGE: %prog --help | AlbumA AlbumB "The Album C" | -f file' - -WAKEUP_OPTS = list([ - { - 'sw': ['-f', '--file'], - 'type': 'str', - 'dest': 'file', - 'metavar': 'filename', - 'help': 'filemame to read album list from. An album name on each line'}, - ]) - - -class WakeUp(Goodie): - """ - """ - script_info = dict({ - 'version': VERSION, - 'prog_name': NAME, - 'description': 'Queue and play an album chosen at random from a list. Albums list provided from CLI or text file.', - 'usage': USAGE, - }) - - def __init__(self): - """""" - Goodie.__init__(self, self.__class__.script_info, - extra_options=WAKEUP_OPTS) - self._get_arg() - self._run() - - def _get_arg(self): - """""" - if self.cli_options.file: - # TODO: handle encoding reading file! - print 'reading from file, assuming %s encoding' % self.localencoding - try: - with open(self.cli_options.file) as f: - self.albums_list = [line.rstrip('\n') for line in f.readlines()] - return True - except IOError, err: - print 'ERROR: "%s": %s' % (self.cli_options.file, err[1]) - sys.exit(1) - if self.cli_args: - print 'WARNING: ignoring "%s"' % self.cli_args - return True - if self.cli_args: - self.albums_list = self.cli_args - return True - self.parser.print_usage() - print "ERROR: Need at least an argument!" - sys.exit(1) - - def _run(self): - """""" - print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port) - self.mpdConnect() - album = choice(self.albums_list) - print 'Queueing "%s"' % album - tracks = self.client.find('album', self._u8_convert(album)) - if not tracks: - print 'No tracks found for "%s"' % album - self.client.disconnect() - sys.exit(1) - for track in tracks: - self.client.add(track.get('file')) - self.client.disconnect() - sys.exit(0) - - -# Script starts here -if __name__ == '__main__': - try: - WakeUp() - except KeyboardInterrupt: - sys.stdout.write('exit') - -# VIM MODLINE -# vim: ai ts=4 sw=4 sts=4 expandtab