[modules/mpd] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-29 20:23:53 +02:00
parent 2ffd4bca1d
commit dc7577069f

View file

@ -56,18 +56,18 @@ class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config, [])
self._layout = self.parameter("layout", "mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat")
self._layout = self.parameter('layout', 'mpd.prev mpd.main mpd.next mpd.shuffle mpd.repeat')
self._fmt = self.parameter("format", "{artist} - {title} {position}/{duration}")
self._fmt = self.parameter('format', '{artist} - {title} {position}/{duration}')
self._status = None
self._shuffle = False
self._repeat = False
self._tags = defaultdict(lambda: '')
if not self.parameter("host"):
self._hostcmd = ""
if not self.parameter('host'):
self._hostcmd = ''
else:
self._hostcmd = " -h " + self.parameter("host")
self._hostcmd = ' -h ' + self.parameter('host')
# Create widgets
widget_list = []
@ -76,19 +76,19 @@ class Module(bumblebee.engine.Module):
widget = bumblebee.output.Widget(name=widget_name)
widget_list.append(widget)
if widget_name == "mpd.prev":
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "mpc prev" + self._hostcmd}
elif widget_name == "mpd.main":
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "mpc toggle" + self._hostcmd}
if widget_name == 'mpd.prev':
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': 'mpc prev' + self._hostcmd}
elif widget_name == 'mpd.main':
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': 'mpc toggle' + self._hostcmd}
widget.full_text(self.description)
elif widget_name == "mpd.next":
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "mpc next" + self._hostcmd}
elif widget_name == "mpd.shuffle":
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "mpc random" + self._hostcmd}
elif widget_name == "mpd.repeat":
widget_map[widget] = {"button": bumblebee.input.LEFT_MOUSE, "cmd": "mpc repeat" + self._hostcmd}
elif widget_name == 'mpd.next':
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': 'mpc next' + self._hostcmd}
elif widget_name == 'mpd.shuffle':
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': 'mpc random' + self._hostcmd}
elif widget_name == 'mpd.repeat':
widget_map[widget] = {'button': bumblebee.input.LEFT_MOUSE, 'cmd': 'mpc repeat' + self._hostcmd}
else:
raise KeyError("The mpd module does not support a {widget_name!r} widget".format(widget_name=widget_name))
raise KeyError('The mpd module does not support a {widget_name!r} widget'.format(widget_name=widget_name))
self.widgets(widget_list)
# Register input callbacks
@ -106,18 +106,18 @@ class Module(bumblebee.engine.Module):
self._load_song()
def state(self, widget):
if widget.name == "mpd.shuffle":
return "shuffle-on" if self._shuffle else "shuffle-off"
if widget.name == "mpd.repeat":
return "repeat-on" if self._repeat else "repeat-off"
if widget.name == "mpd.prev":
return "prev"
if widget.name == "mpd.next":
return "next"
if widget.name == 'mpd.shuffle':
return 'shuffle-on' if self._shuffle else 'shuffle-off'
if widget.name == 'mpd.repeat':
return 'repeat-on' if self._repeat else 'repeat-off'
if widget.name == 'mpd.prev':
return 'prev'
if widget.name == 'mpd.next':
return 'next'
return self._status
def _load_song(self):
info = ""
info = ''
try:
tags = ['name',
'artist',
@ -138,44 +138,44 @@ class Module(bumblebee.engine.Module):
'prio',
'mtime',
'mdate']
joinedtags = "\n".join(["tag {0} %{0}%".format(tag) for tag in tags])
info = bumblebee.util.execute('mpc -f ' + '"' + joinedtags + '"' + self._hostcmd)
joinedtags = '\n'.join(['tag {0} %{0}%'.format(tag) for tag in tags])
info = bumblebee.util.execute('mpc -f ' + """ + joinedtags + """ + self._hostcmd)
except RuntimeError:
pass
self._tags = defaultdict(lambda: '')
self._status = None
for line in info.split("\n"):
if line.startswith("[playing]"):
self._status = "playing"
elif line.startswith("[paused]"):
self._status = "paused"
for line in info.split('\n'):
if line.startswith('[playing]'):
self._status = 'playing'
elif line.startswith('[paused]'):
self._status = 'paused'
if line.startswith("["):
if line.startswith('['):
timer = line.split()[2]
position = timer.split("/")[0]
dur = timer.split("/")[1]
duration = dur.split(" ")[0]
position = timer.split('/')[0]
dur = timer.split('/')[1]
duration = dur.split(' ')[0]
self._tags.update({'position': position})
self._tags.update({'duration': duration})
if line.startswith("volume"):
value = line.split(" ", 2)[1:]
if line.startswith('volume'):
value = line.split(' ', 2)[1:]
for option in value:
if option.startswith("repeat: on"):
if option.startswith('repeat: on'):
self._repeat = True
elif option.startswith("repeat: off"):
elif option.startswith('repeat: off'):
self._repeat = False
elif option.startswith("random: on"):
elif option.startswith('random: on'):
self._shuffle = True
elif option.startswith("random: off"):
elif option.startswith('random: off'):
self._shuffle = False
if line.startswith("tag"):
key, value = line.split(" ", 2)[1:]
if line.startswith('tag'):
key, value = line.split(' ', 2)[1:]
self._tags.update({key: value})
if key == "file":
self._tags.update({"file1": os.path.basename(value)})
if key == 'file':
self._tags.update({'file1': os.path.basename(value)})
self._tags.update(
{"file2":
{'file2':
os.path.splitext(os.path.basename(value))[0]})
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4