From b81c4c4b977e5d60701942665a0848df7e4d75a2 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 23 Jun 2023 17:44:51 +0100 Subject: [PATCH] modify logging config to filter out logs script now ends when OBS is closed. --- examples/obs/README.md | 4 +++ examples/obs/__main__.py | 55 +++++++++++++++++++++++++++++++--------- examples/obs/setup.py | 2 +- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/examples/obs/README.md b/examples/obs/README.md index 703b1a0..40f09c2 100644 --- a/examples/obs/README.md +++ b/examples/obs/README.md @@ -17,8 +17,12 @@ port = 4455 password = "mystrongpass" ``` +Closing OBS will end the script. + ## Notes +In this example all but `voicemeeterlib.iremote` logs are filtered out. Log level set at DEBUG. + For a similar Streamlabs Desktop example: [Streamlabs example](https://gist.github.com/onyx-and-iris/c864f07126eeae389b011dc49520a19b) diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py index 32d6bef..6a224a1 100644 --- a/examples/obs/__main__.py +++ b/examples/obs/__main__.py @@ -1,16 +1,43 @@ -import logging +import time +from logging import config + +import obsws_python as obsws -import obsws_python as obs import voicemeeterlib -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": { + "voicemeeterlib.iremote": {"handlers": ["stream"], "level": "DEBUG"} + }, + } +) -class Observer: +class MyClient: def __init__(self, vm): self.vm = vm - 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.vm.strip[0].mute = True @@ -52,14 +79,18 @@ class Observer: if fn := fget(scene): fn() + def on_exit_started(self, _): + self.client.unsubscribe() + self.is_running = False + def main(): - subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]} - with voicemeeterlib.api("potato", subs=subs) as vm: - obs = Observer(vm) - while cmd := input(" to exit\n"): - if not cmd: - break + KIND_ID = "potato" + + with voicemeeterlib.api(KIND_ID) as vm: + client = MyClient(vm) + while client.is_running: + time.sleep(0.1) if __name__ == "__main__": diff --git a/examples/obs/setup.py b/examples/obs/setup.py index 230342e..4b0cb4a 100644 --- a/examples/obs/setup.py +++ b/examples/obs/setup.py @@ -3,5 +3,5 @@ from setuptools import setup setup( name="obs", description="OBS Example", - install_requires=["voicemeeter-api", "obsws-python"], + install_requires=["obsws-python"], )