sc9k/obs_scene_switcher.py

42 lines
1.0 KiB
Python
Raw Permalink Normal View History

2021-09-19 12:43:52 -05:00
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
import threading
import obspython as obs
2021-10-03 01:23:25 -05:00
2021-09-19 12:43:52 -05:00
def set_current_scene(scene_name):
scenes = obs.obs_frontend_get_scenes()
for scene in scenes:
name = obs.obs_source_get_name(scene)
if name == scene_name:
obs.obs_frontend_set_current_scene(scene)
return 0
return 1
2021-10-03 01:23:25 -05:00
2021-09-19 12:43:52 -05:00
class RqstHandler(BaseHTTPRequestHandler):
def do_GET(self):
up = urlparse(self.path)
if up.path == '/Scene':
qc = parse_qs(up.query)
set_current_scene(qc.get('name', [''])[0])
self.send_response(200)
self.end_headers()
elif up.path == '/ping':
self.send_response(200)
self.end_headers()
2021-10-03 01:23:25 -05:00
2021-09-19 12:43:52 -05:00
def log_message(self, format, *args):
pass
2021-10-03 01:23:25 -05:00
2021-09-19 12:43:52 -05:00
def run(name):
httpd = HTTPServer(('127.0.0.1', 9302), RqstHandler)
httpd.serve_forever()
2021-10-03 01:23:25 -05:00
2021-09-19 12:43:52 -05:00
t = threading.Thread(target=run, args=(1,), daemon=True)
t.start()