source: mpd-status/trunk/mpd-status.py @ 25

Last change on this file since 25 was 24, checked in by simon, 19 years ago

Fix track time vs current track time played mix up.

File size: 1.6 KB
RevLine 
[11]1#!/usr/bin/env python
[16]2# -*- coding: utf-8 -*-
[11]3
[13]4# Copyright © 2005, Simon E. Ward
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of version 2 of the GNU General Public
8# License as published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301, USA
19
[11]20from subprocess import Popen, PIPE
21from os.path import basename, splitext
22
[22]23mpc_fmt = (
24"{"
25    "'artist': '''[%artist% - ]''', "
26    "'album': '''[%album% - ]''', "
27    "'track': '''[%track% - ]''', "
28    "'title': '''[%title%]''', "
[24]29    "'length': '''[%time%]''', "
[22]30    "'file': '''[%file%]'''"
31"}"
32)
33cmd = ['mpc', '--format', mpc_fmt]
[11]34lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n')
35
36if len(lines) >= 3:
[22]37    fields = eval(lines[0])
38    line1 = lines[1].split()
[24]39    fields.update(zip(['status', 'pnum', 'time', 'percent'], line1))
[11]40    status = fields['status'].strip('[]').capitalize() + ':'
41    if fields['title']:
42        title = '%(artist)s%(album)s%(track)s%(title)s' % fields
43    else:
[23]44        title = splitext(basename(fields['file']))[0]
[11]45    time = '%(time)s/%(length)s %(percent)s' % fields
46    outstr = '%s %s [%s]' % (status, title, time)
47else:
48    outstr = '--Not playing--'
49
[21]50print outstr
[11]51
Note: See TracBrowser for help on using the repository browser.