#!/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 subprocess import Popen, PIPE from os.path import basename, splitext mpc_fmt = ( "{" "'artist': '''[%artist% - ]''', " "'album': '''[%album% - ]''', " "'track': '''[%track% - ]''', " "'title': '''[%title%]''', " "'time': '''[%time%]''', " "'file': '''[%file%]'''" "}" ) cmd = ['mpc', '--format', mpc_fmt] lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n') if len(lines) >= 3: fields = eval(lines[0]) line1 = lines[1].split() fields.update(zip(['status', 'pnum', 'length', 'percent'], line1)) 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