def main(): obsws = OBSWS('localhost', 4444, "") for s in scenes: response = obsws.require(SetCurrentSceneRequest(scene_name=s)) # Check if everything is OK if response.status == ResponseStatus.OK: print("Scene set: ",s) else: print("Scene not set. Reason:", response.error) time.sleep(5)
async def displayEnable(): async with OBSWS('192.168.0.4', 4444, "password") as obsws: # We can send an empty StartStreaming request (in that case the plugin # will use OBS configuration), but let's provide some settings as well #stream_settings = StreamSettings( # server="rtmp://example.org/my_application", # key="secret_stream_key", # use_auth=False #) stream = Stream( #settings=stream_settings, type="rtmp_custom", ) # Now let's actually perform a request # response = await obsws.require(StartStreamingRequest(stream=stream)) response = await obsws.require(GetCurrentSceneRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: print(response) for source in response.sources: source_response = await obsws.require( SetSourceRenderRequest({ "source": source.name, "render": True })) if source_response.status == ResponseStatus.OK: pass else: print(response.error) else: print(response.error)
async def main(): async with OBSWS('192.168.0.112', 4444, "password") as obsws: # # We can send an empty StartStreaming request (in that case the plugin # # will use OBS configuration), but let's provide some settings as well # stream_settings = StreamSettings( # server="rtmp://example.org/my_application", # key="secret_stream_key", # use_auth=False # ) # stream = Stream( # settings=stream_settings, # type="rtmp_custom", # ) # # Now let's actually perform a request # response = await obsws.require(StartStreamingRequest(stream=stream)) response = await obsws.require(StartRecordingRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: print("Recording has started") else: print("Couldn't start recording! Reason:", response.error) time.sleep(5) response = await obsws.require(StopRecordingRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: print("Recording has stopped") else: print("Couldn't stop recording! Reason:", response.error)
async def main(): async with OBSWS('localhost', 4444, "password") as obsws: print("Connection established.") # We will be sending StartStopStreaming requests if no events are # received in 10 seconds while True: try: # Await for an event, but at most for 10 seconds event = await asyncio.wait_for(obsws.event(), 10) except asyncio.TimeoutError: # Event wasn't acquired, it's just timeout # Time to toggle streaming await obsws.require(StartStopStreamingRequest()) print("Toggled streaming") else: if event is None: break print("Awaited for '{}' event!".format(event.type_name)) print("Connection terminated.")
class BaseOBSWSTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.loop = None self.obsws = None def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.obsws = OBSWS("localhost", loop=self.loop) try: self.loop.run_until_complete(self.obsws.connect()) except OSError: self.skipTest( "{host}:{port} is unreachable. Is OBS Studio with " "obs-websocket plugin launched?".format( host=self.obsws.host, port=self.obsws.port)) except AuthError: self.skipTest( "Couldn't auth to obs-websocket. Password: {password}".format( password=self.obsws.password)) def tearDown(self): self.loop.close() self.loop = None self.obsws = None
async def main(): async with OBSWS('localhost', 4444, "1234") as obsws: # We can send an empty StartStreaming request (in that case the plugin # will use OBS configuration), but let's provide some settings as well stream_settings = StreamSettings( server="rtmp://example.org/my_application", key="secret_stream_key", use_auth=False) stream = Stream( settings=stream_settings, type="rtmp_custom", ) # Now let's actually perform a request response = await obsws.require(EnableStudioModeRequest()) response = await obsws.require(GetVolumeRequest(source="a")) print(response) response = await obsws.require( SetCurrentSceneRequest(scene_name="On Arrive")) response = await obsws.require(ToggleMuteRequest(source="a")) # response = await obsws.require(StartStopRecordingRequest()) # response = await obsws.require(StartRecordingRequest()) # response = await obsws.require(StartStreamingRequest(stream=stream)) print(response)
async def main(): ports = find_board(get_serial_ports()) board = arduino(ports[0]) # Free the buttons! board.release_latches() # local state, probably should put in a dict streaming = False obs_recording = False obs_streaming = False player = False # obsws is an asynchronous websocket interface to the obs streaming # software. This opens a connection to the target machine async with OBSWS('localhost', 4444, 'password') as obsws: # while True: try: board.flush() board.get_state() state = board.read() if state: cmd, state = state if not player and state[board_status.player] == 1: player = True # exit standby, run help script or execute some fun # stuff if state[board_status.stream_button] == 1: await obsws.require(StartStopStreamingRequest()) await obsws.require(StartStopRecordingRequest()) obs_status = await obsws.require( GetStreamingStatusRequest()) #NOQA obs_streaming = obs_status['streaming'] obs_recording = obs_status['recording'] if state[board_status.player_timeout] == 1: # go to stadby, script needs to be implemented pass if streaming and not (obs_recording or obs_streaming): streaming = False board.lights(0) elif not streaming and (obs_recording or obs_streaming): streaming = True board.lights(1) board.release_latches() except ConnectionRefusedError: # Yes, blocking. If I'm not connected, I wait. # A max_retry would be nice but this is a one-off. print("sleeping a bit, yawn") time.sleep(2)
async def connect(): print("Connecting to OBS-Server ...") while 1: try: async with OBSWS('localhost', 4444, "password") as obsws: print("Success ✔") return True except: print(".", end='')
def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) self.obsws = OBSWS("localhost", loop=self.loop) try: self.loop.run_until_complete(self.obsws.connect()) except OSError: self.skipTest( "{host}:{port} is unreachable. Is OBS Studio with " "obs-websocket plugin launched?".format( host=self.obsws.host, port=self.obsws.port)) except AuthError: self.skipTest( "Couldn't auth to obs-websocket. Password: {password}".format( password=self.obsws.password))
async def main(): async with OBSWS('localhost', 4444, "password") as obsws: response = await obsws.require(StartRecordingRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: print("Recording has started") else: print("Couldn't start recording! Reason:", response.error)
async def next_match_hide_2(): await asyncio.sleep(0.01) async with OBSWS("localhost", 4444, "PIqDeb0q7QYCNunQUMyC") as obsws: await asyncio.wait([ obsws.require( SetSourceRenderRequest(source=f"Tourney Client", render=False, scene_name="Mappool")), ])
async def send_command(scene_name): """ Sends the change scene command to OBS """ async with OBSWS('localhost', 4444, secrets.obs_wss_pass) as obsws: response = await obsws.require(SetCurrentSceneRequest(scene_name=f"scene_{scene_name}")) if response.status == ResponseStatus.OK: print(f"OBS: Scene set to {scene_name}") else: print("error:", response.error)
async def main(): ports = find_board(get_serial_ports()) board = arduino(ports[0]) board.release_latches() streaming = False obs_recording = False obs_streaming = False player = False async with OBSWS('localhost', 4444, 'password') as obsws: while True: try: board.flush() board.get_state() ret = board.read() if ret: cmd, state = ret if not player and state[board_status.player] == 1: player = True # exit standby, run help script or execute some fun # stuff if state[board_status.stream_button] == 1: await obsws.require(StartStopStreamingRequest()) await obsws.require(StartStopRecordingRequest()) obs_status = await obsws.require( GetStreamingStatusRequest()) #NOQA obs_streaming = obs_status['streaming'] obs_recording = obs_status['recording'] if state[board_status.player_timeout] == 1: # go to stadby, script needs to be implemented pass if streaming and not (obs_recording or obs_streaming): streaming = False board.lights(0) elif not streaming and (obs_recording or obs_streaming): streaming = True board.lights(1) board.release_latches() except ConnectionRefusedError: print("sleeping a bit, yawn") time.sleep(2)
async def main(): g = acontrol(serial_port='COM5') streaming = False async with OBSWS('localhost', 4444, 'password') as obsws: while True: response = await obsws.require(GetStreamingStatusRequest()) state = g.get_state() if state[11] == 1: g.flip_lights() g.release_latches() await obsws.require(StartStopRecordingRequest())
async def hide_conditional_2(): await asyncio.sleep(0.01) async with OBSWS("localhost", 4444, "PIqDeb0q7QYCNunQUMyC") as obsws: await asyncio.wait([ obsws.require( SetSourceRenderRequest( source=f"{matches.number}_conditional", render=False, scene_name="Schedule")) ])
async def stopRecording(): async with OBSWS('localhost', 4444, "password") as obsws: response = await obsws.require(StopRecordingRequest()) print("Stopped Recording, waiting for finalization") while 1: try: event = await asyncio.wait_for(obsws.event(), 6) if event['update-type'] == 'RecordingStopped': print('Recording finished') break except asyncio.TimeoutError: print("Timeout - Recording, finished") break
async def stopRecording(): async with OBSWS('192.168.0.4', 4444, "password") as obsws: stream = Stream(type="rtmp_custom", ) response = await obsws.require(StopRecordingRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: print("success") else: print(response.error)
async def main(): async with OBSWS('localhost', 4444, "") as obsws: for s in scenes: response = await obsws.require(SetCurrentSceneRequest(scene_name=s)) # Check if everything is OK if response.status == ResponseStatus.OK: print("Scene set: ",s) else: print("Scene not set. Reason:", response.error) await asyncio.sleep(5)
async def streamStatus(): async with OBSWS('192.168.0.4', 4444, "password") as obsws: stream = Stream(type="rtmp_custom", ) response = await obsws.require(GetStreamingStatusRequest()) # Check if everything is OK if response.status == ResponseStatus.OK: return response else: print(response.error) return response
async def start_stop_recording(): try: # Start recording initially async with OBSWS('localhost', 4444, secrets.obs_wss_pass) as obsws: response = await obsws.require(StartRecordingRequest()) if response.status == ResponseStatus.OK: print("OBS Has started recording") else: print("OBS recording error:", response.error) while True: async with OBSWS('localhost', 4444, secrets.obs_wss_pass) as obsws: sleep(cfg.obs_recording_time_split) # Stop recording response = await obsws.require(StopRecordingRequest()) if not response.status == ResponseStatus.OK: print("OBS recording error:", response.error) sleep(0.8) # Start recording response = await obsws.require(StartRecordingRequest()) if not response.status == ResponseStatus.OK: print("OBS recording error:", response.error) print("OBS record split") except KeyboardInterrupt: async with OBSWS('localhost', 4444, secrets.obs_wss_pass) as obsws: response = await obsws.require(StopRecordingRequest()) if not response.status == ResponseStatus.OK: print("OBS recording error:", response.error) return
async def mainx(s): #global s async with OBSWS(obs_ip, obs_port, "") as obsws: response = await obsws.require(SetCurrentSceneRequest(scene_name=s)) # Check if everything is OK if response.status == ResponseStatus.OK: res = "Scene set: " + s #print("Scene set: ",s) else: res = "Scene " + s + " not set. Reason:" + response.error #print("Scene ", s, " not set. Reason:", response.error) print(res) return (res)
def obs_event_listener(): async with OBSWS('localhost', 4444, "password") as obsws: logging.debug("Connection established.") # We will receive events here by awaiting for them (you can await for # an event of a specific type by providing `type_name` argument to # the obsws.event() method) event = await obsws.event() # Awaited event might be None if connection is closed while event is not None: print("Awaited for '{}' event!".format(event.type_name)) event = await obsws.event() # Handle Events here logging.debug("Connection terminated.")
async def setscene(scene): async with OBSWS(obs_ip, obs_port, "") as obsws: response = await obsws.require(SetCurrentSceneRequest(scene_name=scene) ) # Check if everything is OK if response.status == ResponseStatus.OK: result = "Scene set: " + scene status = "ok" else: result = "Scene " + scene + " not set. Reason:" + response.error status = "error" res = {"status": status, "result": result} return (res)
async def hide_adjusted_2(): await asyncio.sleep(0.01) async with OBSWS("localhost", 4444, "PIqDeb0q7QYCNunQUMyC") as obsws: await asyncio.wait([ obsws.require( SetSourceRenderRequest( source=f"Mappool Showcase Values", render=True, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Mappool Showcase Values HR", render=False, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Mappool Showcase Values DT", render=False, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Mappool Showcase Values FM", render=False, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Map AR Value Adjusted HR DT", render=False, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Map CS Value Adjusted HR", render=False, scene_name="Mappool Showcase")), obsws.require( SetSourceRenderRequest( source=f"Map HP Value Adjusted HR", render=False, scene_name="Mappool Showcase")) ])
async def main(): async with OBSWS(args.host, args.port) as obsws: if args.scene: response = await obsws.require( SetCurrentSceneRequest(scene_name=args.scene)) if args.silent: subprocess.Popen( ["notify-send", "OBS Scene changed to " + args.scene], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) print("Scene changed to " + args.scene) if args.profile: response = await obsws.require( SetCurrentProfileRequest(profile_name=args.profile)) if args.silent: subprocess.Popen( ["notify-send", "OBS Profile changed to " + args.scene], shell=False, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) print("Profile changed to " + args.scene)
async def main(x, w, p, c): # Making sure everything is formatted correctly after being sent from the main program to this server = str(x) wall = int(w) password = str(p) command = str(c) async with OBSWS(server, wall, password) as obsws: # Send request to OBS server to start or stop the recording. if command is 'start': response = await obsws.require(StartRecordingRequest()) elif command is 'stop': response = await obsws.require(StopRecordingRequest()) else: pass # Check if everything is OK if response.status == ResponseStatus.OK: return "Everything was done correctly" else: return "Error with the program! Reason:", response.error
async def main(): async with OBSWS('localhost', 4444, "password") as obsws: # We can send an empty StartStreaming request (in that case the plugin # will use OBS configuration), but let's provide some settings as well stream_settings = StreamSettings( server="rtmp://example.org/my_application", key="secret_stream_key", use_auth=False) stream = Stream( settings=stream_settings, type="rtmp_custom", ) # Now let's actually perform a request response = await obsws.require(StartStreamingRequest(stream=stream)) # Check if everything is OK if response.status == ResponseStatus.OK: print("Streaming has started") else: print("Couldn't start the stream! Reason:", response.error)
async def hide_2(): await asyncio.sleep(0.01) async with OBSWS("localhost", 4444, "PIqDeb0q7QYCNunQUMyC") as obsws: await asyncio.wait([ obsws.require( SetSourceRenderRequest(source=f"{matches.number}_flag", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_{matches.number}_flag", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_flag_done", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source= f"{matches.number}_{matches.number}_flag_done", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{matches.number}_text", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{matches.number}_name", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_{matches.number}_name", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_name_done", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source= f"{matches.number}_{matches.number}_name_done", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_score", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_{matches.number}_score", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{matches.number}_vs", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_vs_done", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{matches.number}_hl", render=True, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{matches.number}_{matches.number}_hl", render=True, scene_name="Schedule")) ])
async def unhide_reset(): await asyncio.sleep(0.01) async with OBSWS("localhost", 4444, "PIqDeb0q7QYCNunQUMyC") as obsws: await asyncio.wait([ obsws.require( SetSourceRenderRequest(source=f"{count}_flag", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_{count}_flag", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_flag_done", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{count}_{count}_flag_done", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_text", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_name", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_{count}_name", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_name_done", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{count}_{count}_name_done", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_score", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_{count}_score", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_vs", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_vs_done", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_hl", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_{count}_hl", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_text 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{count}_{count}_name 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"{count}_{count}_flag 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_vs 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_flag 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_name 2", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest(source=f"{count}_conditional", render=False, scene_name="Schedule")), obsws.require( SetSourceRenderRequest( source=f"conditional_explanation", render=False, scene_name="Schedule")) ])
async def main(): ports = find_board(get_serial_ports()) board = arduino(ports[0]) streaming = False startup = True board.release_latches() async with OBSWS('localhost', 4444, 'password') as obsws: if startup: board.flush() board.get_state() ret = board.read() if ret: cmd, state = ret board.off_air() await obsws.require(SetCurrentSceneRequest( {"scene-name": "NotLive"})) await obsws.require(StopStreamingRequest()) streaming = False state[board_status.stream_button] = 0 startup = False obs_status = await obsws.require(GetStreamingStatusRequest()) #NOQA streaming = obs_status['streaming'] while True: try: obs_status = await obsws.require(GetStreamingStatusRequest()) #NOQA if obs_status is not None: streaming = obs_status['streaming'] board.flush() board.get_state() ret = board.read() if ret: cmd, state = ret # print("{} : {}".format(ret, streaming)) # logger.info(cmd) # logger.info(state) if state[board_status.stream_button] == 1 \ and streaming is False: board.on_air() await obsws.require(SetCurrentSceneRequest( {"scene-name": "Live"})) await obsws.require(StartStreamingRequest()) streaming = True state[board_status.stream_button] = 0 elif state[board_status.stream_button] == 1 \ and streaming is True: board.off_air() await obsws.require(SetCurrentSceneRequest( {"scene-name": "NotLive"})) await obsws.require(StopStreamingRequest()) streaming = False state[board_status.stream_button] = 0 elif state[board_status.player_timeout] == 0 \ and streaming is True: board.off_air() await obsws.require(SetCurrentSceneRequest( {"scene-name": "NotLive"})) await obsws.require(StopStreamingRequest()) streaming = False state[board_status.stream_button] = 0 board.release_latches() except ValueError: print("sleeping a bit, yawn") time.sleep(2)