mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 12:50:53 +00:00
use context manager in scene_rotate
other refactors
This commit is contained in:
parent
27fd86efa5
commit
b8b446f9bf
@ -14,3 +14,5 @@ host = "localhost"
|
||||
port = 4455
|
||||
password = "mystrongpass"
|
||||
```
|
||||
|
||||
Closing OBS ends the script.
|
||||
|
@ -1,10 +1,12 @@
|
||||
import time
|
||||
|
||||
import obsws_python as obs
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, cl):
|
||||
self._cl = cl
|
||||
self._cl.callback.register(
|
||||
def __init__(self):
|
||||
self._client = obs.EventClient()
|
||||
self._client.callback.register(
|
||||
[
|
||||
self.on_current_program_scene_changed,
|
||||
self.on_scene_created,
|
||||
@ -12,7 +14,8 @@ class Observer:
|
||||
self.on_exit_started,
|
||||
]
|
||||
)
|
||||
print(f"Registered events: {self._cl.callback.get()}")
|
||||
print(f"Registered events: {self._client.callback.get()}")
|
||||
self.running = True
|
||||
|
||||
def on_current_program_scene_changed(self, data):
|
||||
"""The current program scene has changed."""
|
||||
@ -29,13 +32,12 @@ class Observer:
|
||||
def on_exit_started(self, _):
|
||||
"""OBS has begun the shutdown process."""
|
||||
print(f"OBS closing!")
|
||||
self._cl.unsubscribe()
|
||||
self._client.unsubscribe()
|
||||
self.running = False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cl = obs.EventClient()
|
||||
observer = Observer(cl)
|
||||
observer = Observer()
|
||||
|
||||
while cmd := input("<Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
while observer.running:
|
||||
time.sleep(0.1)
|
||||
|
@ -5,10 +5,10 @@ import obsws_python as obs
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, cl):
|
||||
self._cl = cl
|
||||
self._cl.callback.register(self.on_current_program_scene_changed)
|
||||
print(f"Registered events: {self._cl.callback.get()}")
|
||||
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()}")
|
||||
|
||||
@property
|
||||
def event_identifier(self):
|
||||
@ -20,20 +20,19 @@ class Observer:
|
||||
|
||||
|
||||
def version():
|
||||
resp = req_cl.get_version()
|
||||
resp = req_client.get_version()
|
||||
print(
|
||||
f"Running OBS version:{resp.obs_version} with websocket version:{resp.obs_web_socket_version}"
|
||||
)
|
||||
|
||||
|
||||
def set_scene(scene, *args):
|
||||
req_cl.set_current_program_scene(scene)
|
||||
req_client.set_current_program_scene(scene)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
req_cl = obs.ReqClient()
|
||||
ev_cl = obs.EventClient()
|
||||
observer = Observer(ev_cl)
|
||||
req_client = obs.ReqClient()
|
||||
observer = Observer()
|
||||
|
||||
keyboard.add_hotkey("0", version)
|
||||
keyboard.add_hotkey("1", set_scene, args=("START",))
|
||||
|
@ -4,16 +4,15 @@ import obsws_python as obs
|
||||
|
||||
|
||||
def main():
|
||||
resp = cl.get_scene_list()
|
||||
scenes = reversed(tuple(di.get("sceneName") for di in resp.scenes))
|
||||
with obs.ReqClient() as client:
|
||||
resp = client.get_scene_list()
|
||||
scenes = [di.get("sceneName") for di in reversed(resp.scenes)]
|
||||
|
||||
for scene in scenes:
|
||||
print(f"Switching to scene {scene}")
|
||||
cl.set_current_program_scene(scene)
|
||||
client.set_current_program_scene(scene)
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cl = obs.ReqClient()
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user