From ca9a31c94a3195b1db408b7dc87a13d51878e564 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 25 Jun 2023 14:49:07 +0100 Subject: [PATCH] example now registeres on_exit_started script will now end when OBS is closed filter out all logs but `vban_cmd.iremote` setup.py added --- examples/obs/README.md | 4 +++- examples/obs/__main__.py | 48 +++++++++++++++++++++++++++++++--------- examples/obs/setup.py | 7 ++++++ 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 examples/obs/setup.py diff --git a/examples/obs/README.md b/examples/obs/README.md index a3b7bbe..8dfb4e0 100644 --- a/examples/obs/README.md +++ b/examples/obs/README.md @@ -40,10 +40,12 @@ Make sure you have established a working connection to OBS and the remote Voicem Run the script, change OBS scenes and watch Voicemeeter parameters change. -Pressing `` will exit. +Closing OBS will end the script. ## Notes +All but `vban_cmd.iremote` logs are filtered out. Log in DEBUG mode. + This script can be run from a Linux host since the vban-cmd interface relies on UDP packets and obsws-python runs over websockets. You could for example, set this up to run in the background on a home server such as a Raspberry Pi. diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py index 4eede23..959dfdb 100644 --- a/examples/obs/__main__.py +++ b/examples/obs/__main__.py @@ -1,16 +1,41 @@ -import logging +import time +from logging import config + +import obsws_python as obsws -import obsws_python as obs import vban_cmd -logging.basicConfig(level=logging.INFO) +config.dictConfig( + { + "version": 1, + "formatters": { + "standard": { + "format": "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s" + } + }, + "handlers": { + "stream": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "standard", + } + }, + "loggers": {"vban_cmd.iremote": {"handlers": ["stream"], "level": "DEBUG"}}, + } +) class Observer: def __init__(self, vban): self.vban = vban - self.client = obs.EventClient() - self.client.callback.register(self.on_current_program_scene_changed) + self.client = obsws.EventClient() + self.client.callback.register( + ( + self.on_current_program_scene_changed, + self.on_exit_started, + ) + ) + self.is_running = True def on_start(self): self.vban.strip[0].mute = True @@ -50,13 +75,16 @@ class Observer: if fn := fget(scene): fn() + def on_exit_started(self, _): + self.client.unsubscribe() + self.is_running = False + def main(): - with vban_cmd.api("potato", sync=True) as vban: - obs = Observer(vban) - while cmd := input(" to exit\n"): - if not cmd: - break + with vban_cmd.api("potato") as vban: + observer = Observer(vban) + while observer.is_running: + time.sleep(0.1) if __name__ == "__main__": diff --git a/examples/obs/setup.py b/examples/obs/setup.py new file mode 100644 index 0000000..4b0cb4a --- /dev/null +++ b/examples/obs/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup( + name="obs", + description="OBS Example", + install_requires=["obsws-python"], +)