From b8e09b3e42407f7b5c5be7510c65beb5db00c9b4 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 30 Aug 2015 13:21:01 +0300 Subject: [PATCH] Fix support for passworded connections in mpd+python-mpd* player seg Fixes #1437 --- powerline/segments/common/players.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index 1e03af93..8ae6cb1a 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -167,14 +167,16 @@ Requires cmus-remote command be acessible from $PATH. class MpdPlayerSegment(PlayerSegment): - def get_player_status(self, pl, host='localhost', port=6600): + def get_player_status(self, pl, host='localhost', password=None, port=6600): try: import mpd except ImportError: + if password: + host = password + '@' + host now_playing = run_cmd(pl, [ 'mpc', 'current', '-f', '%album%\n%artist%\n%title%\n%time%', - '-h', str(host), + '-h', host, '-p', str(port) ], strip=False) if not now_playing: @@ -189,6 +191,8 @@ class MpdPlayerSegment(PlayerSegment): else: client = mpd.MPDClient() client.connect(host, port) + if password: + client.password(password) now_playing = client.currentsong() if not now_playing: return @@ -220,6 +224,8 @@ package) or alternatively the ``mpc`` command to be acessible from $PATH. {0} :param str host: Host on which mpd runs. +:param str password: + Password used for connecting to daemon. :param int port: Port which should be connected to. ''').format(_common_args.format('mpd')))