obs-websocket-tally/scene_is_currently_visible

73 lines
1.7 KiB
Text
Raw Normal View History

2021-12-05 07:46:41 +00:00
#!/usr/bin/env python3
from sys import argv
import logging
import time
from obswebsocket import events, obsws
logging.basicConfig(
format="%(asctime)s %(name)s [%(levelname)s] %(message)s",
level=logging.INFO,
)
log = logging.getLogger(__name__)
host = "localhost"
port = 4444
password = "12345"
my_source_name = argv[1]
my_source_is_program = False
my_source_is_preview = False
def on_event(message):
global my_source_is_program, my_source_is_preview
my_source_in_current_event = False
if isinstance(message, events.SwitchScenes):
visibility = "PROGRAM"
elif isinstance(message, events.PreviewSceneChanged):
visibility = "PREVIEW"
else:
return
for source in message.datain["sources"]:
log.debug(f'visibility of scene {message.datain["scene-name"]} changed, {source["name"]} is now {visibility}')
if source["name"] == my_source_name:
my_source_in_current_event = True
if my_source_in_current_event:
if visibility == "PROGRAM":
my_source_is_program = True
else:
my_source_is_preview = True
else:
if visibility == "PROGRAM":
my_source_is_program = False
else:
my_source_is_preview = False
if my_source_is_program:
log.info(f"{my_source_name} is PROGRAM (and maybe preview)")
elif my_source_is_preview:
log.info(f"{my_source_name} is PREVIEW only")
else:
log.info(f"{my_source_name} is not visible")
ws = obsws(host, port, password)
ws.register(on_event)
ws.connect()
try:
log.info("Waiting ...")
time.sleep(3600)
log.warn("Timeout!")
except KeyboardInterrupt:
pass
ws.disconnect()