Changeset 22 for mpd-status


Ignore:
Timestamp:
Mar 11, 2006, 8:06:54 PM (18 years ago)
Author:
simon
Message:

Request format from mpc which can be (partially) eval()d.

File:
1 edited

Legend:

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

    r21 r22  
    2121from os.path import basename, splitext
    2222
    23 fieldnames = [
    24     'artist', 'album', 'track', 'title', 'length', 'filename',
    25     'status', 'pnum', 'time', 'percent'
    26     ]
    27 delim = '::'
    28 format = delim.join([
    29     "[%artist% - ]", "[%album% - ]", "[%track% - ]",
    30     "[%title%]", "[%time%]", "[%file%]"
    31     ])
    32 cmd = ['mpc', '--format', format]
    33 
     23mpc_fmt = (
     24"{"
     25    "'artist': '''[%artist% - ]''', "
     26    "'album': '''[%album% - ]''', "
     27    "'track': '''[%track% - ]''', "
     28    "'title': '''[%title%]''', "
     29    "'time': '''[%time%]''', "
     30    "'file': '''[%file%]'''"
     31"}"
     32)
     33cmd = ['mpc', '--format', mpc_fmt]
    3434lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n')
    3535
    3636if len(lines) >= 3:
    37     fields = dict(zip(
    38         fieldnames,
    39         map(
    40             lambda s: s.strip('\"'),
    41             lines[0].split(delim) + lines[1].split()
    42             )
    43         ))
     37    fields = eval(lines[0])
     38    line1 = lines[1].split()
     39    fields.update(zip(['status', 'pnum', 'length', 'percent'], line1))
    4440    status = fields['status'].strip('[]').capitalize() + ':'
    4541    if fields['title']:
Note: See TracChangeset for help on using the changeset viewer.