Changeset 26 for mpd-status/trunk


Ignore:
Timestamp:
Jun 5, 2006, 1:00:32 AM (19 years ago)
Author:
simon
Message:

Simplified info-grabbing. mpd-status is now more-or-less a wrapper to mpc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mpd-status/trunk/mpd-status.py

    r24 r26  
    2121from os.path import basename, splitext
    2222
    23 mpc_fmt = (
    24 "{"
    25     "'artist': '''[%artist% - ]''', "
    26     "'album': '''[%album% - ]''', "
    27     "'track': '''[%track% - ]''', "
    28     "'title': '''[%title%]''', "
    29     "'length': '''[%time%]''', "
    30     "'file': '''[%file%]'''"
    31 "}"
    32 )
     23mpc_fmt = '[[%artist% - ][%album% - ][%track% - ]%title%]\n[%file%]'
    3324cmd = ['mpc', '--format', mpc_fmt]
    3425lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n')
     26outstr = lines[0] or splitext(basename(lines[1]))[0]
    3527
    36 if len(lines) >= 3:
    37     fields = eval(lines[0])
    38     line1 = lines[1].split()
    39     fields.update(zip(['status', 'pnum', 'time', 'percent'], line1))
    40     status = fields['status'].strip('[]').capitalize() + ':'
    41     if fields['title']:
    42         title = '%(artist)s%(album)s%(track)s%(title)s' % fields
    43     else:
    44         title = splitext(basename(fields['file']))[0]
    45     time = '%(time)s/%(length)s %(percent)s' % fields
    46     outstr = '%s %s [%s]' % (status, title, time)
    47 else:
    48     outstr = '--Not playing--'
     28if len(lines) >= 4:
     29    (status, pnum, time, percent) = lines[2].split()
     30    outstr = status + ' ' + outstr
    4931
    5032print outstr
Note: See TracChangeset for help on using the changeset viewer.