bumblebee-status/bumblebee_status/modules/contrib/mocp.py

60 lines
1.8 KiB
Python
Raw Normal View History

2020-04-19 14:33:31 +02:00
# pylint: disable=C0111,R0903
# -*- coding: utf-8 -*-
"""Displays information about the current song in mocp. Left click toggles play/pause. Right click toggles shuffle.
Requires the following executable:
* mocp
Parameters:
* mocp.format: Format string for the song information. Replace string sequences with the actual information:
2020-05-06 12:57:38 +02:00
* %state State
* %file File
* %title Title, includes track, artist, song title and album
* %artist Artist
* %song SongTitle
* %album Album
* %tt TotalTime
* %tl TimeLeft
* %ts TotalSec
* %ct CurrentTime
* %cs CurrentSec
* %b Bitrate
* %r Sample rate
contributed by `chrugi <https://github.com/chrugi>`_ - many thanks!
2020-04-19 14:33:31 +02:00
"""
2020-04-19 14:37:16 +02:00
import core.module
import core.widget
import core.input
import util.cli
2020-04-19 14:37:16 +02:00
class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.description))
2020-04-19 14:37:16 +02:00
core.input.register(self, button=core.input.LEFT_MOUSE, cmd="mocp -G")
core.input.register(self, button=core.input.RIGHT_MOUSE, cmd="mocp -t shuffle")
self.__format = self.parameter("format", "%state %artist - %song | %ct/%tt")
2020-04-19 14:37:16 +02:00
self.__running = False
2020-04-19 14:33:31 +02:00
def description(self, widget):
return self.__info if self.__running == True else "Music On Console Player"
2020-04-19 14:33:31 +02:00
2020-04-19 14:37:16 +02:00
def update(self):
self.__load_song()
2020-04-19 14:33:31 +02:00
2020-04-19 14:37:16 +02:00
def __load_song(self):
2020-04-19 14:33:31 +02:00
try:
2020-04-19 14:37:16 +02:00
self.__info = util.cli.execute("mocp -Q '{}'".format(self.__format)).strip()
self.__running = True
2020-04-19 14:33:31 +02:00
except RuntimeError:
2020-04-19 14:37:16 +02:00
self.__running = False
2020-04-19 14:33:31 +02:00
2020-04-19 14:33:31 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4