def check_status_and_toggle(): global status_file global idle_scene global playing_scene global previous_status # read status file contents if not os.path.isfile(status_file): obs.timer_remove(check_status_and_toggle) raise FileNotFoundError("Could not find file '{status_file}'") with open(status_file, 'r') as f: status = f.readlines() if status == []: return status = status[0].strip() if status == previous_status: # status has not changed return # Switch scene according to game status if status == 'Playing': src = obs.obs_get_source_by_name(playing_scene) else: src = obs.obs_get_source_by_name(idle_scene) obs.obs_frontend_set_current_scene(src) obs.obs_source_release(src) previous_status = status
def script_update(settings): # see here to generate info needed below https://help.twitch.tv/customer/en/portal/articles/1302780-twitch-irc HOST = "irc.twitch.tv" # example "NICK ninjahipst3r :" NICK = "NICK "your_nickname"\r\n" PORT = 6667 #example PASS = "******"PASS oauth:"your_key"\r\n" # example "JOIN #ninjahipst3r :" JOIN= "JOIN #"your_channel_name" \r\n" #this makes the connection and sets it up to not block. Otherwise OBS will hangup s.connect((HOST, PORT)) s.send(PASS .encode()) s.send(NICK.encode()) s.send(JOIN.encode()) s.setblocking(0) sock_close = False obs.timer_remove(send_help) obs.timer_add(send_help, 1000 * 300) source_name = obs.obs_data_get_string(settings, "source") obs.timer_remove(update_text) obs.timer_add(update_text, 1) #bug here when first started, this can be taken out if needed obs.obs_frontend_set_current_scene(scenes[1])
def transition(scene): print("Transition: " + scene) scenes = obs.obs_frontend_get_scenes() for s in scenes: if obs.obs_source_get_name(s) == scene: obs.obs_frontend_set_current_scene(s) obs.obs_source_release(s)
def set_current_scene(scene): obs.obs_frontend_remove_event_callback(on_event) if obs.obs_frontend_preview_program_mode_active(): obs.obs_frontend_set_current_preview_scene(scene) else: obs.obs_frontend_set_current_scene(scene) obs.obs_frontend_add_event_callback(on_event)
def set_current_scene(self): scenes = obs.obs_frontend_get_scenes() for scene in scenes: name = obs.obs_source_get_name(scene) if name == self.scene_name: obs.obs_frontend_set_current_scene(scene) obs.source_list_release(scenes)
def set_scene_by_name(scene_name): scenes = obs.obs_frontend_get_scenes() scene = find_source_by_name_in_list(scenes, scene_name) if scene is not None: obs.obs_frontend_set_current_scene(scene) obs.source_list_release(scenes)
def scene_handler(address, *args): print(f"{address}: {args}") control, id_type, i_str = address.split("/")[3:6] if control == "button": i = int(i_str) - 1 scn = obspython.obs_frontend_get_scenes()[i] obspython.obs_frontend_set_current_scene(scn)
def change_to_scene(scene_name): scenes = obs.obs_frontend_get_scenes() for scene in scenes: print(obs.obs_source_get_name(scene)) if obs.obs_source_get_name(scene) == scene_name: current_scene = obs.obs_frontend_get_current_scene() scenes.remove(current_scene) obs.obs_frontend_set_current_scene(scene)
def transition(idx=-1): trans = None if idx >= 0: set_transition(idx) trans = obs.obs_frontend_get_current_transition() mode = obs.OBS_TRANSITION_MODE_AUTO duration = 0 p_scene = obs.obs_frontend_get_current_preview_scene() obs.obs_transition_start(trans, mode, duration, p_scene) obs.obs_frontend_set_current_scene(p_scene)
def switch_scenes(): if is_active and should_switch_scenes(): sources = obs.obs_enum_sources() scenes = obs.obs_frontend_get_scenes(sources) obs.source_list_release(sources) current = obs.obs_frontend_get_current_scene() for s in scenes: if s != current and obs.obs_source_get_name(s) in scene_names: obs.obs_frontend_set_current_scene(s) obs.obs_source_release(current)
def transition(num=-1): trans = None if num >= 0: setTransition(num) trans = obs.obs_frontend_get_current_transition() act = obs.obs_frontend_get_current_scene() mode = obs.OBS_TRANSITION_MODE_AUTO duration = 0 dest = obs.obs_frontend_get_current_preview_scene() obs.obs_transition_start(trans, mode, duration, dest) obs.obs_frontend_set_current_scene(dest) obs.obs_frontend_set_current_preview_scene(act)
def update_text(): global source_name global readbuffer global MODT global sock_close recieve = "".encode() try: recieve = s.recv(1024) # uncomment if you want to see the recieved message # print(recieve) except: # I don't handle this, but you can if needed pass readbuffer = readbuffer + recieve temp = readbuffer.split("\n".encode()) readbuffer = temp.pop() # this is setup to take 1 (the first) command every 5 seconds. Anything else it 'SHOULD' throw away. # not tested fully and more testing/optimization should be done for line in temp: parts = line.split(":".encode()) if "QUIT".encode() not in parts[1] and "JOIN".encode() not in parts[1] and "PART".encode() not in parts[1]: try: message = parts[2][:len(parts[2]) - 1] except: message = "" usernamesplit = parts[1].split("!".encode()) username = usernamesplit[0] if MODT: if message == "Hey".encode(): Send_message("Welcome to the stream, " + str(username)) obs.timer_remove(update_text) obs.timer_add(update_text, 1000 * 5) elif message == "!help".encode(): Send_message("ENTER HELP INFO HERE\n") obs.timer_remove(update_text) obs.timer_add(update_text, 1000 * 5) elif message == "!change_view".encode(): Send_message("Next switch available in 5 seconds\n") # this switches to scene 1 obs.obs_frontend_set_current_scene(scenes[1]) obs.timer_remove(update_text) obs.timer_add(update_text, 1000 * 5) #continue if needed break for l in parts: if "End of /NAMES list".encode() in l: MODT = True
def change_to_scene(bot, message, args): time_to_wait = time.time() - last_scene_change["t"] last_scene_change["t"] = time.time() if time_to_wait < DELAY: message['ttw'] = "{:.1f}".format(time_to_wait) return "CommandToSoon" scene_name = args['scene'] scenes = obs.obs_frontend_get_scenes() for scene in scenes: print(obs.obs_source_get_name(scene)) if obs.obs_source_get_name(scene) == scene_name: current_scene = obs.obs_frontend_get_current_scene() scenes.remove(current_scene) obs.obs_frontend_set_current_scene(scene) return 'Success'
def midi_update(msg): global audio_source global start_note global scene_sources if (msg.type == "control_change"): if (msg.control - 1) < len(audio_source): audio_device = audio_source[msg.control - 1] audio = obs.obs_get_source_by_name(audio_device) if audio is not None: volume = float(msg.value) / 127.0 obs.obs_source_set_volume(audio, volume) obs.obs_source_release(audio) elif (msg.type == "note_on"): index = msg.note - start_note if (index < len(scene_sources) and index >= 0): scene = obs.obs_get_source_by_name(scene_sources[index]) obs.obs_frontend_set_current_scene(scene) obs.obs_source_release(scene)
def update(): global url try: with urllib.request.urlopen(url) as response: data = response.read() response = json.loads(data) _scenes = zip(obs.obs_frontend_get_scene_names(), obs.obs_frontend_get_scenes()) scenes = {} for scene in _scenes: scenes[scene[0]] = scene[1] if scenes.get(response['camera']) is not None: print("Switching to scene: " + response['camera']) obs.obs_frontend_set_current_scene(scenes[response['camera']]) except urllib.error.URLError as err: obs.script_log(obs.LOG_WARNING, "Error opening URL '" + url + "': " + err.reason) obs.remove_current_callback()
def on_event(event): if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED: if get_current_scene_name() == closing_scene: if manage_recording and obs.obs_frontend_recording_active(): if stop_recording_delay == 0: stop_recording() else: obs.timer_add(stop_recording, stop_recording_delay * 1000) if manage_streaming and obs.obs_frontend_streaming_active(): if stop_streaming_delay == 0: stop_streaming() else: obs.timer_add(stop_streaming, stop_streaming_delay * 1000) else: if manage_recording and obs.obs_frontend_recording_active(): obs.timer_remove(stop_recording) if manage_streaming and obs.obs_frontend_streaming_active(): obs.timer_remove(stop_streaming) elif not (obs.obs_frontend_streaming_active() or obs.obs_frontend_recording_active()) and ( event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTING or event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTING ) and get_current_scene_name() != start_scene: scenes = obs.obs_frontend_get_scenes() if scenes != None: for scene_source in scenes: print(str(obs.obs_source_get_type(scene_source))) scene_name = obs.obs_source_get_name(scene_source) if scene_name == start_scene: print(scene_name) obs.obs_frontend_set_current_scene(scene_source) break obs.source_list_release(scenes) elif (event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPING and not obs.obs_frontend_recording_active()) or ( event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPING and not obs.obs_frontend_streaming_active()): obs.obs_frontend_remove_event_callback(on_event)
def cycle(): scenes = obs.obs_frontend_get_scenes() current_scene = obs.obs_frontend_get_current_scene() scenes.remove(current_scene) obs.obs_frontend_set_current_scene(random.choice(scenes))
def set_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)
def start(): print(c_ipA) print(c_port) # Open Port? """ #open Port if (c_port != ""): cmd = 'netsh advfirewall firewall add rule name= \"Open Port ' + str(c_port) + '\" dir=in action=allow protocol=TCP localport='+str(c_port) #os.system('cmd /k ' + cmd) subprocess.call(['runas', '/user:Administrator', cmd]) else: #cmd = "echo Hello"#"netsh advfirewall firewall add rule name= \"Open Port \" dir=in action=allow protocol=TCP localport=80" #os.system('cmd /k ' + cmd) pass """ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.settimeout(5) if c_ipA != "" and c_port != "": print("Connecting with custom ip adress and port...") s.bind((c_ipA, int(c_port))) elif c_ipA == "" and c_port != "": print("Connecting with custom port...") s.bind((getIP(), int(c_port))) elif c_ipA != "" and c_port == "": print("Connecting with custom ip adress...") s.bind((c_ipA, PORT)) else: print("Connecting with default values...") s.bind(ADDR) s.listen() print("Server Started...") global runServer global stopServer while runServer: print("Server Running...") try: conn, addr = s.accept() conn.settimeout(5) with conn: print("connected by", addr) connected = True while connected: try: msg = conn.recv(1024) if not msg: break msg = msg.decode(FORMAT) if "scene" in msg: try: scene = int(msg[5:]) scenes = obs.obs_frontend_get_scenes() if len(scenes) >= (scene + 1): obs.obs_frontend_set_current_scene( scenes[scene]) except: pass elif "s_mute" in msg: try: msource = str(msg[6:]) source = obs.obs_get_source_by_name( msource) if source is not None: obs.obs_source_set_muted(source, True) except: pass elif "s_unmute" in msg: try: umsource = str(msg[8:]) source = obs.obs_get_source_by_name( umsource) if source is not None: obs.obs_source_set_muted(source, False) except: pass elif "s_hide" in msg: try: hsource = str(msg[6:]) source = obs.obs_get_source_by_name( hsource) if source is not None: obs.obs_source_set_enabled( source, False) except: pass elif "s_unhide" in msg: try: uhsource = str(msg[8:]) source = obs.obs_get_source_by_name( uhsource) if source is not None: obs.obs_source_set_enabled( source, True) except: pass elif "st_start" in msg: try: obs.obs_frontend_streaming_start() except: pass elif "st_stop" in msg: try: obs.obs_frontend_streaming_stop() except: pass elif "re_start" in msg: try: obs.obs_frontend_recording_start() except: pass elif "re_stop" in msg: try: obs.obs_frontend_recording_stop() except: pass elif "re_pause" in msg: try: if obs.obs_frontend_recording_paused(): obs.obs_frontend_recording_pause(False) else: obs.obs_frontend_recording_pause(True) except: pass if "server_stop" in msg: connected = False runServer = False stopServer = False except: if runServer == False: connected = False print("Closing Connection") conn.close() print("Server Stopped...") sys.exit() except: pass print("Server Stopped...") sys.exit()