# Command line args take priority, with fallback to config.ini, and further fallback to defaults. parser = argparse.ArgumentParser(description='A Python-based program that provides HTTP endpoints for obs-websocket') parser.add_argument('--http_bind_addres', dest='http_bind_addres', default=config.get('http', 'bind_to_address', fallback='0.0.0.0')) parser.add_argument('--http_bind_port', dest='http_bind_port', type=int, default=config.getint('http', 'bind_to_port', fallback=4445)) parser.add_argument('--http_auth_key', dest='http_auth_key', default=config.get('http', 'authentication_key', fallback='')) parser.add_argument('--ws_url', dest='ws_url', default=config.get('obsws', 'ws_url', fallback='ws://127.0.0.1:4444')) parser.add_argument('--ws_password', dest='ws_password', default=config.get('obsws', 'ws_password', fallback='')) args = parser.parse_args() httpAddress = args.http_bind_addres httpPort = args.http_bind_port httpAuthKey = args.http_auth_key wsUrl = args.ws_url wsPassword = args.ws_password if httpAuthKey: logging.info('HTTP server will start with AuthKey set to `{}`'.format(httpAuthKey)) else: logging.info('HTTP server will start without authentication.') httpAuthKey = None ws = simpleobsws.WebSocketClient(url=wsUrl, password=wsPassword) if not loop.run_until_complete(init()): os._exit(1) app.add_routes([web.post('/call/{requestType}', call_request_callback), web.post('/emit/{requestType}', emit_request_callback)]) app.on_cleanup.append(shutdown) web.run_app(app, host=httpAddress, port=httpPort)
import logging logging.basicConfig(level=logging.DEBUG) import asyncio import simpleobsws parameters = simpleobsws.IdentificationParameters( ignoreNonFatalRequestChecks=False ) # Create an IdentificationParameters object (optional for connecting) ws = simpleobsws.WebSocketClient( url='ws://localhost:4444', password='******', identification_parameters=parameters ) # Every possible argument has been passed, but none are required. See lib code for defaults. async def make_request(): await ws.connect() # Make the connection to obs-websocket await ws.wait_until_identified( ) # Wait for the identification handshake to complete request = simpleobsws.Request('GetVersion') # Build a Request object ret = await ws.call(request) # Perform the request if ret.ok(): # Check if the request succeeded print("Request succeeded! Response data: {}".format(ret.responseData)) await ws.disconnect() # Disconnect from the websocket server cleanly loop = asyncio.get_event_loop()
import simpleobsws import random password = '******' url = 'ws://127.0.0.1:4444' dvdStageSceneName = 'dvd' dvdStageSourceName = 'dvdIcon' # Velocity range, in pixels-per-frame velocityMin = 2.5 velocityMax = 4.5 # =============== NO NEED TO CHANGE ANYTHING BELOW =============== ws = simpleobsws.WebSocketClient(url=url, password=password) # Runtime constants obsXResolution = 0 obsYResolution = 0 sceneItemId = 0 # X and Y values for the true width and height of the scene item sceneItemWidth = 0 sceneItemHeight = 0 # The "current" position of the scene item on the screen currentXPosition = 0 currentYPosition = 0 # The starting velocity of the scene item