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