#!/usr/bin/env python # 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 subprocess import Popen, PIPE from os.path import basename, splitext fieldnames = [ 'artist', 'album', 'track', 'title', 'length', 'filename', 'status', 'pnum', 'time', 'percent' ] delim = '::' format = delim.join([ "[%artist% - ]", "[%album% - ]", "[%track% - ]", "[%title%]", "[%time%]", "[%file%]" ]) cmd = ['mpc', '--format', format] lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n') if len(lines) >= 3: fields = dict(zip( fieldnames, map( lambda s: s.strip('\"'), lines[0].split(delim) + lines[1].split() ) )) status = fields['status'].strip('[]').capitalize() + ':' if fields['title']: title = '%(artist)s%(album)s%(track)s%(title)s' % fields else: title = splitext(basename(fields['filename']))[0] time = '%(time)s/%(length)s %(percent)s' % fields outstr = '%s %s [%s]' % (status, title, time) else: outstr = '--Not playing--' print outstr + ' |'