Adds moc.py module. Does not add icons
This commit is contained in:
parent
ddbd063ade
commit
ae7a5bf7a9
1 changed files with 39 additions and 28 deletions
|
@ -1,13 +1,13 @@
|
||||||
# pylint: disable=C0111,R0903
|
# pylint: disable=C0111,R0903
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""Displays information about the current song in cmus.
|
"""Displays information about the current song in moc.
|
||||||
|
|
||||||
Requires the following executable:
|
Requires the following executable:
|
||||||
* cmus-remote
|
* mocp
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* cmus.format: Format string for the song information. Tag values can be put in curly brackets (i.e. {artist})
|
* mocp.format: Format string for the song information. Tag values can be put in curly brackets (i.e. {artist})
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -24,24 +24,24 @@ from bumblebee.output import scrollable
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
widgets = [
|
widgets = [
|
||||||
bumblebee.output.Widget(name="cmus.prev"),
|
bumblebee.output.Widget(name="moc.prev"),
|
||||||
bumblebee.output.Widget(name="cmus.main", full_text=self.description),
|
bumblebee.output.Widget(name="moc.main", full_text=self.description),
|
||||||
bumblebee.output.Widget(name="cmus.next"),
|
bumblebee.output.Widget(name="moc.next"),
|
||||||
bumblebee.output.Widget(name="cmus.shuffle"),
|
bumblebee.output.Widget(name="moc.shuffle"),
|
||||||
bumblebee.output.Widget(name="cmus.repeat"),
|
bumblebee.output.Widget(name="moc.repeat"),
|
||||||
]
|
]
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
super(Module, self).__init__(engine, config, widgets)
|
||||||
|
|
||||||
engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="cmus-remote -r")
|
cmd="mocp -r")
|
||||||
engine.input.register_callback(widgets[1], button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(widgets[1], button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="cmus-remote -u")
|
cmd="mocp -G")
|
||||||
engine.input.register_callback(widgets[2], button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(widgets[2], button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="cmus-remote -n")
|
cmd="mocp -f")
|
||||||
engine.input.register_callback(widgets[3], button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(widgets[3], button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="cmus-remote -S")
|
cmd=self._toggle_shuffle)
|
||||||
engine.input.register_callback(widgets[4], button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(widgets[4], button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="cmus-remote -R")
|
cmd=self._toggle_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
|
||||||
|
@ -57,36 +57,47 @@ class Module(bumblebee.engine.Module):
|
||||||
self._load_song()
|
self._load_song()
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
if widget.name == "cmus.shuffle":
|
if widget.name == "moc.shuffle":
|
||||||
return "shuffle-on" if self._shuffle else "shuffle-off"
|
return "shuffle-on" if self._shuffle else "shuffle-off"
|
||||||
if widget.name == "cmus.repeat":
|
if widget.name == "moc.repeat":
|
||||||
return "repeat-on" if self._repeat else "repeat-off"
|
return "repeat-on" if self._repeat else "repeat-off"
|
||||||
if widget.name == "cmus.prev":
|
if widget.name == "moc.prev":
|
||||||
return "prev"
|
return "prev"
|
||||||
if widget.name == "cmus.next":
|
if widget.name == "moc.next":
|
||||||
return "next"
|
return "next"
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
def _load_song(self):
|
def _load_song(self):
|
||||||
info = ""
|
info = ""
|
||||||
try:
|
try:
|
||||||
info = bumblebee.util.execute("cmus-remote -Q")
|
info = bumblebee.util.execute("mocp -i")
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
self._tags = defaultdict(lambda: '')
|
self._tags = defaultdict(lambda: '')
|
||||||
for line in info.split("\n"):
|
for line in info.split("\n"):
|
||||||
if line.startswith("status"):
|
if line.startswith("State"):
|
||||||
self._status = line.split(" ", 2)[1]
|
status = line.split(" ", 2)[1]
|
||||||
if line.startswith("tag"):
|
if status == "PAUSE":
|
||||||
key, value = line.split(" ", 2)[1:]
|
self._status = "paused"
|
||||||
self._tags.update({ key: value })
|
if status == "PLAY":
|
||||||
for key in ["duration", "position"]:
|
self._status = "playing"
|
||||||
|
if line.startswith("Title"):
|
||||||
|
value = line.split(" ", 2)[1:]
|
||||||
|
self._tags.update({ "title": value })
|
||||||
|
if line.startswith("Artist"):
|
||||||
|
value = line.split(" ", 2)[1:]
|
||||||
|
self._tags.update({ "artist": value })
|
||||||
|
for key in ["TotalSec", "CurrentSec"]:
|
||||||
if line.startswith(key):
|
if line.startswith(key):
|
||||||
dur = int(line.split(" ")[1])
|
dur = int(line.split(" ")[1])
|
||||||
self._tags.update({key:bumblebee.util.durationfmt(dur)})
|
self._tags.update({key:bumblebee.util.durationfmt(dur)})
|
||||||
if line.startswith("set repeat "):
|
|
||||||
self._repeat = False if "false" in line else True
|
def _toggle_shuffle(self, widget):
|
||||||
if line.startswith("set shuffle "):
|
bumblebee.util.execute("mocp -t shuffle")
|
||||||
self._shuffle = False if "false" in line else True
|
self._shuffle = False if self._shuffle else True
|
||||||
|
|
||||||
|
def _toggle_repeat(self, widget):
|
||||||
|
bumblebee.util.execute("mocp -t repeat")
|
||||||
|
self._repeat = False if self._repeat else True
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Add table
Reference in a new issue