From 4fcaf9899b40e50120d52668070987ee089a0259 Mon Sep 17 00:00:00 2001 From: zoe Date: Sat, 19 Nov 2022 14:29:12 +0100 Subject: [PATCH] add play pause script to i3 --- i3/__pycache__/audiotools.cpython-311.pyc | Bin 0 -> 1119 bytes i3/audiotools.py | 50 ++++++++++++++++++++++ i3/config.nix | 2 +- i3/play_pause.py | 8 ++++ i3/volume.py | 28 +----------- 5 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 i3/__pycache__/audiotools.cpython-311.pyc create mode 100755 i3/audiotools.py create mode 100644 i3/play_pause.py diff --git a/i3/__pycache__/audiotools.cpython-311.pyc b/i3/__pycache__/audiotools.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dfe48d228437da171bde4b5fd434d7cdd8e5f18c GIT binary patch literal 1119 zcmb7E&1(};5PxqsAG@0-Zdy&WLD+s^yI_+;duT-z0v=STsXet9S+m=8OR_J#eM{SX zKo25C3VIOg&C)|uD)>Km@|cuB!$Lt61aDhvA@t;X(S#Oy&|&sB^V^-7otgc37Y<8+ z%B_R7>Bi#$su5|AUKKg6a-|O)zytqaV=z(4Mk2Sb+HCU$|(SsGZ z-iP#e=~A?1(axhjn2Q<+X1Azod+WTp5IZgH#(oV3op)G=;W^P z3t$zh(rk&Fz;1AIW_oI7a@rM(d2QXmS(0}HHqnSzF+gmB%7A4%^zdm!A|TK^^aH zZCkMrSvIYlLXct`hO%s6BbiL9epj-cr$vmihHbn43@RFy>&x8F+;e&CSZ*kb3I)e9 zvl=l}-sMakv$x3&S!neM8->=i*;W)qIUP?eqk@qtAtRN{B5TRar7Uv|*(q}}r8&BZ z2ts)~SzLEzdzt2+se$`x4c4{&gTe-ANs(7#T^!sH-|4a4Os`Al=CuckmTT*-L7tD0n=Cumz&^u6ltOoP!>?7%}^4{05qM^s4{> literal 0 HcmV?d00001 diff --git a/i3/audiotools.py b/i3/audiotools.py new file mode 100755 index 0000000..0d809be --- /dev/null +++ b/i3/audiotools.py @@ -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"] + ) diff --git a/i3/config.nix b/i3/config.nix index c686043..42bee2e 100644 --- a/i3/config.nix +++ b/i3/config.nix @@ -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"; }; }; diff --git a/i3/play_pause.py b/i3/play_pause.py new file mode 100644 index 0000000..4e047c4 --- /dev/null +++ b/i3/play_pause.py @@ -0,0 +1,8 @@ +import subprocess +import audiotools + +try: + subprocess.Popen(["playerctl", "play-pause"]).wait() + audiotools.show_now_playing() +except: + pass diff --git a/i3/volume.py b/i3/volume.py index d958d82..b2eba27 100644 --- a/i3/volume.py +++ b/i3/volume.py @@ -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())