Added mpc support for state and elapsed

- mpc current format only used to get album info
- state, artist, title, total and elapsed now gotten from mpc command
with no extra parameters and a regular expression
- state uses convert state to sanitize the state from mpc
Ref #2010
This commit is contained in:
Jonathan Montgomery 2019-06-12 17:20:14 -05:00
parent 5d82d544f3
commit 8c0577d9fd
1 changed files with 17 additions and 6 deletions

View File

@ -2,6 +2,7 @@
from __future__ import (unicode_literals, division, absolute_import, print_function) from __future__ import (unicode_literals, division, absolute_import, print_function)
import sys import sys
import re
from powerline.lib.shell import asrun, run_cmd from powerline.lib.shell import asrun, run_cmd
from powerline.lib.unicode import out_u from powerline.lib.unicode import out_u
@ -174,19 +175,29 @@ class MpdPlayerSegment(PlayerSegment):
if password: if password:
host = password + '@' + host host = password + '@' + host
now_playing = run_cmd(pl, [ now_playing = run_cmd(pl, [
'mpc', 'current', 'mpc',
'-f', '%album%\n%artist%\n%title%\n%time%',
'-h', host, '-h', host,
'-p', str(port) '-p', str(port)
], strip=False) ], strip=False)
if not now_playing: album = run_cmd(pl, [
'mpc', 'current',
'-f', '%album%',
'-h', host,
'-p', str(port)
])
if not now_playing or now_playing.count("\n") != 3:
return return
now_playing = now_playing.split('\n') now_playing = re.match(
r"(.*) - (.*)\n\[([a-z]+)\] +[#0-9\/]+ +([0-9\:]+)\/([0-9\:]+)",
now_playing
)
return { return {
'album': now_playing[0], 'state': _convert_state(now_playing[3]),
'album': album,
'artist': now_playing[1], 'artist': now_playing[1],
'title': now_playing[2], 'title': now_playing[2],
'total': now_playing[3], 'elapsed': now_playing[4],
'total': now_playing[5]
} }
else: else:
try: try: