mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 21:00:53 +00:00
1db3b2db4d
fixes bug with ExitStarted event. remove redundant assignment in conn_from_toml add explicit call to ws.close() in unsubscribe() patch bump
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import obsws_python as obs
|
|
|
|
|
|
class Observer:
|
|
def __init__(self, cl):
|
|
self._cl = cl
|
|
self._cl.callback.register(
|
|
[
|
|
self.on_current_program_scene_changed,
|
|
self.on_scene_created,
|
|
self.on_input_mute_state_changed,
|
|
self.on_exit_started,
|
|
]
|
|
)
|
|
print(f"Registered events: {self._cl.callback.get()}")
|
|
|
|
def on_current_program_scene_changed(self, data):
|
|
"""The current program scene has changed."""
|
|
print(f"Switched to scene {data.scene_name}")
|
|
|
|
def on_scene_created(self, data):
|
|
"""A new scene has been created."""
|
|
print(f"scene {data.scene_name} has been created")
|
|
|
|
def on_input_mute_state_changed(self, data):
|
|
"""An input's mute state has changed."""
|
|
print(f"{data.input_name} mute toggled")
|
|
|
|
def on_exit_started(self, _):
|
|
"""OBS has begun the shutdown process."""
|
|
print(f"OBS closing!")
|
|
self._cl.unsubscribe()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
cl = obs.EventClient()
|
|
observer = Observer(cl)
|
|
|
|
while cmd := input("<Enter> to exit\n"):
|
|
if not cmd:
|
|
break
|