Fix mpd support
This commit is contained in:
parent
a37f90921f
commit
f233c1f77e
|
@ -16,7 +16,7 @@ if sys.platform.startswith('win32'):
|
|||
Popen = partial(Popen, creationflags=0x08000000)
|
||||
|
||||
|
||||
def run_cmd(pl, cmd, stdin=None):
|
||||
def run_cmd(pl, cmd, stdin=None, strip=True):
|
||||
'''Run command and return its stdout, stripped
|
||||
|
||||
If running command fails returns None and logs failure to ``pl`` argument.
|
||||
|
@ -27,6 +27,8 @@ def run_cmd(pl, cmd, stdin=None):
|
|||
Command which will be run.
|
||||
:param str stdin:
|
||||
String passed to command. May be None.
|
||||
:param bool strip:
|
||||
True if the result should be stripped.
|
||||
'''
|
||||
try:
|
||||
p = Popen(cmd, shell=False, stdout=PIPE, stdin=PIPE)
|
||||
|
@ -36,7 +38,7 @@ def run_cmd(pl, cmd, stdin=None):
|
|||
else:
|
||||
stdout, err = p.communicate(stdin)
|
||||
stdout = stdout.decode(get_preferred_input_encoding())
|
||||
return stdout.strip()
|
||||
return stdout.strip() if strip else stdout
|
||||
|
||||
|
||||
def asrun(pl, ascript):
|
||||
|
|
|
@ -160,7 +160,12 @@ class MpdPlayerSegment(PlayerSegment):
|
|||
try:
|
||||
import mpd
|
||||
except ImportError:
|
||||
now_playing = run_cmd(pl, ['mpc', 'current', '-f', '%album%\n%artist%\n%title%\n%time%', '-h', str(host), '-p', str(port)])
|
||||
now_playing = run_cmd(pl, [
|
||||
'mpc', 'current',
|
||||
'-f', '%album%\n%artist%\n%title%\n%time%',
|
||||
'-h', str(host),
|
||||
'-p', str(port)
|
||||
], strip=False)
|
||||
if not now_playing:
|
||||
return
|
||||
now_playing = now_playing.split('\n')
|
||||
|
@ -372,7 +377,7 @@ class RhythmboxPlayerSegment(PlayerSegment):
|
|||
'rhythmbox-client',
|
||||
'--no-start', '--no-present',
|
||||
'--print-playing-format', '%at\n%aa\n%tt\n%te\n%td'
|
||||
])
|
||||
], strip=False)
|
||||
if not now_playing:
|
||||
return
|
||||
now_playing = now_playing.split('\n')
|
||||
|
|
Loading…
Reference in New Issue