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
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Displays information about the current song in cmus.
|
||||
"""Displays information about the current song in moc.
|
||||
|
||||
Requires the following executable:
|
||||
* cmus-remote
|
||||
* mocp
|
||||
|
||||
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
|
||||
|
@ -24,24 +24,24 @@ from bumblebee.output import scrollable
|
|||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
widgets = [
|
||||
bumblebee.output.Widget(name="cmus.prev"),
|
||||
bumblebee.output.Widget(name="cmus.main", full_text=self.description),
|
||||
bumblebee.output.Widget(name="cmus.next"),
|
||||
bumblebee.output.Widget(name="cmus.shuffle"),
|
||||
bumblebee.output.Widget(name="cmus.repeat"),
|
||||
bumblebee.output.Widget(name="moc.prev"),
|
||||
bumblebee.output.Widget(name="moc.main", full_text=self.description),
|
||||
bumblebee.output.Widget(name="moc.next"),
|
||||
bumblebee.output.Widget(name="moc.shuffle"),
|
||||
bumblebee.output.Widget(name="moc.repeat"),
|
||||
]
|
||||
super(Module, self).__init__(engine, config, widgets)
|
||||
|
||||
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,
|
||||
cmd="cmus-remote -u")
|
||||
cmd="mocp -G")
|
||||
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,
|
||||
cmd="cmus-remote -S")
|
||||
cmd=self._toggle_shuffle)
|
||||
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._status = None
|
||||
|
@ -57,36 +57,47 @@ class Module(bumblebee.engine.Module):
|
|||
self._load_song()
|
||||
|
||||
def state(self, widget):
|
||||
if widget.name == "cmus.shuffle":
|
||||
if widget.name == "moc.shuffle":
|
||||
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"
|
||||
if widget.name == "cmus.prev":
|
||||
if widget.name == "moc.prev":
|
||||
return "prev"
|
||||
if widget.name == "cmus.next":
|
||||
if widget.name == "moc.next":
|
||||
return "next"
|
||||
return self._status
|
||||
|
||||
def _load_song(self):
|
||||
info = ""
|
||||
try:
|
||||
info = bumblebee.util.execute("cmus-remote -Q")
|
||||
info = bumblebee.util.execute("mocp -i")
|
||||
except RuntimeError:
|
||||
pass
|
||||
self._tags = defaultdict(lambda: '')
|
||||
for line in info.split("\n"):
|
||||
if line.startswith("status"):
|
||||
self._status = line.split(" ", 2)[1]
|
||||
if line.startswith("tag"):
|
||||
key, value = line.split(" ", 2)[1:]
|
||||
self._tags.update({ key: value })
|
||||
for key in ["duration", "position"]:
|
||||
if line.startswith("State"):
|
||||
status = line.split(" ", 2)[1]
|
||||
if status == "PAUSE":
|
||||
self._status = "paused"
|
||||
if status == "PLAY":
|
||||
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):
|
||||
dur = int(line.split(" ")[1])
|
||||
self._tags.update({key:bumblebee.util.durationfmt(dur)})
|
||||
if line.startswith("set repeat "):
|
||||
self._repeat = False if "false" in line else True
|
||||
if line.startswith("set shuffle "):
|
||||
self._shuffle = False if "false" in line else True
|
||||
|
||||
def _toggle_shuffle(self, widget):
|
||||
bumblebee.util.execute("mocp -t shuffle")
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue