nixos-old/i3/audiotools.py

59 lines
1.5 KiB
Python
Executable File

import subprocess
def show_now_playing():
id = ["-r", "3984938"]
try:
status = subprocess.Popen(
["playerctl", "status"],
stdout=subprocess.PIPE,
)
now_playing = subprocess.Popen(
[
"playerctl",
"metadata",
"--format",
"{artist}\n\n{title}".format(
artist="🧑‍🎨 {{artist}}",
title="🎵 {{title}}",
),
],
stdout=subprocess.PIPE,
)
subprocess.run(
[
"dunstify",
"{}".format(status.communicate()[0].decode()),
now_playing.communicate()[0],
]
+ id
)
except:
subprocess.run(["dunstify", "", "🦗 nothing to see here..."] + id)
def get_amixer_volume() -> int:
s: str = str(subprocess.check_output(["amixer", "get", "Master"]))
try:
# turns the front left argument into an int
return int(
# the thing we're looking for is in the fifth line
s.split(r"\n")[5]
.strip()
# and is the 4th word
.split(" ")[4]
.replace("[", "")
.replace("]", "")
.replace("%", "")
)
except:
return -1
def display_volume(volume: int):
subprocess.call(
["dunstify", "volume 蓼", "-h", "int:value:" + str(volume), "-r", "39489384"]
)