Changeset 27 for mpd-status/trunk/mpd-status.py
- Timestamp:
- Feb 17, 2007, 3:49:56 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mpd-status/trunk/mpd-status.py
r26 r27 18 18 # 02110-1301, USA 19 19 20 from subprocess import Popen, PIPE 21 from os.path import basename, splitext 20 from mpdclient2 import connect 21 from os.path import sep, splitext 22 from sre import compile 22 23 23 mpc_fmt = '[[%artist% - ][%album% - ][%track% - ]%title%]\n[%file%]' 24 cmd = ['mpc', '--format', mpc_fmt] 25 lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n') 26 outstr = lines[0] or splitext(basename(lines[1]))[0] 24 state_map = { 25 'play': 'Playing', 26 'pause': 'Paused', 27 'stop': 'Stopped' 28 } 29 fields = ['artist', 'album', 'track', 'title'] 30 format = '♫ %(state)s: %(song)s' 31 strip_paths = [ 32 'albums', 33 'classical', 34 'houseofdoom', 35 'mods', 36 'original', 37 'soundtracks' 38 ] 27 39 28 if len(lines) >= 4: 29 (status, pnum, time, percent) = lines[2].split() 30 outstr = status + ' ' + outstr 40 strip_expr = compile('(%s)/' % r'|'.join(strip_paths)) 31 41 32 print outstr 33 42 songinfo = {} 43 mpc = connect() 44 songinfo['state'] = state_map[mpc.status()['state']] 45 song = mpc.currentsong() 46 songinfo['song'] = \ 47 ' - '.join([song[f] for f in fields if song.has_key(f)]) \ 48 or strip_expr.sub('', splitext(song['file'])[0]).replace(sep, ' - ') 49 print format % songinfo
Note: See TracChangeset
for help on using the changeset viewer.