From 56524ce54bf9125374180757bb19c67254b6a0d7 Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Mon, 7 Nov 2016 22:14:46 +0100 Subject: [PATCH] Add Cmus player module --- bumblebee/modules/cmus.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bumblebee/modules/cmus.py diff --git a/bumblebee/modules/cmus.py b/bumblebee/modules/cmus.py new file mode 100644 index 0000000..dc2b70f --- /dev/null +++ b/bumblebee/modules/cmus.py @@ -0,0 +1,46 @@ +import datetime +import bumblebee.module +import subprocess + +def description(): + return "Displays the current song and artist playing in cmus" + +class Module(bumblebee.module.Module): + def __init__(self, output, config, alias): + super(Module, self).__init__(output, config, alias) + self._title = "None" + self._artist = "None" + self._status = 0 + + def widgets(self): + self._process = subprocess.Popen(["cmus-remote", "-Q"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self._query, self._error = self._process.communicate() + self._query = self._query.decode("utf-8").split("\n") + if b'cmus is not running' in self._error: + return bumblebee.output.Widget(self, "Cmus isn't running") + for line in self._query: + if "status playing" in line: + self._status = 1 + if "status paused" in line: + self._status = 2 + if "status stopped" in line: + self._status = 3 + else: + if "tag title" in line: + self._title = line[10:] + if "tag artist" in line: + self._artist = line[11:] + + return bumblebee.output.Widget(self, "{} - {}".format( + self._artist, + self._title) + ) + def state(self, widget): + if self._status == 1: + return "playing" + if self._status == 2: + return "paused" + if self._status == 3: + return "stopped" + return "default" +