[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 | format = '♫ %(state)s: %(song)s' |
---|
| 30 | strip_paths = [ |
---|
| 31 | 'albums', |
---|
| 32 | 'classical', |
---|
| 33 | 'houseofdoom', |
---|
| 34 | 'mods', |
---|
| 35 | 'original', |
---|
| 36 | 'soundtracks' |
---|
| 37 | ] |
---|
[11] | 38 | |
---|
[27] | 39 | strip_expr = compile('(%s)/' % r'|'.join(strip_paths)) |
---|
[11] | 40 | |
---|
[28] | 41 | def 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 | |
---|
| 50 | if __name__ == '__main__': |
---|
| 51 | from mpdclient2 import connect |
---|
| 52 | print get_status(connect()) |
---|