From 2a9484a6800dc4d06a7c535b6fdf58f01e1abc00 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 20:25:30 +0100 Subject: [PATCH 1/2] add a mpd plugin --- plugins/mpd_client.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plugins/mpd_client.py diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py new file mode 100644 index 00000000..6298a729 --- /dev/null +++ b/plugins/mpd_client.py @@ -0,0 +1,27 @@ +# a plugin adding a command to manipulate an MPD instance + +from plugin import BasePlugin +from common import shell_split +import mpd + +class Plugin(BasePlugin): + def init(self): + self.add_command('mpd', self.command_mpd, "Usage: /mpd [full]\nMpd: sends a message showing the current song of an MPD instance. If full is provided, teh message is more verbose.", self.completion_mpd) + + def command_mpd(self, args): + args = shell_split(args) + c = mpd.MPDClient() + c.connect(host=self.config.get('host', 'localhost'), port=self.config.get('host', '6600')) + + current = c.currentsong() + current_time = float(c.status()['elapsed']) + + s = '%(artist)s - %(title)s (%(album)s)' % current + if 'full' in args: + pourcentage = int(current_time / float(current['time']) * 10) + s += ' \x192[\x191' + '-'*(pourcentage-1) + '\x193+' + '\x191' + '-' * (10-pourcentage-1) + '\x192]\x19o' + if not self.core.send_message('%s' % (s,)): + self.core.information('Cannot send result (%s), this is not a conversation tab' % result) + + def completion_mpd(self, the_input): + return the_input.auto_completion(['full']) From d62a3a1b1bf2eda1186aa8bf94bd33c1b54c4d59 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 20:29:46 +0100 Subject: [PATCH 2/2] mpd plugins now accepts a password and catches some errors. --- plugins/mpd_client.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py index 6298a729..5207a0d6 100644 --- a/plugins/mpd_client.py +++ b/plugins/mpd_client.py @@ -10,9 +10,19 @@ class Plugin(BasePlugin): def command_mpd(self, args): args = shell_split(args) - c = mpd.MPDClient() + c = mpd.MPDClient() + try: c.connect(host=self.config.get('host', 'localhost'), port=self.config.get('host', '6600')) - + except Exception as e: + self.core.information('%s' % (e,), 'Error') + return + password = self.config.get('password', '') + if password: + try: + c.password(password) + except Exception as e: + self.core.information('%s' % (e,), 'Error') + return current = c.currentsong() current_time = float(c.status()['elapsed'])