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

Last change on this file since 26 was 26, checked in by simon, 18 years ago

Simplified info-grabbing. mpd-status is now more-or-less a wrapper to mpc.

File size: 1.1 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 subprocess import Popen, PIPE
21from os.path import basename, splitext
22
23mpc_fmt = '[[%artist% - ][%album% - ][%track% - ]%title%]\n[%file%]'
24cmd = ['mpc', '--format', mpc_fmt]
25lines = Popen(cmd, stdout=PIPE).communicate()[0].split('\n')
26outstr = lines[0] or splitext(basename(lines[1]))[0]
27
28if len(lines) >= 4:
29    (status, pnum, time, percent) = lines[2].split()
30    outstr = status + ' ' + outstr
31
32print outstr
33
Note: See TracBrowser for help on using the repository browser.