def remove(self): global globSettings selection = self.list.curselection() if selection != "": templates = obs.obs_data_get_array(globSettings, "templates" + self.scene.get()) obs.obs_data_array_erase(templates, selection[0]) length = obs.obs_data_array_count(templates) for i in range(selection[0], length): item = obs.obs_data_array_item(templates, i) obs.obs_data_set_string(item, "id", str(i + 1)) obs.obs_data_release(item) obs.obs_data_array_release(templates) self.update()
def _get(self, data): o = _obs.obs_data_get_obj(data, self.name) try: d = _helper.read_data(o, None) finally: _obs.obs_data_release(o) f = d.get("flags", 0) d.update({ "bold": bool(f & _obs.OBS_FONT_BOLD), "italic": bool(f & _obs.OBS_FONT_ITALIC), "underline": bool(f & _obs.OBS_FONT_UNDERLINE), "strikeout": bool(f & _obs.OBS_FONT_STRIKEOUT), }) return {self.name: d}
def refresh_source(key, value): # Get source by name source = obs.obs_get_source_by_name(key) # Create text data for source settings = obs.obs_data_create() obs.obs_data_set_string(settings, 'text', value) # Update source obs.obs_source_update(source, settings) # Release resources obs.obs_source_release(source) obs.obs_data_release(settings)
def crete_text_source(self): current_scene = S.obs_frontend_get_current_scene() scene = S.obs_scene_from_source(current_scene) settings = S.obs_data_create() S.obs_data_set_string(settings, "text", "The quick brown fox jumps over the lazy dog") # doesnt work on private sources source = S.obs_source_create("text_gdiplus", "1test_py", settings, None) S.obs_scene_add(scene, source) S.obs_scene_release(scene) S.obs_data_release(settings) S.obs_source_release(source)
def update_gst_source(self,source_name, pipeline): source = obs.obs_get_source_by_name(source_name) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "pipeline", pipeline) if source is None: obs.script_log(obs.LOG_INFO,"Creating non-existant GStreamer source: {source_name}".format(source_name=source_name)) source = obs.obs_source_create("gstreamer-source",source_name,None,None) # TODO - this doesn't seem to create sources else: obs.script_log(obs.LOG_INFO,"Updating {source_name} pipeline to: {pipeline}".format(source_name=source_name,pipeline=pipeline)) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def script_unload(): global app global globSettings global animationInfo if animationInfo["animScene"] != None: obs.obs_source_release(animationInfo["animScene"]) app.quit() while app.quitted == False: pass obs.obs_data_release(globSettings) return
def set_value(self, source_name, prop, value): """ Set the value of the source using the provided settings If settings is None, previously-provided settings will be used """ _settings = obs.obs_data_create() _source = obs.obs_get_source_by_name(source_name) obs.obs_data_set_string(_settings, prop, value) obs.obs_source_update(_source, _settings) obs.obs_data_release(_settings) obs.obs_source_release(_source) self.properties[source_name].cur_value = value
def _make_list(arr, obj): d = _obs.obs_data_array_create() try: for o in obj: d2 = _obs.obs_data_create() try: set_data(d2, o.items()) _obs.obs_data_array_push_back(arr, d2) finally: _obs.obs_data_release(d2) d_, d = d, None return d_ finally: if d: _obs.obs_data_release(d)
def script_unload(): global cached_items global dimensions if cached_items is not None: for key, item in cached_items.items(): #obs.obs_source_release(item["source"]) obs.obs_sceneitem_release(item["item"]) cached_items = {} obs.obs_data_release(dimensions)
def update_text(self, counter_text, counter_value=0): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() if counter_value == 1: self.counter += 1 if counter_value == -1: 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_tickers(): # Run every second(ish) to update real-time controls global cache_remainingtime global source_gametime control_gametime = obs.obs_get_source_by_name(source_gametime) datastream = obs.obs_data_create() if cache_remainingtime > 0 and control_gametime not in ['',None]: cache_remainingtime -= 1 obs.obs_data_set_string(datastream, "text", "{0}".format(str(time.strftime("%M:%S",time.gmtime(cache_remainingtime))))) obs.obs_source_update(control_gametime, datastream) else: obs.timer_remove(update_tickers) obs.obs_data_release(datastream) obs.obs_source_release(control_gametime)
def set_filter_value(source_name, filter_name, filter_field_name, value): source = obs.obs_get_source_by_name(source_name) if source is not None: filter = obs.obs_source_get_filter_by_name(source, filter_name) if filter is not None: # Get the settings data object for the filter filter_settings = obs.obs_source_get_settings(filter) # Update the hue_shift property and update the filter with the new settings obs.obs_data_set_int(filter_settings, filter_field_name, value) obs.obs_source_update(filter, filter_settings) # Release the resources obs.obs_data_release(filter_settings) obs.obs_source_release(filter) obs.obs_source_release(source)
def update_song(artist="", song=""): # now_playing = "无音乐" now_playing = "" if(artist != "" or song != ""): now_playing = display_text.replace( '%artist', artist).replace('%title', song) settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", now_playing) source = obs.obs_get_source_by_name(source_name) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) if debug_mode: print("[CS] 正在播放: " + artist + " / " + song)
def update_text(): global interval global source_name source = obs.obs_get_source_by_name(source_name) if source is not None: now = datetime.datetime.now() settings = obs.obs_data_create() ### Prof. Wyllian ### #obs.obs_data_set_string(settings, "text", now.strftime("%X")) #obs.obs_data_set_string(settings, "text", now.strftime('%d/%m/%Y - %H:%M:%S.%f')[:-3]) obs.obs_data_set_string(settings, "text", now.strftime('%H:%M:%S.%f')[:-3]) ##################### obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def update_text(self, force=False): source = obs.obs_get_source_by_name(self.source_name) if source is not None: if Data._timerRunning_: text_output = datetime.now().strftime('%I:%M%p') # prevent more work being done than necessary if(text_output == self.lastCount and not force): return self.lastCount = text_output settings = obs.obs_data_create() obs.obs_data_set_string(settings, 'text', text_output) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def change_input(): global globSettings url = obs.obs_data_get_string(globSettings, "url") source = obs.obs_data_get_string(globSettings, "source") if url != None and source != None: sourceObj = obs.obs_get_source_by_name(source) try: streamUrl = streamlink.streams(url)["best"].url if sourceObj != None: settings = obs.obs_data_create() obs.obs_data_set_string(settings, "input", streamUrl) obs.obs_data_set_bool(settings, "is_local_file", False) obs.obs_source_update(sourceObj, settings) obs.obs_data_release(settings) except streamlink.StreamlinkError: pass obs.obs_source_release(sourceObj)
def update_text(): global time_input global source_name source = obs.obs_get_source_by_name(source_name) if time_input.count(':') > 1: final=time_input.split(':') else: print('Zły format. Użyj HH:MM:SS') final='00:00:00'.split(':') if final[0].isdigit() and final[1].isdigit() and final[2].isdigit(): godzina = int(final[0]) -1 minuty = int(final[1]) sekundy = int(final[2]) else: print('Zły format. Użyj HH:MM:SS') godzina = 0 minuty = 0 sekundy = 0 czas1 = list(time.localtime()) czas1[3] = godzina czas1[4] = minuty czas1[5] = sekundy czas1 = time.struct_time(tuple(czas1)) timestamp = time.mktime(czas1) - time.mktime(time.gmtime()) h = int(((timestamp / 60) / 60) % 60 ) s= int(timestamp % 60) m= int((timestamp / 60) % 60) if timestamp > 0: text = '{}:{:02}:{:02}'.format(h, m, s) else: text = 'START!' 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_color(self): source = obs.obs_get_source_by_name(self.source_name) scroll = obs.obs_source_get_filter_by_name(source, "py_color") filter_settings = obs.obs_source_get_settings(scroll) value = self.value if value: self.last_value = value if value == 0: value = self.last_value value = 50 - value obs.obs_data_set_int(filter_settings, "opacity", value) obs.obs_source_update(scroll, filter_settings) obs.obs_data_release(filter_settings) obs.obs_source_release(source) obs.obs_source_release(scroll)
def update_text(self, force=False, updateTime=True): source = obs.obs_get_source_by_name(self.source_name) if source is not None: if not Data._timerRunning_: countdown = '' else: countdown = self.get_formatted_time() #prevent more work being done than necessary if(countdown == self.lastCount and not force): return self.lastCount = countdown settings = obs.obs_data_create() obs.obs_data_set_string(settings, 'text', countdown) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source)
def update_text(): global source_name global target_id global target_title source = obs.obs_get_source_by_name(source_name) for i in get_windows(): if target_id in i[0]: target_title = i[3] target_title = modify(target_title) settings = obs.obs_data_create() obs.obs_data_set_string( settings, "text", target_title) if source is not None: obs.obs_source_update( source , settings) obs.obs_data_release( settings) else: obs_warning("Choose a text source!") obs.remove_current_callback()
def update_text(self, counter_text, counter_value=0): source = obs.obs_get_source_by_name(self.source_name) settings = obs.obs_data_create() if counter_value == 1: self.counter += 1 if counter_value == -1: self.counter -= 1 if counter_value == 0: self.counter = 0 self.text_string = f"{counter_text}{self.counter}" f = open(f"{os.environ['USERPROFILE']}\\counter_data.txt", "w") f.write(str(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 set_names(source_name, string): 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) == source_name: source = source_t settings = obs.obs_data_create() obs.obs_data_set_string(settings, "text", str(string)) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.source_list_release(scenes) obs.sceneitem_list_release(items)
def monitor_source(source): ignored = obs.obs_data_get_array(settings, 'ignored') for idx in range(obs.obs_data_array_count(ignored)): ignored_source_data = obs.obs_data_array_item(ignored, idx) ignored_source = str( obs.obs_data_get_string(ignored_source_data, 'value')) obs.obs_data_release(ignored_source_data) if ignored_source.strip() == obs.obs_source_get_name(source).strip(): print(f'Ignoring "{obs.obs_source_get_name(source)}"') break else: print(f'Monitoring "{obs.obs_source_get_name(source)}"') obs.obs_source_set_monitoring_type( source, obs.OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT) obs.obs_data_array_release(ignored)
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 aseta(props, p): global liitteet global settings sources = obs.obs_enum_sources() for liite in liitteet: for source in sources: nimi = obs.obs_source_get_name(source) if nimi.endswith(liite): data = obs.obs_data_create() if "N" in liite: tieto = obs.obs_data_get_string(settings, liite) obs.obs_data_set_string(data, "text", tieto) elif "V" in liite: tieto = obs.obs_data_get_string(settings, liite) obs.obs_data_set_int(data, "color", int(tieto)) obs.obs_source_update(source, data) obs.obs_data_release(data) obs.obs_source_release(source)
def add(self): global globSettings loc = filedialog.askopenfilename(filetypes=[("JSON", "*.json")], title="Open Template File") templates = obs.obs_data_get_array(globSettings, "templates" + self.scene.get()) if templates == None: template = obs.obs_data_array_create() obs.obs_data_set_array(globSettings, "templates" + self.scene.get(), template) new = obs.obs_data_create() length = obs.obs_data_array_count(templates) + 1 obs.obs_data_set_string(new, "id", str(length)) obs.obs_data_set_string(new, "name", os.path.basename(loc)) obs.obs_data_set_string(new, "loc", loc) obs.obs_data_array_push_back(templates, new) obs.obs_data_release(new) obs.obs_data_array_release(templates) self.list.insert('end', str(length) + ". " + os.path.basename(loc))
def get_properties(self): print("PythonManager get_properties") self.liveSource = True self.props = libobs.obs_properties_create() #need to load from the save file or new python managers will wipe our scripts data = open_json_config_file("PythonScripts.json") obsdata = libobs.obs_data_create_from_json(json.dumps(data)) libobs.obs_source_update(self.source, obsdata) libobs.obs_data_release(obsdata) scriptFiles = libobs.obs_properties_add_editable_list( self.props, "ScriptFiles", "PythonScriptFiles", True, "*.py", "../../data/obs-plugins/obs-python/scripts") libobs.obs_properties_apply_settings(self.props, obsdata) return self.props
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(text): global text_source global old_text if old_text == text: return source = obs.obs_get_source_by_name(text_source) 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) old_text = text else: if DEBUG: obs.script_log( obs.LOG_WARNING, f"Source is empty: {source}/{text_source}")
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: 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(): 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)