def thread_data(name): source = obs.obs_get_source_by_name(TEXTSOURCE_VALUE) button = obs.obs_get_source_by_name("btn_connect") print("Started the chat service.") while STOP_SIGNAL: data = None try: data = SOCKET.recv(1024).decode("utf-8") if not data: break except: print("ERROR: Non valid data received to be parsed.") break #Parses the IRC line and returns a dictionary with the command content = parse_message(data) if not content['command'] == None: if content['command'] == "PING": SOCKET.sendall( bytes("PONG {}\r\n".format(PINGPONG_SERVER), "UTF-8")) elif content['command'] == "PRIVMSG": append_buffer( source, "{}: {}".format(content['username'], content['message'])) obs.obs_source_release(source) print("Stopping the chat service.")
def validate_and_start(): global initial_load global idle_scene global playing_scene initial_load = True obs.timer_remove(validate_and_start) obs.timer_remove(check_status_and_toggle) # check if file exists if not os.path.isfile(status_file): raise FileNotFoundError(f"Could not find file '{status_file}'") obs.script_log(obs.LOG_INFO, f'{status_file} found!') # check if gameplay enter scene exists src = obs.obs_get_source_by_name(playing_scene) if src is None or obs.obs_source_get_type( src) != obs.OBS_SOURCE_TYPE_SCENE: obs.obs_source_release(src) raise FileNotFoundError(f" Could not find scene '{playing_scene}'") obs.obs_source_release(src) obs.script_log(obs.LOG_INFO, f"Scene '{playing_scene}' found!") # check if gameplay exit scene exists src = obs.obs_get_source_by_name(idle_scene) if src is None or obs.obs_source_get_type( src) != obs.OBS_SOURCE_TYPE_SCENE: obs.obs_source_release(src) raise FileNotFoundError(f" Could not find scene '{idle_scene}'") obs.obs_source_release(src) obs.script_log(obs.LOG_INFO, f"Scene '{idle_scene}' found!") obs.script_log(obs.LOG_INFO, 'Script is now active.') obs.timer_add(check_status_and_toggle, 500)
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 update_content(): global debug_mode global currentTalk global nextTalk #with open(json_filename, 'r') as myfile: with open("c:\\test\\test.json", 'r') as myfile: data = myfile.read() nextTalk = "" data = json.loads(data) for value in data: #Format string from json into date/time for comparison value["startTime"] = datetime.datetime.strptime( value["startTime"], '%Y-%m-%d %H:%M') value["endTime"] = datetime.datetime.strptime(value["endTime"], '%Y-%m-%d %H:%M') #If no nextTalk set, set it to the first entry on the list if nextTalk == "": nextTalk = value # If Current Date is greater then value's start time but less then values end time, set it as current talk. if value["startTime"] < datetime.datetime.now() < value["endTime"]: currentTalk = value # If start time is less then the currently selected next talk # Meaning it is no longer next because it started if nextTalk["startTime"] < datetime.datetime.now(): nextTalk = value #Update fields on OBS settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", currentTalk["title"]) source = obs.obs_get_source_by_name(source_title) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", currentTalk["presenter"]) source = obs.obs_get_source_by_name(source_presenter) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) settings = obs.obs_data_create() obs.obs_data_set_string( settings, "text", datetime.datetime.strftime(currentTalk["startTime"], "%I:%M%p") + " - " + datetime.datetime.strftime(currentTalk["endTime"], "%I:%M%p")) source = obs.obs_get_source_by_name(source_time) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def reset_relics(props, prop): """Sets faction of all relics in overlay to NS by disabling overlays for other factions""" global previous_relic_status, previous_wg_status, previous_connected_status for name in relic_source_names: # Iterate through and disable relic overlay sources source = obs.obs_get_source_by_name(name) if source is not None: obs.obs_source_set_enabled(source, False) obs.obs_source_release( source) # Release sources to prevent memory leak for name in warpgate_names: # Iterate through and disable warpgate overlay sources for fxn in ['_VS', '_NC', '_TR']: nm = warpgate_names[name] + fxn source = obs.obs_get_source_by_name(nm) if source is not None: obs.obs_source_set_enabled(source, False) obs.obs_source_release( source) # Release sources to prevent memory leak for name in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']: # Iterate through and disable cutoff overlay sources nm = name + '_cutoff' source = obs.obs_get_source_by_name(nm) if source is not None: obs.obs_source_set_enabled(source, False) obs.obs_source_release( source) # Release sources to prevent memory leak previous_relic_status = { 'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0 } previous_wg_status = {'N_WG': 0, 'SE_WG': 0, 'SW_WG': 0} previous_connected_status = { 'A': True, 'B': True, 'C': True, 'D': True, 'E': True, 'F': True, 'G': True, 'H': True, 'I': True }
def run_import(props, prop): global template_scene_name global video_directory template_source = obs.obs_get_source_by_name(template_scene_name) template_scene = obs.obs_scene_from_source(template_source) files = glob.glob(video_directory + "/*") files.sort() transition_number = 0 for filename in files: transition_number += 1 bare_name = "Transition " + str(transition_number) new_scene = obs.obs_scene_duplicate(template_scene, bare_name, obs.OBS_SCENE_DUP_REFS) source_data = obs.obs_data_create() obs.obs_data_set_string(source_data, 'local_file', filename) source = obs.obs_source_create('ffmpeg_source', 'Video - ' + bare_name, source_data, None) scene_item = obs.obs_scene_add(new_scene, source) obs.obs_sceneitem_set_order(scene_item, obs.OBS_ORDER_MOVE_BOTTOM) import_utils.fit_to_screen(scene_item) obs.obs_source_release(source) obs.obs_scene_release(new_scene) obs.script_log(obs.LOG_INFO, "created scene '" + bare_name + "' from " + filename) obs.obs_source_release(template_source)
def update_text(self, force=False, updateTime=True): source = obs.obs_get_source_by_name(self.source_name) if source is not None: if updateTime: self.secondsLive += 1 if (self.secondsLive >= 60): self.minutesLive += 1 self.secondsLive = 0 if (self.minutesLive >= 60): self.hoursLive += 1 self.minutesLive = 0 if (Data._visible_ and not Data._timerRunning_): timeLive = "" else: timeLive = self.get_formatted_time() #prevent more work being done than necessary if (timeLive == self.lastTimeLive and not force): return self.lastTimeLive = timeLive settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", timeLive) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def update_text(): global source_name source = obs.obs_get_source_by_name(source_name) if source is not None: # Get the time from the computer OBS runs on if clock_24hr is True: time_now = datetime.now().strftime("%H:%M") else: time_now = datetime.now().strftime("%I:%M %p").lstrip("0") # Add timezone text beneath clock if timezone_text != "": clock_entry = f"{time_now}\n{timezone_text}" else: clock_entry = time_now # Updating the OBS source data settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", clock_entry) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) set_timer_interval()
def update_cursor(self): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() if source is not None: scene_source = obs.obs_frontend_get_current_scene() scene_width = obs.obs_source_get_width(source) scene_height = obs.obs_source_get_height(source) scene = obs.obs_scene_from_source(scene_source) scene_item = obs.obs_scene_find_source(scene, self.source_name) if scene_item: scale = obs.vec2() obs.obs_sceneitem_get_scale(scene_item, scale) scene_width, scene_height = apply_scale( scale.x, scale.y, scene_width, scene_height ) next_pos = obs.vec2() next_pos.x, next_pos.y = get_position() next_pos.x -= scene_width / 2 next_pos.y -= scene_height / 2 # set position to center of source where cursor is obs.obs_sceneitem_set_pos(scene_item, next_pos) obs.obs_data_release(settings) obs.obs_scene_release(scene) obs.obs_source_release(source)
def create_muted_callback(sn): global callback_name if sn is None or sn == callback_name: return False # source hasn't changed or callback is already set if callback_name is not None: remove_muted_callback(callback_name) source = obs.obs_get_source_by_name(sn) if source is None: if sources_loaded: # don't print if sources are still loading dprint("ERROR: Could not create callback for", sn) return False handler = obs.obs_source_get_signal_handler(source) obs.signal_handler_connect(handler, "mute", mute_callback) callback_name = sn # save name for future reference dprint("Added callback for \"{:s}\"".format( obs.obs_source_get_name(source))) if port: # if the serial port is open... obs.timer_add(send_initial_state, init_state_delay) # send the initial state obs.obs_source_release(source) return True
def update_text(): global interval global source_name global strftime global prefix global suffix global time_offset time_stamp = time.time() + (time_offset * 60 * 60) source = obs.obs_get_source_by_name(source_name) if source is not None: time_obj = datetime.datetime.fromtimestamp(time_stamp) settings = obs.obs_data_create() time_str = "格式错误" try: time_str = "{}{}{}".format(prefix, time_obj.strftime(strftime), suffix) except ValueError: pass obs.obs_data_set_string(settings, "text", time_str) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def update_text(): """Updates text sources for the scoreboard""" global scoreboard_source_names, rate_vs, rate_nc, rate_tr scoreboard_source_names['RATE_VS'] = rate_vs scoreboard_source_names['RATE_NC'] = rate_nc scoreboard_source_names['RATE_TR'] = rate_tr for name in scoreboard_source_names: # Iterate through list and update sources in OBS source = obs.obs_get_source_by_name(name) if source is not None: try: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", scoreboard_source_names[name]) obs.obs_source_update(source, settings) obs.obs_data_release(settings) except: obs.script_log( obs.LOG_WARNING, f'[{datetime.datetime.now()}][TRACKER] Encountered error updating ' f'scoreboard source') obs.remove_current_callback() obs.obs_source_release( source) # Releases source and prevents memory leak
def update_sprite_sources(source_name, team_slot): """Updates the settings values Gets called by update_team. Given the source name list, it updates the path for the sprite sources """ # If the dex number is zero or null, then give it the empty GIF file so # they can set sizing if (not team_slot["dexnumber"]) or (team_slot["dexnumber"] == 0): location = f"{script_path()}empty.gif" else: sprite = get_sprite_location(sprite_map['sprites'], team_slot['shiny'], team_slot["dexnumber"], None) location = cache_image(sprite, team_slot['shiny'], sprite_map['cache_location'], "sprites") source = obs.obs_get_source_by_name(source_name) if source is not None: # Set the text element as being the local cached version of the file settings = obs.obs_data_create() obs.obs_data_set_string(settings, "file", location) obs.obs_source_update(source, settings) obs.obs_data_release(settings) # Release the source obs.obs_source_release(source)
def run_import(props, prop): global template_scene_name global image_directory template_source = obs.obs_get_source_by_name(template_scene_name) template_scene = obs.obs_scene_from_source(template_source) # expecting filenames like '01 - test.jpg' files = glob.glob(image_directory + "/*") files.sort() for filename in files: # try to remove the initial ordinal, but don't error if it isn't present. # '01 - test.jpg' -> 'test' # 'test.jpg' -> 'test' parts = Path(filename).stem.split('-') bare_name = parts[len(parts) - 1].strip() new_scene = obs.obs_scene_duplicate(template_scene, bare_name, obs.OBS_SCENE_DUP_REFS) source_data = obs.obs_data_create() obs.obs_data_set_string(source_data, 'file', filename) source = obs.obs_source_create('image_source', 'Image - ' + bare_name, source_data, None) scene_item = obs.obs_scene_add(new_scene, source) obs.obs_sceneitem_set_order(scene_item, obs.OBS_ORDER_MOVE_BOTTOM) import_utils.fit_to_screen(scene_item) obs.obs_source_release(source) obs.obs_scene_release(new_scene) obs.script_log(obs.LOG_INFO, "created scene '" + bare_name + "' from " + filename) obs.obs_source_release(template_source)
def is_source_playing(): source = obs.obs_get_source_by_name(sourcename) mediastate = obs.obs_source_media_get_state(source) #obs.script_log(obs.LOG_DEBUG, "Media state: "+str(mediastate)) obs.obs_source_release(source) return mediastate == 1 #PLAYING is 1
def update_text(self): source = obs.obs_get_source_by_name(self.source_name) if source is not None: data = str(next(datacycle)) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", data) obs.obs_source_update(source, settings)
def update_text(): """ Update the text with the passed time string """ _hide_zero_units = script_state.properties['hide_zero_units'].cur_value _format = script_state.properties['format'].cur_value _round_up = script_state.properties['round_up'].cur_value _time = script_state.clock.get_time(_format, _hide_zero_units, _round_up) _source = script_state.get_value('text_source') if not _source: return _text = _time.string if _time.seconds == 0: obs.remove_current_callback() _text = script_state.get_value('end_text') _settings = obs.obs_data_create() _source = obs.obs_get_source_by_name(_source) obs.obs_data_set_string(_settings, 'text', _text) obs.obs_source_update(_source, _settings) obs.obs_data_release(_settings) obs.obs_source_release(_source)
def update_crop(self): """ Create 2 display captures. Create crop filter with this name: cropXY. Check relative. Set Width and Height to relatively small numbers e.g : 64x64 . Image mask blend + color correction might be an option too. Run script,select this source as cursor source , check Update crop, click start. """ source = obs.obs_get_source_by_name(self.source_name) crop = obs.obs_source_get_filter_by_name(source, "cropXY") filter_settings = obs.obs_source_get_settings(crop) _x, _y = get_position() # https://github.com/obsproject/obs-studio/blob/79981889c6d87d6e371e9dc8fcaad36f06eb9c9e/plugins/obs-filters/crop-filter.c#L87-L93 w = obs.obs_data_get_int(filter_settings, "cx") h = obs.obs_data_get_int(filter_settings, "cy") h, w = int(h / 2), int(w / 2) obs.obs_data_set_int(filter_settings, "left", _x - h) obs.obs_data_set_int(filter_settings, "top", _y - w) obs.obs_source_update(crop, filter_settings) obs.obs_data_release(filter_settings) obs.obs_source_release(source) obs.obs_source_release(crop)
def set_sources(): #run only at loading and in thread t global update_time global slideText global last_slideText global source_1_name global source_2_name global transparency1 global transparency2 update_time = time.time() transparency2 = transparency1 transparency1 = 0 source1 = obs.obs_get_source_by_name(source_1_name) source2 = obs.obs_get_source_by_name(source_2_name) filter1 = obs.obs_source_get_filter_by_name(source1, COLOR_FILTER_NAME) filter2 = obs.obs_source_get_filter_by_name(source2, COLOR_FILTER_NAME) source1Settings = obs.obs_data_create() source2Settings = obs.obs_data_create() filter1Settings = obs.obs_data_create() filter2Settings = obs.obs_data_create() if source1 is not None: obs.obs_data_set_string(source1Settings, "text", slideText) if source2 is not None: obs.obs_data_set_string(source2Settings, "text", last_slideText) obs.obs_data_set_int(filter1Settings, "opacity", transparency1) obs.obs_data_set_int(filter2Settings, "opacity", transparency2) else: obs.obs_data_set_int(filter1Settings, "opacity", 100) elif source2 is not None: obs.obs_data_set_string(source2Settings, "text", last_slideText) obs.obs_data_set_int(filter1Settings, "opacity", 0) obs.obs_data_set_int(filter2Settings, "opacity", 100) obs.obs_source_update(source1, source1Settings) obs.obs_source_update(source2, source2Settings) obs.obs_source_update(filter1, filter1Settings) obs.obs_source_update(filter2, filter2Settings) obs.obs_data_release(source1Settings) obs.obs_data_release(source2Settings) obs.obs_data_release(filter1Settings) obs.obs_data_release(filter2Settings) obs.obs_source_release(source1) obs.obs_source_release(source2) obs.obs_source_release(filter1) obs.obs_source_release(filter2)
def tulosta(props, p): global settings nimi = obs.obs_data_get_string(settings, "valinta") source = obs.obs_get_source_by_name(nimi) data = obs.obs_source_get_settings(source) color = obs.obs_data_get_int(data, "color") print(color)
def is_ql_source(self): source = obs.obs_get_source_by_name(self.source_name) setting = obs.obs_source_get_settings(source) name = obs.obs_data_get_string(setting, "window") if QUAKELIVE_PROCESS in name and (not self.onlyruninql or self.is_ql_running()): return True else: return False
def update_text(self): source = obs.obs_get_source_by_name(self.source_name) if source is not None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", self.data) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def blink(): global source_name global visible source = obs.obs_get_source_by_name(source_name) if source is not None: visible = not visible obs.obs_source_set_enabled(source, visible)
def set_text_source(text): source = obs.obs_get_source_by_name(text_source) if source != None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def scene_name_to_scene(scene): source = obs.obs_get_source_by_name(scene) if source is not None: scene = obs.obs_scene_from_source(source) obs.obs_source_release(source) return scene else: return None
async def updateSource(self): source = obs.obs_get_source_by_name(config.obsSource) text = config.streamList.displayNext() if source is not None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def update_match_video(): global last_video_path print('update_match_video') # TODO: actually set the video starting at the start of the game, rather # than the slot. Also involves ensuring that our timings are in step with # the compbox. path = video_path.get() if last_video_path == path: print(f"{path!r} has already played") return # TODO: can we pull the current video from the source? I tried this but # couldn't work out how. last_video_path = path print(f"Updating to {path!r}") source = obs.obs_get_source_by_name(source_name) if source != None: print('got source') settings = obs.obs_data_create() source_id = obs.obs_source_get_id(source) if source_id == "ffmpeg_source": obs.obs_data_set_string(settings, "local_file", path) obs.obs_data_set_bool(settings, "is_local_file", True) # updating will automatically cause the source to # refresh if the source is currently active obs.obs_source_update(source, settings) # TODO: this ends up resetting the size of the video within OBS. Can # we inspect the source beforehand and preserve the apparent size? # Might be moot if all our videos are the same size and we're # showing them at 100% scale, but would be good to sort properly. elif source_id == "vlc_source": # "playlist" array = obs.obs_data_array_create() item = obs.obs_data_create() obs.obs_data_set_string(item, "value", path) obs.obs_data_array_push_back(array, item) obs.obs_data_set_array(settings, "playlist", array) # updating will automatically cause the source to # refresh if the source is currently active obs.obs_source_update(source, settings) obs.obs_data_release(item) obs.obs_data_array_release(array) obs.obs_data_release(settings) obs.obs_source_release(source) print('update_match_video done')
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_text(text): #updates global source_name source = obs.obs_get_source_by_name(source_name) if source is not None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def blur(pred): # Switches blur on if probability is high source = obs.obs_get_source_by_name(stgs.source) blured = obs.obs_source_enabled(source) if blured and pred <= stgs.pred_threshold: obs.obs_source_set_enabled(source, False) if not blured and pred > stgs.pred_threshold: obs.obs_source_set_enabled(source, True) obs.obs_source_release(source)
def update_text(): global url global interval global source_name source = obs.obs_get_source_by_name(source_name) if source is not None: try: with urllib.request.urlopen(url) as response: data = response.read() text = data.decode('utf-8') settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) except urllib.error.URLError as err: obs.script_log(obs.LOG_WARNING, "Error opening URL '" + url + "': " + err.reason) obs.remove_current_callback() obs.obs_source_release(source)