source: mpd-status/trunk/mpd-status.py @ 27

Last change on this file since 27 was 27, checked in by simon, 17 years ago

Rewrite to use mpdclient instead of invoking the command-line mpc.

File size: 1.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
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
20from mpdclient2 import connect
21from os.path import sep, splitext
22from sre import compile
23
24state_map = {
25    'play': 'Playing',
26    'pause': 'Paused',
27    'stop': 'Stopped'
28    }
29fields = ['artist', 'album', 'track', 'title']
30format = '♫ %(state)s: %(song)s'
31strip_paths = [
32    'albums',
33    'classical',
34    'houseofdoom',
35    'mods',
36    'original',
37    'soundtracks'
38    ]
39
40strip_expr = compile('(%s)/' % r'|'.join(strip_paths))
41
42songinfo = {}
43mpc = connect()
44songinfo['state'] = state_map[mpc.status()['state']]
45song = mpc.currentsong()
46songinfo['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, ' - ')
49print format % songinfo
Note: See TracBrowser for help on using the repository browser.