Add mpris support
This commit is contained in:
parent
f011b376bb
commit
86f9f75bd7
6 changed files with 126 additions and 21 deletions
|
@ -25,7 +25,7 @@ pkgs.python3Packages.buildPythonApplication {
|
|||
pulsectl
|
||||
pyinotify
|
||||
];
|
||||
makeWrapperArgs = [ "--prefix PATH : ${pkgs.lib.makeBinPath ([ lemonbar ] ++ (with pkgs; [ wirelesstools ]))}" ];
|
||||
makeWrapperArgs = [ "--prefix PATH : ${pkgs.lib.makeBinPath ([ lemonbar ] ++ (with pkgs; [ wirelesstools playerctl ]))}" ];
|
||||
|
||||
src = ./.;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@ def run() -> None:
|
|||
)
|
||||
|
||||
# TODO Middle
|
||||
Bar.addSectionAll(fp.MpdProvider(theme=9), BarGroupType.LEFT)
|
||||
Bar.addSectionAll(fp.MprisProvider(theme=9), BarGroupType.LEFT)
|
||||
# Bar.addSectionAll(fp.MpdProvider(theme=9), BarGroupType.LEFT)
|
||||
# Bar.addSectionAll(I3WindowTitleProvider(), BarGroupType.LEFT)
|
||||
|
||||
# TODO Computer modes
|
||||
|
|
|
@ -849,3 +849,96 @@ class MpdProvider(Section, ThreadedUpdater):
|
|||
self.connect()
|
||||
except BaseException as e:
|
||||
log.error(e, exc_info=True)
|
||||
|
||||
|
||||
class MprisProviderSection(Section, Updater):
|
||||
def __init__(self, parent: "MprisProvider"):
|
||||
Updater.__init__(self)
|
||||
Section.__init__(self, theme=parent.theme)
|
||||
self.parent = parent
|
||||
|
||||
|
||||
class MprisProvider(Section, ThreadedUpdater):
|
||||
# TODO Controls (select player at least)
|
||||
# TODO Use the Python native thing for it:
|
||||
# https://github.com/altdesktop/playerctl?tab=readme-ov-file#using-the-library
|
||||
# TODO Make it less sucky
|
||||
|
||||
SECTIONS = [
|
||||
"{{ playerName }} {{ status }}",
|
||||
"{{ album }}",
|
||||
"{{ artist }}",
|
||||
"{{ duration(position) }}|{{ duration(mpris:length) }}"
|
||||
" {{ title }}",
|
||||
]
|
||||
|
||||
# nf-fd icons don't work (UTF-16?)
|
||||
SUBSTITUTIONS = {
|
||||
"Playing": "",
|
||||
"Paused": "",
|
||||
"Stopped": "",
|
||||
"mpd": "",
|
||||
"firefox": "",
|
||||
"chromium": "",
|
||||
"mpv": "",
|
||||
}
|
||||
|
||||
ICONS = {
|
||||
1: "",
|
||||
2: "",
|
||||
3: "",
|
||||
}
|
||||
|
||||
def __init__(self, theme: int | None = None):
|
||||
ThreadedUpdater.__init__(self)
|
||||
Section.__init__(self, theme)
|
||||
|
||||
self.line = ""
|
||||
self.start()
|
||||
|
||||
self.sections: list[Section] = []
|
||||
|
||||
def fetcher(self) -> Element:
|
||||
create = not len(self.sections)
|
||||
populate = self.line
|
||||
split = self.line.split("\t")
|
||||
|
||||
lastSection: Section = self
|
||||
for i in range(len(self.SECTIONS)):
|
||||
if create:
|
||||
section = Section(theme=self.theme)
|
||||
lastSection.appendAfter(section)
|
||||
lastSection = section
|
||||
self.sections.append(section)
|
||||
else:
|
||||
section = self.sections[i]
|
||||
|
||||
if populate:
|
||||
text = split[i]
|
||||
if i == 0:
|
||||
for key, val in self.SUBSTITUTIONS.items():
|
||||
text = text.replace(key, val)
|
||||
if text:
|
||||
if i in self.ICONS:
|
||||
text = f"{self.ICONS[i]} {text}"
|
||||
section.updateText(text)
|
||||
else:
|
||||
section.updateText(None)
|
||||
else:
|
||||
section.updateText(None)
|
||||
|
||||
return None
|
||||
|
||||
def loop(self) -> None:
|
||||
cmd = [
|
||||
"playerctl",
|
||||
"metadata",
|
||||
"--format",
|
||||
"\t".join(self.SECTIONS),
|
||||
"--follow",
|
||||
]
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
assert p.stdout
|
||||
while p.poll() is None:
|
||||
self.line = p.stdout.readline().decode().strip()
|
||||
self.refreshData()
|
||||
|
|
|
@ -4,6 +4,7 @@ import functools
|
|||
import logging
|
||||
import math
|
||||
import os
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
@ -11,8 +12,8 @@ import coloredlogs
|
|||
import i3ipc
|
||||
import pyinotify
|
||||
|
||||
from frobar.display import Element
|
||||
from frobar.common import notBusy
|
||||
from frobar.display import Element
|
||||
|
||||
coloredlogs.install(level="DEBUG", fmt="%(levelname)s %(message)s")
|
||||
log = logging.getLogger()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue