Skip to content

Instantly share code, notes, and snippets.

@onyx-and-iris
Last active December 7, 2022 17:50
Show Gist options
  • Save onyx-and-iris/4b824ee93ac9dbbd701e069ee133b306 to your computer and use it in GitHub Desktop.
Save onyx-and-iris/4b824ee93ac9dbbd701e069ee133b306 to your computer and use it in GitHub Desktop.
toggles record state and prints event notifications
import time
import obsws_python as obs
def on_record_state_changed(data):
"""The state of the record output has changed."""
print(f"Current record state: {data.output_state}")
if data.output_state == "OBS_WEBSOCKET_OUTPUT_STARTED":
print(f"Output Path: {data.output_path}")
def main():
client_e = obs.EventClient()
client_e.callback.register(on_record_state_changed)
with obs.ReqClient() as client_r:
client_r.start_record()
time.sleep(3)
client_r.stop_record()
if __name__ == "__main__":
main()
@onyx-and-iris
Copy link
Author

Requires the obsws-python package which can be found at https://github.com/aatikturk/obsws-python

This example assumes existence of config file.

example config.toml:

[connection]
host = "localhost"
port = 4455
password = "mystrongpass"

config.toml should be placed next to your __main__.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment