add play pause script to i3

This commit is contained in:
zoe 2022-11-19 14:29:12 +01:00
parent a3fb4b29dc
commit 4fcaf9899b
5 changed files with 61 additions and 27 deletions

Binary file not shown.

50
i3/audiotools.py Executable file
View File

@ -0,0 +1,50 @@
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}} | {{title}}"],
stdout=subprocess.PIPE,
)
subprocess.run(
[
"dunstify",
status.communicate()[0],
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"]
)

View File

@ -111,7 +111,7 @@ in
m = "exec --no-startup-id amixer set Master toggle";
c = "exec --no-startup-id kitty cmus";
v = "exec --no-startup-id mpv";
Space = "exec playerctl play-pause";
space = "exec python3 /etc/nixos/i3/play_pause.py";
};
};

8
i3/play_pause.py Normal file
View File

@ -0,0 +1,8 @@
import subprocess
import audiotools
try:
subprocess.Popen(["playerctl", "play-pause"]).wait()
audiotools.show_now_playing()
except:
pass

View File

@ -1,35 +1,11 @@
# script that changes the volume and then shows a notfication with it using dunst
import subprocess
import argparse
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"]
)
import audiotools
parser = argparse.ArgumentParser()
parser.add_argument("volchange")
args = parser.parse_args()
subprocess.check_output(["amixer", "set", "Master", args.volchange])
display_volume(get_amixer_volume())
audiotools.display_volume(audiotools.get_amixer_volume())