[11] | 1 | #!/usr/bin/env python |
---|
[16] | 2 | # -*- coding: utf-8 -*- |
---|
[11] | 3 | |
---|
[13] | 4 | # Copyright © 2005, Simon E. Ward |
---|
| 5 | # |
---|
| 6 | # This program is free software; you can redistribute it and/or |
---|
| 7 | # modify it under the terms of version 2 of the GNU General Public |
---|
| 8 | # License as published by the Free Software Foundation. |
---|
| 9 | # |
---|
| 10 | # This program is distributed in the hope that it will be useful, |
---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 13 | # General Public License for more details. |
---|
| 14 | # |
---|
| 15 | # You should have received a copy of the GNU General Public License |
---|
| 16 | # along with this program; if not, write to the Free Software |
---|
| 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
| 18 | # 02110-1301, USA |
---|
| 19 | |
---|
[27] | 20 | from os.path import sep, splitext |
---|
| 21 | from sre import compile |
---|
[11] | 22 | |
---|
[27] | 23 | state_map = { |
---|
| 24 | 'play': 'Playing', |
---|
| 25 | 'pause': 'Paused', |
---|
| 26 | 'stop': 'Stopped' |
---|
| 27 | } |
---|
| 28 | fields = ['artist', 'album', 'track', 'title'] |
---|
| 29 | strip_paths = [ |
---|
| 30 | 'albums', |
---|
| 31 | 'classical', |
---|
| 32 | 'houseofdoom', |
---|
| 33 | 'mods', |
---|
| 34 | 'original', |
---|
| 35 | 'soundtracks' |
---|
| 36 | ] |
---|
[11] | 37 | |
---|
[27] | 38 | strip_expr = compile('(%s)/' % r'|'.join(strip_paths)) |
---|
[11] | 39 | |
---|
[28] | 40 | def get_status(connection): |
---|
| 41 | songinfo = {} |
---|
| 42 | songinfo['state'] = state_map[connection.status()['state']] |
---|
| 43 | song = connection.currentsong() |
---|
| 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, ' - ') |
---|
[29] | 47 | return songinfo |
---|
[28] | 48 | |
---|
| 49 | if __name__ == '__main__': |
---|
| 50 | from mpdclient2 import connect |
---|
[29] | 51 | format = '♫ %(state)s: %(song)s' |
---|
| 52 | print format % get_status(connect()) |
---|