nixos-config/modules/workspace/i3blocks/scripts/music.nix
2020-07-28 13:38:08 +03:00

19 lines
756 B
Nix

{ python3, playerctl, iconfont, ...}: ''
#!${python3}/bin/python
from subprocess import getoutput, call
from os import environ
status = getoutput("${playerctl}/bin/playerctl status")
if "BLOCK_BUTTON" in environ:
BLOCK_BUTTON = environ["BLOCK_BUTTON"]
if BLOCK_BUTTON == "1": call(["${playerctl}/bin/playerctl", "play-pause"])
if BLOCK_BUTTON == "2": call(["${playerctl}/bin/playerctl", "stop"])
if BLOCK_BUTTON == "3": call(["${playerctl}/bin/playerctl", "next"])
if status == "Paused" or status == "Playing":
text = getoutput("${playerctl}/bin/playerctl metadata title")[:20:]
icon = ""
else:
text = ""
icon = ""
print("<span font='${iconfont}'>%s</span> %s" % (icon, text.replace('&', '&amp;')))
''