summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-07-07 04:39:01 +0200
committermathieui <mathieui@mathieui.net>2012-07-07 04:39:01 +0200
commitab14923611a438386822598e2fc24b4efa00d282 (patch)
tree83d796a1c29b8cecb6069d927c951e671b2facf2
parentd47c31a58748d6cfc52c893eaf39d5412cba1f84 (diff)
downloadpoezio-ab14923611a438386822598e2fc24b4efa00d282.tar.gz
poezio-ab14923611a438386822598e2fc24b4efa00d282.tar.bz2
poezio-ab14923611a438386822598e2fc24b4efa00d282.tar.xz
poezio-ab14923611a438386822598e2fc24b4efa00d282.zip
Prevent tracebacks in the mpd_client plugin
Do not traceback when: - The song has no album - the song has no title - the song has no artist - the playlist is empty - mpd is not playing
-rw-r--r--plugins/mpd_client.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py
index 4c70f066..e71c8a5f 100644
--- a/plugins/mpd_client.py
+++ b/plugins/mpd_client.py
@@ -2,6 +2,7 @@
from plugin import BasePlugin
from common import shell_split
+from os.path import basename as base
import tabs
import mpd
@@ -19,14 +20,19 @@ class Plugin(BasePlugin):
if password:
c.password(password)
current = c.currentsong()
- current_time = float(c.status()['elapsed'])
+ artist = current.get('artist', 'Unknown artist')
+ album = current.get('album', 'Unknown album')
+ title = current.get('title', base(current.get('file', 'Unknown title')))
- s = '%(artist)s - %(title)s (%(album)s)' % current
+
+ s = '%s - %s (%s)' % (artist, title, album)
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 'elapsed' in current and 'time' in current:
+ current_time = float(c.status()['elapsed'])
+ 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)' % s, 'Error')
def completion_mpd(self, the_input):
- return the_input.auto_completion(['full'])
+ return the_input.auto_completion(['full'], quotify=False)