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