2022-07-27 19:39:33 +01:00
|
|
|
import inspect
|
|
|
|
|
|
|
|
import keyboard
|
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
|
|
|
|
|
|
|
@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__":
|
2022-10-24 22:42:46 +01:00
|
|
|
req_client = obs.ReqClient()
|
|
|
|
observer = Observer()
|
2022-07-27 19:39:33 +01:00
|
|
|
|
2022-07-27 23:54:46 +01:00
|
|
|
keyboard.add_hotkey("0", version)
|
2022-07-27 19:39:33 +01:00
|
|
|
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")
|