#!/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% - ][%album% - ][%track% - ]%title%]\n[%file%]' cmd = ['mpc', '--format', mpc_fmt] lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n') outstr = lines[0] or splitext(basename(lines[1]))[0] if len(lines) >= 4: (status, pnum, time, percent) = lines[2].split() outstr = status + ' ' + outstr print outstr