Skip to content

Commit ab14923

Browse files
committed
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
1 parent d47c31a commit ab14923

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

plugins/mpd_client.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from plugin import BasePlugin
44
from common import shell_split
5+
from os.path import basename as base
56
import tabs
67
import mpd
78

@@ -19,14 +20,19 @@ def command_mpd(self, args):
1920
if password:
2021
c.password(password)
2122
current = c.currentsong()
22-
current_time = float(c.status()['elapsed'])
23+
artist = current.get('artist', 'Unknown artist')
24+
album = current.get('album', 'Unknown album')
25+
title = current.get('title', base(current.get('file', 'Unknown title')))
2326

24-
s = '%(artist)s - %(title)s (%(album)s)' % current
27+
28+
s = '%s - %s (%s)' % (artist, title, album)
2529
if 'full' in args:
26-
pourcentage = int(current_time / float(current['time']) * 10)
27-
s += ' \x192}[\x191}' + '-'*(pourcentage-1) + '\x193}+' + '\x191}' + '-' * (10-pourcentage-1) + '\x192}]\x19o'
30+
if 'elapsed' in current and 'time' in current:
31+
current_time = float(c.status()['elapsed'])
32+
pourcentage = int(current_time / float(current['time']) * 10)
33+
s += ' \x192}[\x191}' + '-'*(pourcentage-1) + '\x193}+' + '\x191}' + '-' * (10-pourcentage-1) + '\x192}]\x19o'
2834
if not self.core.send_message('%s' % (s,)):
2935
self.core.information('Cannot send result (%s)' % s, 'Error')
3036

3137
def completion_mpd(self, the_input):
32-
return the_input.auto_completion(['full'])
38+
return the_input.auto_completion(['full'], quotify=False)

0 commit comments

Comments
 (0)