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