bumblebee-status/modules/contrib/mocp.py

55 lines
1.7 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:
%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
"""
2020-04-19 14:37:16 +02:00
import core.module
import core.widget
import core.input
import util.cli
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')
self.__running = False
2020-04-19 14:33:31 +02:00
def description(self, widget):
2020-04-19 14:37:16 +02:00
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
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4