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

Last change on this file since 14 was 13, checked in by simon, 19 years ago

Added copyright and license information

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