#!/usr/bin/env python from subprocess import Popen, PIPE from os.path import basename, splitext fieldnames = [ 'artist', 'album', 'track', 'title', 'length', 'filename', 'status', 'pnum', 'time', 'percent' ] cmd = [ 'mpc','--format', '"[%artist% - ]::[%album% - ]::[%track% - ]::[%title%]::[%time%]::[%file%]"'] 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('::') + 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 + ' |'