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')
|
Loading…
Add table
Add a link
Reference in a new issue