bumblebee-status/modules/contrib/gpmdp.py

57 lines
1.7 KiB
Python
Raw Normal View History

2020-04-19 10:14:34 +02:00
# pylint: disable=C0111,R0903
"""Displays information about the current song in Google Play music player.
Requires the following executable:
* gpmdp-remote
"""
import bumblebee.util
import bumblebee.input
import bumblebee.output
import bumblebee.engine
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
widgets = [
2020-04-19 10:14:56 +02:00
bumblebee.output.Widget(name='gpmdp.prev'),
bumblebee.output.Widget(name='gpmdp.main', full_text=self.description),
bumblebee.output.Widget(name='gpmdp.next'),
2020-04-19 10:14:34 +02:00
]
super(Module, self).__init__(engine, config, widgets)
engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE,
2020-04-19 10:14:56 +02:00
cmd='playerctl previous')
2020-04-19 10:14:34 +02:00
engine.input.register_callback(widgets[1], button=bumblebee.input.LEFT_MOUSE,
2020-04-19 10:14:56 +02:00
cmd='playerctl play-pause')
2020-04-19 10:14:34 +02:00
engine.input.register_callback(widgets[2], button=bumblebee.input.LEFT_MOUSE,
2020-04-19 10:14:56 +02:00
cmd='playerctl next')
2020-04-19 10:14:34 +02:00
self._status = None
self._tags = None
def description(self, widget):
2020-04-19 10:14:56 +02:00
return self._tags if self._tags else 'n/a'
2020-04-19 10:14:34 +02:00
def update(self, widgets):
self._load_song()
def state(self, widget):
2020-04-19 10:14:56 +02:00
if widget.name == 'gpmdp.prev':
return 'prev'
if widget.name == 'gpmdp.next':
return 'next'
2020-04-19 10:14:34 +02:00
return self._status
def _load_song(self):
2020-04-19 10:14:56 +02:00
info = ''
2020-04-19 10:14:34 +02:00
try:
2020-04-19 10:14:56 +02:00
info = bumblebee.util.execute('gpmdp-remote current')
status = bumblebee.util.execute('gpmdp-remote status')
2020-04-19 10:14:34 +02:00
except RuntimeError:
pass
2020-04-19 10:14:56 +02:00
self._status = status.split('\n')[0].lower()
self._tags = info.split('\n')[0]
2020-04-19 10:14:34 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4