Commit f5af9770 authored by nextime's avatar nextime

Add obs minimal support

parent fa0cb6f4
......@@ -16,20 +16,70 @@
import obsws_python as obs
import time
def on_scene_item_enable_state_changed(data):
print("scscene_item_enable_state_changed")
print(data.attrs())
print(data.scene_item_enabled, data.scene_item_id, data.scene_name, data.scene_uuid)
class OBSControl:
def __init__(self, obs_server, config_section):
self.online = False
self.last_try = time.time()-11
self.lastping = time.time()-20
self.server = obs_server
self.config_section = config_section
self.config_options = config.options(config_section)
for c in self.config_options:
setattr(self, c, config.get(config_section, c))
def start(self):
if self.online:
return
self.last_try = time.time()
try:
self.cl = obs.EventClient(host=self.host, port=self.port, password=self.password)
self.cr = obs.ReqClient(host=self.host, port=self.port, password=self.password)
self.cl.callback.register(self.on_scene_item_enable_state_changed)
self.setonline()
except Exception:
pass
def setonline(self):
self.online = True
def setoffline(self):
self.online = False
def run_tasks(self):
if not self.online and time.time()-self.last_try > 10:
print("OBS ", self.server, "starting... ")
self.start()
if self.online:
if time.time()-self.lastping > 20:
try:
self.cr.broadcast_custom_event({'eventData': {'eventType': 'Ping', 'time': time.time()}})
self.lastping = time.time()
except:
self.setoffline()
def on_scene_item_enable_state_changed(self, data):
print("scscene_item_enable_state_changed")
print(data.attrs())
print(data.scene_item_enabled, data.scene_item_id, data.scene_name, data.scene_uuid)
def run_obs_controller():
cl = obs.EventClient(host='192.168.42.115', port=4455, password='motorol4')
cr = obs.ReqClient(host='192.168.42.115', port=4455, password='motorol4')
obs_servers = {}
for k in [x for x in config.sections() if 'OBS:' in x]:
if not config.get(k, 'active', fallback=False):
obs_servers[k.split(":",1)[1]] = OBSControl(k.split(":",1)[1], k)
#cl = obs.EventClient(host='192.168.42.115', port=4455, password='motorol4')
#cr = obs.ReqClient(host='192.168.42.115', port=4455, password='motorol4')
cl.callback.register(on_scene_item_enable_state_changed)
#cl.callback.register(on_scene_item_enable_state_changed)
print(cl.callback.get())
#print(cl.callback.get())
#cl.callback.deregister(on_input_mute_state_changed)
......@@ -37,6 +87,8 @@ def run_obs_controller():
while True:
if (time.time() - now) > 30:
now = time.time()
cr.broadcast_custom_event({'eventData': {'eventType': 'Ping', 'time': time.time()}})
#cr.broadcast_custom_event({'eventData': {'eventType': 'Ping', 'time': time.time()}})
for o in obs_servers.keys():
obs_servers[o].run_tasks()
time.sleep(.01)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment