X-Git-Url: http://git.kaliko.me/?p=mpd-goodies.git;a=blobdiff_plain;f=misc%2Fjingle.py;fp=misc%2Fjingle.py;h=0000000000000000000000000000000000000000;hp=3d25dd68731b4383065cc203905a7e063bb97dd7;hb=3b6737cd15bf7dab6595cdaade2bf4b3a1f530a5;hpb=ec7480efdd506097843e12353a43e1e4a0e43645 diff --git a/misc/jingle.py b/misc/jingle.py deleted file mode 100755 index 3d25dd6..0000000 --- a/misc/jingle.py +++ /dev/null @@ -1,132 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Copyright (c) 2009 Efrim {{{ -# -# 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 . -# -# }}} - -DOC = """ -DOC: - - The script randomly pick up a song to queue from the library. - JINGLE_TAG variable allows you to filter the list of songs the - choice is made from. - - Adjust MPD settings and TAG filtering editing config.py. - - JINGLE_TAG is a dictionary, ie. a list of "key:value" couples, keys - among "artist", "title", "genre", "comment" and many others (cf. - man 1 mpc). - - The search made is a non exact search (search vs. find MPD command), - it allows you /some/ fuzziness in JINGLE_TAG settings. - - To retrieve easily jingles with this script you may set the - "comment" tag to "my jingle" for all your jingle sound files (or - anything else you want as long it is a unique identifier for your - jingles). Then set up JINGLE_TAG to fit this choice: - JINGLE_TAG = {'comment': 'my jingle'} - - PAY ATTENTION: - Be sure tags your using in JINGLE_TAG are among tag types being - extracted during audio track discovery in your MPD server settings. - Refer to “metadata_to_use” option in MPD server configuration. - - An alternate way is to pick up songs from a specific directory - setting "filename" key in JINGLE_TAG: - JINGLE_TAG = {'filename': 'partial/path/to/my jingle'} - JINGLE_TAG = {'filename': 'jingle'} - …etc. - - Refer to config.py file for some examples. - -BUGS: - MPD 0.15 is not correctly updating file tags, so you migth set - comment or another tag to filter jingles and not been able to get - files queued with this script because of that. Please check your - tag is known in MPD database running something like that: - - mpc search - - Issue fixed in MPD 0.16 - MPD bugs: http://musicpd.org/mantis/view.php?id=498 -""" - -__version__ = u'0.3' -__author__ = u'$Author: kaliko $' -__date__ = u'$LastChangedDate: 2009-11-17 19:23:34 +0100 (mar. 17 nov. 2009) $'[18:28] - - -# IMPORTS {{{ -import sys - -from random import choice -try: - from mpd import (CommandError) -except ImportError, err: - print 'ERROR: "%s"\n\nPlease install python-mpd module.\n' % err - sys.exit(1) - -try: - from config import JINGLE_TAG -except ImportError, err: - print 'ERROR: "%s"\n' % err - print '\tPlease set JINGLE_TAG in config.py' - sys.exit(1) - -from lib.mpdutils import (mconnect) -#}}} - - -def search(tags):#{{{ - """ - Construct search string for MPD search function. - """ - search_str = list() - for k, v in tags.iteritems(): - search_str.extend([str(k), str(v)]) - return search_str#}}} - - -def main(): - client = mconnect() - ## List tracks matching JINGLE_TAG and randomly chose one. - try: - trk = choice(client.search(*search(JINGLE_TAG))) - except CommandError, err: - print 'Wrong search command, check JINGLE_TAG settings: %s' % err - sys.exit(1) - except IndexError, err: - print ('Search for "%s" returned nothing: %s' % - (' '.join(search(JINGLE_TAG)), err)) - sys.exit(1) - - ## Uncomment to print out file added to playlist - #print 'add "%s"' % trk.get('file') - - client.add(trk.get('file', None)) - client.disconnect() - sys.exit(0) - -# Script starts here -if __name__ == "__main__": - if len(sys.argv) > 1: - print DOC - sys.exit(0) - main() - -# VIM MODLINE -# vim: ai ts=4 sw=4 sts=4 expandtab