Add/update one to many links for link-virtual-mic

This commit is contained in:
Sheldon Lee 2023-11-28 14:59:53 +08:00
parent 5f468b232b
commit 09edab32fa

View File

@ -4,13 +4,14 @@ import subprocess
import time import time
mappingMic = { mappingMic = {
"output\\.rnnoise_source:capture_1": "mixed-mic:input_FL", # "output\\.rnnoise_source:capture_1": ["mixed-mic:input_FL"],
"output\\.rnnoise_source:capture_2": "mixed-mic:input_FR" # "output\\.rnnoise_source:capture_2": ["mixed-mic:input_FR"]
"rnnoise_source:capture_1": ["mixed-mic:input_FL", "mixed-mic:input_FR"],
} }
mappingLoopback = { mappingLoopback = {
"loopback:monitor_FL": "mixed-mic:input_FL", "loopback:monitor_FL": ["mixed-mic:input_FL"],
"loopback:monitor_FR": "mixed-mic:input_FR" "loopback:monitor_FR": ["mixed-mic:input_FR"]
} }
@ -49,27 +50,30 @@ def main():
def manageLinks(mapping, disconnect=False): def manageLinks(mapping, disconnect=False):
for key, value in mapping.items(): for iter_out, iter_inputs in mapping.items():
cmdOpts = {"shell": True, "capture_output": True, "text": True} cmdOpts = {"shell": True, "capture_output": True, "text": True}
cmd = "pw-link -o | grep -e '{}'".format(key) cmd = "pw-link -o | grep -e '{}'".format(iter_out)
completedProcess = subprocess.run(cmd, **cmdOpts) completedProcess = subprocess.run(cmd, **cmdOpts)
if completedProcess.returncode == 1: if completedProcess.returncode == 1:
print(f"Output `{iter_out}` not found")
return False return False
output = completedProcess.stdout.split('\n')[0] output = completedProcess.stdout.split('\n')[0]
cmd = "pw-link -i | grep -e '{}'".format(value) for iter_input in iter_inputs:
completedProcess = subprocess.run(cmd, **cmdOpts) cmd = "pw-link -i | grep -e '{}'".format(iter_input)
if completedProcess.returncode == 1: completedProcess = subprocess.run(cmd, **cmdOpts)
return False if completedProcess.returncode == 1:
input = completedProcess.stdout.split('\n')[0] print(f"Output `{iter_input}` not found")
return False
input = completedProcess.stdout.split('\n')[0]
if disconnect: if disconnect:
cmd = ["pw-link", "-d", output, input] cmd = ["pw-link", "-d", output, input]
else: else:
cmd = ["pw-link", output, input] cmd = ["pw-link", output, input]
print(' '.join(cmd)) print(' '.join(cmd))
subprocess.run(cmd, capture_output=True) subprocess.run(cmd, capture_output=True)
return True return True