#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright © 2005, Simon E. Ward # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License as published by the Free Software Foundation. # # 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, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA from mpdclient2 import connect from os.path import sep, splitext from sre import compile state_map = { 'play': 'Playing', 'pause': 'Paused', 'stop': 'Stopped' } fields = ['artist', 'album', 'track', 'title'] format = '♫ %(state)s: %(song)s' strip_paths = [ 'albums', 'classical', 'houseofdoom', 'mods', 'original', 'soundtracks' ] strip_expr = compile('(%s)/' % r'|'.join(strip_paths)) songinfo = {} mpc = connect() songinfo['state'] = state_map[mpc.status()['state']] song = mpc.currentsong() songinfo['song'] = \ ' - '.join([song[f] for f in fields if song.has_key(f)]) \ or strip_expr.sub('', splitext(song['file'])[0]).replace(sep, ' - ') print format % songinfo