summaryrefslogtreecommitdiff
path: root/plugins/mpd_client.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-09 01:23:35 +0100
commitad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f (patch)
tree3f2bbf1be7f753f1c7495f0a60833f469e7f10a7 /plugins/mpd_client.py
parent7fadb35fe2e7932a0a4aa6a8184ab6b186669edc (diff)
parent03999f1ef08036b7ea25e2239cf7b6bcdb4d76cc (diff)
downloadpoezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.gz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.bz2
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.tar.xz
poezio-ad0b3b41ecc0003f3d5b4fdb9799b6e325127e1f.zip
Merge branch 'plugins'
Conflicts: README src/core.py src/tabs.py
Diffstat (limited to 'plugins/mpd_client.py')
-rw-r--r--plugins/mpd_client.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py
new file mode 100644
index 00000000..b56e0d7f
--- /dev/null
+++ b/plugins/mpd_client.py
@@ -0,0 +1,29 @@
+# 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, the 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('port', '6600'))
+ password = self.config.get('password', '')
+ if password:
+ c.password(password)
+ 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'])