This repository was archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_stream.py
More file actions
executable file
·108 lines (66 loc) · 3.13 KB
/
switch_stream.py
File metadata and controls
executable file
·108 lines (66 loc) · 3.13 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
import pulsectl
import argparse
pulse = pulsectl.Pulse()
def get_sink_indexes():
sink_indexes = []
for sink in pulse.sink_list():
sink_indexes.append(str(sink.index))
return sink_indexes
def get_default_sink():
return pulse.get_sink_by_name(pulse.server_info().default_sink_name)
def sink_toggle(indexes):
# Iterate through the index arguments given by the user
# and switch to the first non-default sink
for index in indexes:
index = index.strip()
default_index = int(pulse.get_sink_by_name(pulse.server_info().default_sink_name).index)
default_sink = get_default_sink()
default_sink.mute = True
#current_volume = default_sink.volume
#current_volume.value_flat = 0.0
#pulse.volume_set(default_sink, current_volume)
#pulse.sink_input_volume_set(default_sink, current_volume)
if int(index) != default_index:
# Set the new default and mute the old sink
pulse.sink_default_set(index)
pulse.mute(default_sink, True)
# Unmute the new sink
new_sink = pulse.get_sink_by_name(pulse.server_info().default_sink_name)
pulse.mute(new_sink, False)
print('the default sink has been set to index: %s, name: %s' % (index, get_default_sink().name))
break
def move_streams():
count = 0
streams = pulse.sink_input_list()
default_sink = get_default_sink()
for stream in streams:
#print('moved stream: %s to the default sink' % (stream.name))
#pulse.sink_input_move(stream.index, default_index)
print('STREAM', stream)
pulse.sink_input_move(stream.index, get_default_sink().index)
count += 1
print('moved %s streams' % (count))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--manual-sink-toggle', action='store', nargs='+', type=str, help='example: --manual-sink-toggle 0 2', metavar='[sink index]')
parser.add_argument('--move-streams', action='store_true', help='this will move all streams to the new default sink')
parser.add_argument('--auto', action='store_true', help='automatically move all streams to the next sink')
parser.add_argument('--show-short', action='store_true', help='just print the current sink (shortened)')
args = parser.parse_args()
sinks = pulse.sink_list()
if not args.auto and not args.manual_sink_toggle and not args.move_streams and not args.show_short:
print('No arguments specified')
exit()
if args.show_short:
print(get_default_sink().description.split(' ')[0])
exit()
# If they give no arguments, or only --auto
if args.auto == True:
sink_toggle(get_sink_indexes())
# They manually specified the sinks to toggle between
elif args.manual_sink_toggle:
sink_toggle(args.manual_sink_toggle)
# Take all the streams and move them to the (new) default sink.
if args.move_streams:
move_streams()