Working Version
This commit is contained in:
parent
f0601974be
commit
e05183ffeb
72
obsWebSocket.py
Normal file
72
obsWebSocket.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import asyncio
|
||||||
|
import simpleobsws
|
||||||
|
import json
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
ws = simpleobsws.obsws(host='127.0.0.1', port=4444, password='MYSecurePassword', loop=loop) # Every possible argument has been passed, but none are required. See lib code for defaults.
|
||||||
|
|
||||||
|
|
||||||
|
async def default_request():
|
||||||
|
await ws.connect() # Make the connection to OBS-Websocket
|
||||||
|
result = await ws.call('GetVersion') # We get the current OBS version. More request data is not required
|
||||||
|
print(result) # Print the raw json output of the GetVersion request
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
print("\n\n")
|
||||||
|
requests = result['available-requests'].split(',')
|
||||||
|
for r in requests:
|
||||||
|
print(r)
|
||||||
|
print("\n\n")
|
||||||
|
#data = {'source':'test_source', 'volume':0.5}
|
||||||
|
#result = await ws.call('SetVolume', data) # Make a request with the given data
|
||||||
|
#print(result)
|
||||||
|
await ws.disconnect() # Clean things up by disconnecting. Only really required in a few specific situations, but good practice if you are done making requests or listening to events.
|
||||||
|
|
||||||
|
async def make_custom_request(request, data=None):
|
||||||
|
await ws.connect() # Make the connection to OBS-Websocket
|
||||||
|
result = await ws.call(request) # We get the current OBS version. More request data is not required
|
||||||
|
print(result) # Print the raw json output of the GetVersion request
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
if not data==None:
|
||||||
|
data = {'source':'test_source', 'volume':0.5}
|
||||||
|
result = await ws.call('SetVolume', data) # Make a request with the given data
|
||||||
|
print(result)
|
||||||
|
await ws.disconnect() # Clean things up by disconnecting. Only really required in a few specific situations, but good practice if you are done making requests or listening to events.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def on_event(data):
|
||||||
|
print('New event! Type: {} | Raw Data: {}'.format(data['update-type'], data)) # Print the event data. Note that `update-type` is also provided in the data
|
||||||
|
|
||||||
|
async def on_switchscenes(data):
|
||||||
|
print("\n===========================================\n\n")
|
||||||
|
print('Scene switched to "{}". It has these sources: {}'.format(data['scene-name'], data['sources']))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getRequests():
|
||||||
|
loop.run_until_complete(default_request())
|
||||||
|
|
||||||
|
def makeRequest(request):
|
||||||
|
loop.run_until_complete(make_custom_request(request))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def listenForData():
|
||||||
|
print("\n\nListener:")
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
ws = simpleobsws.obsws(host='127.0.0.1', port=4444, password='MYSecurePassword', loop=loop) # Every possible argument has been passed, but none are required. See lib code for defaults.
|
||||||
|
loop.run_until_complete(ws.connect())
|
||||||
|
ws.register(on_event) # By not specifying an event to listen to, all events are sent to this callback.
|
||||||
|
ws.register(on_switchscenes, 'SwitchScenes')
|
||||||
|
loop.run_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#print("\n\nRequests:")
|
||||||
|
#loop.run_until_complete(get_requests())
|
||||||
|
|
||||||
|
#makeRequest("ToggleStudioMode")
|
||||||
|
#listenForData()
|
||||||
|
pass
|
||||||
@ -1,17 +1,24 @@
|
|||||||
import asyncio
|
import flask
|
||||||
import simpleobsws
|
from flask import request
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
import obsWebSocket
|
||||||
ws = simpleobsws.obsws(host='127.0.0.1', port=4444, password='MYSecurePassword', loop=loop) # Every possible argument has been passed, but none are required. See lib code for defaults.
|
|
||||||
|
|
||||||
async def make_request():
|
import os
|
||||||
await ws.connect() # Make the connection to OBS-Websocket
|
import praxis_logging
|
||||||
result = await ws.call('GetVersion') # We get the current OBS version. More request data is not required
|
praxis_logger_obj = praxis_logging.praxis_logger()
|
||||||
print(result) # Print the raw json output of the GetVersion request
|
praxis_logger_obj.init(os.path.basename(__file__))
|
||||||
await asyncio.sleep(1)
|
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
|
||||||
data = {'source':'test_source', 'volume':0.5}
|
|
||||||
result = await ws.call('SetVolume', data) # Make a request with the given data
|
|
||||||
print(result)
|
|
||||||
await ws.disconnect() # Clean things up by disconnecting. Only really required in a few specific situations, but good practice if you are done making requests or listening to events.
|
|
||||||
|
|
||||||
loop.run_until_complete(make_request())
|
api = flask.Flask(__name__)
|
||||||
|
# enable/disable this to get web pages of crashes returned
|
||||||
|
api.config["DEBUG"] = False
|
||||||
|
|
||||||
|
def init():
|
||||||
|
obsWebSocket.getRequests()
|
||||||
|
#obsWebSocket.makeRequest("ToggleStudioMode")
|
||||||
|
obsWebSocket.listenForData()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
init()
|
||||||
|
api.run(host='0.0.0.0', port=6009)
|
||||||
Loading…
Reference in New Issue
Block a user