forked from kunsi/dotfiles
add .bin/pulseaudio-assert-volume
This commit is contained in:
parent
a4112d4226
commit
d4400473a0
3 changed files with 54 additions and 12 deletions
48
.bin/pulseaudio-assert-volume
Executable file
48
.bin/pulseaudio-assert-volume
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from subprocess import check_output, CalledProcessError
|
||||||
|
from re import findall
|
||||||
|
from signal import signal, SIGTERM
|
||||||
|
from sys import exit
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def handle_signal(_signo, _stack_frame):
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
signal(SIGTERM, handle_signal)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
print('Startup')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
for line in check_output(['pactl', 'list', 'sink-inputs']).decode().splitlines():
|
||||||
|
line = line.strip().lower()
|
||||||
|
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith('sink input #'):
|
||||||
|
sink_id = line[len('sink input #'):]
|
||||||
|
needs_adjusting = False
|
||||||
|
|
||||||
|
if line.startswith('volume:'):
|
||||||
|
for speaker, absolute, percent in findall('([a-z-]+):\W+([0-9]+)\W+\/\W+([0-9]+)%', line):
|
||||||
|
if int(percent) < 100:
|
||||||
|
print(f' sink {sink_id} speaker {speaker} at {percent} % volume')
|
||||||
|
needs_adjusting = True
|
||||||
|
|
||||||
|
if needs_adjusting:
|
||||||
|
check_output(['pactl', 'set-sink-input-volume', sink_id, '100%'])
|
||||||
|
print(f' adjusted sink {sink_id} to 100%')
|
||||||
|
|
||||||
|
needs_adjusting = False
|
||||||
|
|
||||||
|
except CalledProcessError as e:
|
||||||
|
print(repr(e))
|
||||||
|
|
||||||
|
sleep(0.5)
|
||||||
|
finally:
|
||||||
|
print('Shutdown')
|
|
@ -2,4 +2,9 @@
|
||||||
Description=pulseaudio sickofit
|
Description=pulseaudio sickofit
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/bash -c "pactl list sink-inputs | grep -F 'Sink Input #' | cut -d# -f2 | while read id; do pactl set-sink-input-volume $id 100%; done"
|
ExecStart=/home/kunsi/.bin/pulseaudio-assert-volume
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=pulseaudio sickofit
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
Persistent=False
|
|
||||||
OnUnitActiveSec=1s
|
|
||||||
OnUnitInctiveSec=1s
|
|
||||||
AccuracySec=1ms
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=timers.target
|
|
Loading…
Reference in a new issue