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

Last change on this file since 12 was 11, checked in by simon, 19 years ago

Import mpd-status, a quick script to print the song currently playing in mpd. Based off szs3rd's mpc module.

File size: 964 bytes
RevLine 
[11]1#!/usr/bin/env python
2
3from subprocess import Popen, PIPE
4from os.path import basename, splitext
5
6fieldnames = [
7    'artist', 'album', 'track', 'title', 'length', 'filename',
8    'status', 'pnum', 'time', 'percent'
9    ]
10cmd = [ 'mpc','--format',
11    '"[%artist% - ]::[%album% - ]::[%track% - ]::[%title%]::[%time%]::[%file%]"']
12
13lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n')
14
15if len(lines) >= 3:
16    fields = dict(zip(
17        fieldnames,
18        map(
19            lambda s: s.strip('\"'),
20            lines[0].split('::') + lines[1].split()
21            )
22        ))
23    status = fields['status'].strip('[]').capitalize() + ':'
24    if fields['title']:
25        title = '%(artist)s%(album)s%(track)s%(title)s' % fields
26    else:
27        title = splitext(basename(fields['filename']))[0]
28    time = '%(time)s/%(length)s %(percent)s' % fields
29    outstr = '%s %s [%s]' % (status, title, time)
30else:
31    outstr = '--Not playing--'
32
33print outstr + ' |'
34
Note: See TracBrowser for help on using the repository browser.