2022-07-27 19:39:33 +01:00
|
|
|
import inspect
|
|
|
|
|
|
|
|
import keyboard
|
2024-01-07 11:21:01 +00:00
|
|
|
|
2022-09-04 12:20:40 +01:00
|
|
|
import obsws_python as obs
|
2022-07-27 19:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Observer:
|
2022-10-24 22:42:46 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._client = obs.EventClient()
|
|
|
|
self._client.callback.register(self.on_current_program_scene_changed)
|
|
|
|
print(f"Registered events: {self._client.callback.get()}")
|
2022-07-27 19:39:33 +01:00
|
|
|
|
2024-01-07 11:21:01 +00:00
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
|
|
|
self._client.disconnect()
|
|
|
|
|
2022-07-27 19:39:33 +01:00
|
|
|
@property
|
|
|
|
def event_identifier(self):
|
|
|
|
return inspect.stack()[1].function
|
|
|
|
|
|
|
|
def on_current_program_scene_changed(self, data):
|
|
|
|
"""The current program scene has changed."""
|
2022-07-27 22:44:40 +01:00
|
|
|
print(f"{self.event_identifier}: {data.scene_name}")
|
2022-07-27 19:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
def version():
|
2022-10-24 22:42:46 +01:00
|
|
|
resp = req_client.get_version()
|
2022-07-27 23:54:46 +01:00
|
|
|
print(
|
|
|
|
f"Running OBS version:{resp.obs_version} with websocket version:{resp.obs_web_socket_version}"
|
|
|
|
)
|
2022-07-27 19:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
def set_scene(scene, *args):
|
2022-10-24 22:42:46 +01:00
|
|
|
req_client.set_current_program_scene(scene)
|
2022-07-27 19:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-01-07 11:21:01 +00:00
|
|
|
with obs.ReqClient() as req_client:
|
|
|
|
with Observer() as observer:
|
|
|
|
keyboard.add_hotkey("0", version)
|
|
|
|
keyboard.add_hotkey("1", set_scene, args=("START",))
|
|
|
|
keyboard.add_hotkey("2", set_scene, args=("BRB",))
|
|
|
|
keyboard.add_hotkey("3", set_scene, args=("END",))
|
|
|
|
|
|
|
|
print("press ctrl+enter to quit")
|
|
|
|
keyboard.wait("ctrl+enter")
|