-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.py
More file actions
executable file
·61 lines (49 loc) · 1.64 KB
/
Copy pathaudio.py
File metadata and controls
executable file
·61 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/env python3
import subprocess as sp
import json
import sys
list_sinks = ['pactl', '-f', 'json', 'list', 'sinks', 'short']
sink_inputs = ['pactl', '-f', 'json', 'list', 'sink-inputs']
FZF = ['fzf', '--reverse', '--prompt', 'Select Device']
def list_dev():
lister = sp.Popen(list_sinks, stdout=sp.PIPE, stderr=sp.PIPE, text=True)
output, err = lister.communicate()
if lister.returncode != 0:
print(f"Error: {err},\nexiting")
sys.exit(1)
else:
dev_list = json.loads(output)
dev_name = [item['name'] for item in dev_list]
return dev_name
def fzf(list):
if list is None:
return
else:
input = '\n'.join(list)
fzf_command = sp.Popen(FZF, stdin=sp.PIPE, text=True)
fzf_command.stdin.write(''.join(input.strip()))
fzf_command.stdin.close()
return_code = fzf_command.wait()
if return_code != 0:
print(f"Error:{return_code}")
sys.exit(1)
else:
return fzf_command.stdout
# device_list = list_dev()
# fzf(device_list)
# jq '.[]|.properties."media.name"'
def list_sink_inputs():
sinks = sp.Popen(sink_inputs, stdin=sp.PIPE,
stdout=sp.PIPE, stderr=sp.PIPE, text=True)
output, err = sinks.communicate()
if sinks.returncode != 0:
print(f"Error: {err}")
else:
sink_output = json.loads(output)
list = [item['properties']['media.name'] for item in sink_output]
index = [item['index'] for item in sink_output]
for name in list:
print(f"{name}")
for idx in index:
print(f"\t{idx}")
list_sink_inputs()