-
Notifications
You must be signed in to change notification settings - Fork 0
/
conference_switcher.py
58 lines (53 loc) · 2.29 KB
/
conference_switcher.py
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
from os import path
from argparse import ArgumentParser
from json import load
from time import monotonic
from obswebsocket import obsws, requests
from obswebsocket.exceptions import ConnectionFailure
from websocket._exceptions import WebSocketConnectionClosedException
from random import random, choices
from time import sleep
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('creds', nargs='?', help="Optional path to creditentials",
default=f"{path.dirname(__file__)}/creditentials.json")
args = parser.parse_args()
UPDATE_INTERVAL: float = 0.5 # stepsize in seconds
CHECK_INTERVAL: float = 3 # time before check if scene is in list
# init scenes to work with
# list of solo fullscreen scenes
SCENE_SPEAK: list[str] = ['Main_Tharos', 'Main_Byow']
SCENE_PROBAS: list[int] = [66, 33]
# Loading creditentials for OBSwebsocket
print("Loading creditentials...")
with open(args.creds, 'r') as creds:
creditentials: dict = load(creds)
ws = obsws(creditentials["host"],
creditentials["port"], creditentials["password"])
delay, future_delay = monotonic(), 2
try:
print("Connecting to OBS...")
ws.connect()
timer: float = 0.0
print("Starting main loop!")
while(True):
if ws.call(requests.GetCurrentScene()).getName() in SCENE_SPEAK:
if random() < 0.08 and timer > 8.0:
ws.call(requests.SetCurrentScene(
choices(SCENE_SPEAK, weights=SCENE_PROBAS, k=1)[0]))
timer = 0 # reset timer for scene switch
else:
sleep(UPDATE_INTERVAL)
timer += UPDATE_INTERVAL
else:
sleep(CHECK_INTERVAL)
timer = 0
except KeyboardInterrupt:
ws.disconnect()
print("Connexion closed!")
except ConnectionFailure:
print("Could not connect to OBS ; please check creditentials file and if OBS is up and running.")
except WebSocketConnectionClosedException:
print("Connexion to OBS was prematurely closed ; aborting...")
except ConnectionRefusedError:
print("OBS refused connexion to the switcher.")