Changeset 31 for mpd-status/trunk
- Timestamp:
- Feb 18, 2007, 1:51:33 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mpd-status/trunk/mpdstatus.py
r30 r31 20 20 from os.path import sep, splitext 21 21 from sre import compile 22 22 import sys 23 23 state_map = { 24 'play': 'Playing',25 'pause': 'Paused',26 'stop': 'Stopped'24 'play': u'Playing', 25 'pause': u'Paused', 26 'stop': u'Stopped' 27 27 } 28 28 fields = ['artist', 'album', 'track', 'title'] 29 29 strip_paths = [ 30 'albums',31 'classical',32 'houseofdoom',33 'mods',34 'original',35 'soundtracks'30 u'albums', 31 u'classical', 32 u'houseofdoom', 33 u'mods', 34 u'original', 35 u'soundtracks' 36 36 ] 37 37 38 strip_expr = compile( '(%s)/' %r'|'.join(strip_paths))38 strip_expr = compile(u'(%s)/' % ur'|'.join(strip_paths)) 39 39 40 40 def get_status(connection): … … 43 43 song = connection.currentsong() 44 44 songinfo['song'] = \ 45 ' - '.join([song[f] for f in fields if song.has_key(f)]) \ 46 or strip_expr.sub('', splitext(song['file'])[0]).replace(sep, ' - ') 45 u' - '.join([unicode(song[f]) 46 for f in fields 47 if song.has_key(f)]) \ 48 or unicode(strip_expr.sub(u'', 49 splitext(unicode(song['file']))[0]).replace(sep, u' - ')) 47 50 return songinfo 48 51 49 52 if __name__ == '__main__': 53 import locale, codecs 50 54 from mpdclient2 import connect 51 format = '♫ %(state)s: %(song)s' 55 enc = locale.getpreferredencoding() 56 sys.stdout = codecs.getwriter(enc)(sys.__stdout__) 57 format = u'♫ %(state)s: %(song)s' 52 58 print format % get_status(connect())
Note: See TracChangeset
for help on using the changeset viewer.