Changeset 31


Ignore:
Timestamp:
Feb 18, 2007, 1:51:33 AM (18 years ago)
Author:
simon
Message:

Munge to Unicode -- py-libmpdclient appears to return standard byte strings.

File:
1 edited

Legend:

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

    r30 r31  
    2020from os.path import sep, splitext
    2121from sre import compile
    22 
     22import sys
    2323state_map = {
    24     'play': 'Playing',
    25     'pause': 'Paused',
    26     'stop': 'Stopped'
     24    'play': u'Playing',
     25    'pause': u'Paused',
     26    'stop': u'Stopped'
    2727    }
    2828fields = ['artist', 'album', 'track', 'title']
    2929strip_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'
    3636    ]
    3737
    38 strip_expr = compile('(%s)/' % r'|'.join(strip_paths))
     38strip_expr = compile(u'(%s)/' % ur'|'.join(strip_paths))
    3939
    4040def get_status(connection):
     
    4343    song = connection.currentsong()
    4444    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' - '))
    4750    return songinfo
    4851
    4952if __name__ == '__main__':
     53    import locale, codecs
    5054    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'
    5258    print format % get_status(connect())
Note: See TracChangeset for help on using the changeset viewer.