From 6fd168993f532a718d51ce6b996bfefe23320b69 Mon Sep 17 00:00:00 2001 From: Chrugi Date: Mon, 12 Jun 2017 15:06:56 +0200 Subject: [PATCH 1/2] Added Module for mocp (Music On Console Player) This Module Displays the Status, Song, Artist and Time of the current song played or paused in mocp. Clicking the Modules toggles play/pause. I'm no programmer so alteration and feedback is welcome. Best regards, Chrugi --- bumblebee/modules/mocp.py | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bumblebee/modules/mocp.py diff --git a/bumblebee/modules/mocp.py b/bumblebee/modules/mocp.py new file mode 100644 index 0000000..6c7006f --- /dev/null +++ b/bumblebee/modules/mocp.py @@ -0,0 +1,66 @@ +# pylint: disable=C0111,R0903 +# -*- coding: utf-8 -*- + +"""Displays information about the current song in mocp. + +Requires the following executable: + * mocp + +Parameters: + * mocp.format: Format string for the song information. Tag values can be put in curly brackets (i.e. {artist}) +""" + +from collections import defaultdict + +import string + +import bumblebee.util +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +from bumblebee.output import scrollable + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + widgets = [ + bumblebee.output.Widget(name="mocp.main", full_text=self.description), + ] + super(Module, self).__init__(engine, config, widgets) + + engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE, + cmd="mocp -G") + + #@scrollable + def description(self, widget): + if self._running == 1: + display = self._status + ": " + self._artist + " - " + self._title + " | " + self._position + "/" + self._duration + else: + display = "Music On Console Player" + return display + + def update(self, widgets): + self._load_song() + + def _load_song(self): + try: + info = bumblebee.util.execute("mocp -i") + for line in info.split("\n"): + if line.startswith("State:"): + self._status = line.split(": ", 2)[1] + if line.startswith("Artist:"): + self._artist = line.split(": ", 2)[1] + if line.startswith("Title:"): + self._title = line.split(": ", 2)[1] + self._title = self._title.split("(by ",2)[0] + if line.startswith("CurrentTime:"): + self._position = line.split(": ", 2)[1] + if line.startswith("TotalTime:"): + self._duration = line.split(": ", 2)[1] + self._running = 1 + if line.startswith("State: STOP"): + self._running = 0 + except RuntimeError: + self._running = 0 + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 82d8cf1370250464c791c4b30a94f32ec219694e Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 12 Jun 2017 18:50:08 +0200 Subject: [PATCH 2/2] [modules/mocp] Initialize variables --- bumblebee/modules/mocp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bumblebee/modules/mocp.py b/bumblebee/modules/mocp.py index 6c7006f..5c203b2 100644 --- a/bumblebee/modules/mocp.py +++ b/bumblebee/modules/mocp.py @@ -30,6 +30,7 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE, cmd="mocp -G") + self._running = 0 #@scrollable def description(self, widget):