mirror of
https://github.com/powerline/powerline.git
synced 2025-07-30 01:05:42 +02:00
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)
|
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
|
'''Run command and return its stdout, stripped
|
||||||
|
|
||||||
If running command fails returns None and logs failure to ``pl`` argument.
|
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.
|
Command which will be run.
|
||||||
:param str stdin:
|
:param str stdin:
|
||||||
String passed to command. May be None.
|
String passed to command. May be None.
|
||||||
|
:param bool strip:
|
||||||
|
True if the result should be stripped.
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
p = Popen(cmd, shell=False, stdout=PIPE, stdin=PIPE)
|
p = Popen(cmd, shell=False, stdout=PIPE, stdin=PIPE)
|
||||||
@ -36,7 +38,7 @@ def run_cmd(pl, cmd, stdin=None):
|
|||||||
else:
|
else:
|
||||||
stdout, err = p.communicate(stdin)
|
stdout, err = p.communicate(stdin)
|
||||||
stdout = stdout.decode(get_preferred_input_encoding())
|
stdout = stdout.decode(get_preferred_input_encoding())
|
||||||
return stdout.strip()
|
return stdout.strip() if strip else stdout
|
||||||
|
|
||||||
|
|
||||||
def asrun(pl, ascript):
|
def asrun(pl, ascript):
|
||||||
|
@ -160,7 +160,12 @@ class MpdPlayerSegment(PlayerSegment):
|
|||||||
try:
|
try:
|
||||||
import mpd
|
import mpd
|
||||||
except ImportError:
|
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:
|
if not now_playing:
|
||||||
return
|
return
|
||||||
now_playing = now_playing.split('\n')
|
now_playing = now_playing.split('\n')
|
||||||
@ -372,7 +377,7 @@ class RhythmboxPlayerSegment(PlayerSegment):
|
|||||||
'rhythmbox-client',
|
'rhythmbox-client',
|
||||||
'--no-start', '--no-present',
|
'--no-start', '--no-present',
|
||||||
'--print-playing-format', '%at\n%aa\n%tt\n%te\n%td'
|
'--print-playing-format', '%at\n%aa\n%tt\n%te\n%td'
|
||||||
])
|
], strip=False)
|
||||||
if not now_playing:
|
if not now_playing:
|
||||||
return
|
return
|
||||||
now_playing = now_playing.split('\n')
|
now_playing = now_playing.split('\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user