Changeset 28


Ignore:
Timestamp:
Feb 17, 2007, 4:14:34 PM (18 years ago)
Author:
simon
Message:

Stuck the status string grabby thing into a function so I could use it as a
module.

File:
1 edited

Legend:

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

    r27 r28  
    1818# 02110-1301, USA
    1919
    20 from mpdclient2 import connect
    2120from os.path import sep, splitext
    2221from sre import compile
     
    4039strip_expr = compile('(%s)/' % r'|'.join(strip_paths))
    4140
    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
     41def get_status(connection):
     42    songinfo = {}
     43    songinfo['state'] = state_map[connection.status()['state']]
     44    song = connection.currentsong()
     45    songinfo['song'] = \
     46        ' - '.join([song[f] for f in fields if song.has_key(f)]) \
     47        or strip_expr.sub('', splitext(song['file'])[0]).replace(sep, ' - ')
     48    return format % songinfo
     49
     50if __name__ == '__main__':
     51    from mpdclient2 import connect
     52    print get_status(connect())
Note: See TracChangeset for help on using the changeset viewer.