mirror of
https://github.com/onyx-and-iris/xair-api-python.git
synced 2025-01-18 04:40:47 +00:00
upd obs example
This commit is contained in:
parent
fd4a228086
commit
7b6e70028b
@ -19,7 +19,7 @@ password = "mystrongpass"
|
||||
|
||||
## Use
|
||||
|
||||
Change the xair ip argument from `mixer.local` to the ip of your xair mixer. Run the code and switch between scenes in OBS.
|
||||
Change the xair ip argument from `mixer.local` to the ip of your xair mixer. Run the code and switch between scenes in OBS. Closing OBS will end the script.
|
||||
|
||||
## Notes
|
||||
|
||||
|
@ -1,13 +1,48 @@
|
||||
import obsws_python as obs
|
||||
import threading
|
||||
from logging import config
|
||||
|
||||
import obsws_python as obsws
|
||||
|
||||
import xair_api
|
||||
|
||||
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': {
|
||||
'xair_api.xair': {
|
||||
'handlers': ['stream'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
}
|
||||
},
|
||||
'root': {'handlers': ['stream'], 'level': 'WARNING'},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, mixer):
|
||||
def __init__(self, mixer, stop_event):
|
||||
self._mixer = mixer
|
||||
self._client = obs.EventClient()
|
||||
self._client.callback.register(self.on_current_program_scene_changed)
|
||||
self._stop_event = stop_event
|
||||
self._client = obsws.EventClient()
|
||||
self._client.callback.register(
|
||||
(
|
||||
self.on_current_program_scene_changed,
|
||||
self.on_exit_started,
|
||||
)
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
@ -32,12 +67,16 @@ class Observer:
|
||||
self._mixer.config.mute_group[0].on = True
|
||||
print(f'Mute Group 1 is {self._mixer.config.mute_group[0].on}')
|
||||
|
||||
def on_exit_started(self, _):
|
||||
self._stop_event.set()
|
||||
|
||||
|
||||
def main():
|
||||
with xair_api.connect('MR18', ip='mixer.local') as mixer:
|
||||
with Observer(mixer):
|
||||
while _ := input('Press <Enter> to exit\n'):
|
||||
pass
|
||||
stop_event = threading.Event()
|
||||
|
||||
with Observer(mixer, stop_event):
|
||||
stop_event.wait()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user