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
|
Line | |
---|
1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from subprocess import Popen, PIPE |
---|
4 | from os.path import basename, splitext |
---|
5 | |
---|
6 | fieldnames = [ |
---|
7 | 'artist', 'album', 'track', 'title', 'length', 'filename', |
---|
8 | 'status', 'pnum', 'time', 'percent' |
---|
9 | ] |
---|
10 | cmd = [ 'mpc','--format', |
---|
11 | '"[%artist% - ]::[%album% - ]::[%track% - ]::[%title%]::[%time%]::[%file%]"'] |
---|
12 | |
---|
13 | lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n') |
---|
14 | |
---|
15 | if 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) |
---|
30 | else: |
---|
31 | outstr = '--Not playing--' |
---|
32 | |
---|
33 | print outstr + ' |' |
---|
34 | |
---|
Note: See
TracBrowser
for help on using the repository browser.