2022-10-24 22:42:46 +01:00
|
|
|
import time
|
|
|
|
|
2022-09-04 12:20:40 +01:00
|
|
|
import obsws_python as obs
|
2022-07-25 23:51:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Observer:
|
2022-10-24 22:42:46 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._client = obs.EventClient()
|
|
|
|
self._client.callback.register(
|
2022-07-26 04:36:55 +01:00
|
|
|
[
|
|
|
|
self.on_current_program_scene_changed,
|
|
|
|
self.on_scene_created,
|
|
|
|
self.on_input_mute_state_changed,
|
|
|
|
self.on_exit_started,
|
|
|
|
]
|
2022-07-25 23:51:30 +01:00
|
|
|
)
|
2022-10-24 22:42:46 +01:00
|
|
|
print(f"Registered events: {self._client.callback.get()}")
|
|
|
|
self.running = True
|
2022-07-25 23:51:30 +01:00
|
|
|
|
2022-07-26 04:36:55 +01:00
|
|
|
def on_current_program_scene_changed(self, data):
|
2022-07-26 21:47:41 +01:00
|
|
|
"""The current program scene has changed."""
|
2022-07-27 22:44:40 +01:00
|
|
|
print(f"Switched to scene {data.scene_name}")
|
2022-07-26 04:36:55 +01:00
|
|
|
|
2022-07-26 21:47:41 +01:00
|
|
|
def on_scene_created(self, data):
|
2022-07-26 04:36:55 +01:00
|
|
|
"""A new scene has been created."""
|
2022-07-27 22:44:40 +01:00
|
|
|
print(f"scene {data.scene_name} has been created")
|
2022-07-26 04:36:55 +01:00
|
|
|
|
2022-07-26 21:47:41 +01:00
|
|
|
def on_input_mute_state_changed(self, data):
|
2022-07-26 04:36:55 +01:00
|
|
|
"""An input's mute state has changed."""
|
2022-07-27 22:44:40 +01:00
|
|
|
print(f"{data.input_name} mute toggled")
|
2022-07-26 04:36:55 +01:00
|
|
|
|
2022-09-26 10:58:02 +01:00
|
|
|
def on_exit_started(self, _):
|
2022-07-26 21:47:41 +01:00
|
|
|
"""OBS has begun the shutdown process."""
|
2022-07-25 23:51:30 +01:00
|
|
|
print(f"OBS closing!")
|
2022-10-24 22:42:46 +01:00
|
|
|
self._client.unsubscribe()
|
|
|
|
self.running = False
|
2022-07-25 23:51:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-10-24 22:42:46 +01:00
|
|
|
observer = Observer()
|
2022-07-25 23:51:30 +01:00
|
|
|
|
2022-10-24 22:42:46 +01:00
|
|
|
while observer.running:
|
|
|
|
time.sleep(0.1)
|