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 set_logo(blue_config, orange_config): #reused for logo later default_logo = os.path.join(files_path, 'logo.png') blue_config_bun = get_bot_config_bundle(blue_config) orange_config_bun = get_bot_config_bundle(orange_config) blue_logo = blue_config_bun.get_logo_file() if blue_logo is None: blue_logo = default_logo orange_logo = orange_config_bun.get_logo_file() if orange_logo is None: orange_logo = default_logo default_logo_scale = 0.25 default_logo_size = [400*default_logo_scale, 300*default_logo_scale] blue_logo_size = list(Image.open(blue_logo).size) blue_scale = default_logo_size[0]/blue_logo_size[0] orange_logo_size = list(Image.open(orange_logo).size) orange_scale = default_logo_size[0]/orange_logo_size[0] scenes = obs.obs_frontend_get_scenes() if scenes is not None: for scene in scenes: if obs.obs_source_get_name(scene) == 'RLBot - AutoLeague': scene = obs.obs_scene_from_source(scene) items = obs.obs_scene_enum_items(scene) for item in items: if item is not None: source_t = obs.obs_sceneitem_get_source(item) if obs.obs_source_get_name(source_t) == "Logo-0": source = source_t settings = obs.obs_data_create() obs.obs_data_set_string(settings, "file", blue_logo) obs.obs_source_update(source, settings) obs.obs_data_release(settings) vec = obs.vec2() obs.vec2_set(vec, blue_scale, blue_scale) obs.obs_sceneitem_set_scale(item, vec) if obs.obs_source_get_name(source_t) == "Logo-1": source = source_t settings = obs.obs_data_create() obs.obs_data_set_string(settings, "file", orange_logo) obs.obs_source_update(source, settings) obs.obs_data_release(settings) vec = obs.vec2() obs.vec2_set(vec, orange_scale, orange_scale) obs.obs_sceneitem_set_scale(item, vec) obs.source_list_release(scenes) obs.sceneitem_list_release(items)
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 update_text(): song = get_active_song() song_name = obs.obs_source_get_name(song) settings = obs.obs_data_create() text_source = obs.obs_get_source_by_name(text_source_name) if text_source is not None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", song_name) obs.obs_source_update(text_source, settings) obs.obs_data_release(settings) obs.obs_source_release(text_source)
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(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 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 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 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 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 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 _obs_filter_set_property_values(self, filter_name, owner_name, values): with self._filter_by_name(owner_name, filter_name) as s: d = _obs.obs_data_create() try: _data.set_data(d, values.items()) _obs.obs_source_update(s, d) finally: _obs.obs_data_release(d)
def createObsData(): """ Context manager to call obs_data_create() and release the data when done. """ data = obs.obs_data_create() yield data obs.obs_data_release(data)
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)
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 data_ar(source_settings=None): if not source_settings: settings = obs.obs_data_create() if source_settings: settings = obs.obs_source_get_settings(source_settings) try: yield settings finally: obs.obs_data_release(settings)
def change_input(): global globSettings url = obs.obs_data_get_string(globSettings, "url") source = obs.obs_data_get_string(globSettings, "source") qual = obs.obs_data_get_string(globSettings, "res") if url != None and source != None: sourceObj = obs.obs_get_source_by_name(source) try: streamUrl = "" stream = streamlink.streams(url) if qual in stream: streamUrl = stream[qual].url elif qual + "60" in stream: streamUrl = stream[qual + "60"].url elif qual + "_alt" in stream: streamUrl = stream[qual + "_alt"].url elif qual + "60_alt" in stream: streamUrl = stream[qual + "60_alt"].url elif "best" in stream: streamUrl = stream["best"].url if streamUrl != "" and sourceObj != None: source_id = obs.obs_source_get_id(sourceObj) settings = obs.obs_data_create() if source_id == "ffmpeg_source": obs.obs_data_set_string(settings, "input", streamUrl) obs.obs_data_set_bool(settings, "is_local_file", False) obs.obs_source_update(sourceObj, settings) else: array = obs.obs_data_array_create() data = obs.obs_data_create() obs.obs_data_set_string(data, "name", streamUrl) obs.obs_data_set_string(data, "value", streamUrl) obs.obs_data_array_push_back(array, data) obs.obs_data_release(data) obs.obs_data_set_array(settings, "playlist", array) obs.obs_source_update(sourceObj, settings) obs.obs_data_array_release(array) obs.obs_data_release(settings) except streamlink.StreamlinkError: pass obs.obs_source_release(sourceObj)
def update_bar(): source = obs.obs_get_source_by_name(source_name) if source is not None: text = title() + " Maker: " + maker() + " Likes: " + likes() + " Plays: " + plays() + " " + id() 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_song(): global debug_mode global now_playing settings = obspython.obs_data_create() obspython.obs_data_set_string(settings, "text", now_playing) source = obspython.obs_get_source_by_name(source_name) obspython.obs_source_update(source, settings) obspython.obs_data_release(settings) obspython.obs_source_release(source)
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) settings1 = obs.obs_data_create() settings2 = obs.obs_data_create() if source1 is not None: obs.obs_data_set_string(settings1, "text", slideText) if source2 is not None: obs.obs_data_set_string(settings2, "text", last_slideText) obs.obs_data_set_int(settings1, "opacity", transparency1) obs.obs_data_set_int(settings2, "opacity", transparency2) obs.obs_data_set_int(settings1, "outline_opacity", transparency1) obs.obs_data_set_int(settings2, "outline_opacity", transparency2) else: obs.obs_data_set_int(settings1, "opacity", 100) obs.obs_data_set_int(settings1, "outline_opacity", 100) elif source2 is not None: obs.obs_data_set_string(settings2, "text", last_slideText) obs.obs_data_set_int(settings1, "opacity", 0) obs.obs_data_set_int(settings2, "opacity", 100) obs.obs_data_set_int(settings1, "outline_opacity", 0) obs.obs_data_set_int(settings2, "outline_opacity", 100) obs.obs_source_update(source1, settings1) obs.obs_source_update(source2, settings2) obs.obs_data_release(settings1) obs.obs_data_release(settings2) obs.obs_source_release(source1) obs.obs_source_release(source2)
def update_text(self, scripted_text, color=None): """takes scripted_text , sets its value in obs """ source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() self.text_string = scripted_text if color: obs.obs_data_set_int(settings, "color", color) # colored text obs.obs_data_set_string(settings, "text", self.text_string) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def render_textSource(source): textData = "" for lineCounter in range(0, len(TEXTSOURCE_BUFFER)): textData = textData + TEXTSOURCE_BUFFER[lineCounter] if (lineCounter != (len(TEXTSOURCE_BUFFER) - 1)): textData = textData + "\n" settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", textData) obs.obs_source_update(source, settings) obs.obs_data_release(settings)
def update_text(self, counter_text, counter_value=0): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() self.counter += 1 if counter_value < 0: self.counter = 0 self.text_string = f"{counter_text}{self.counter}" obs.obs_data_set_string(settings, "text", self.text_string) 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) text = "Hello World" 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_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)