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_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_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 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 playsound(filename, volume, speed): obs.script_log(obs.LOG_DEBUG, "Trying to play " + filename + " to source " + sourcename) scenesource = obs.obs_frontend_get_current_scene() scene = obs.obs_scene_from_source(scenesource) #obs.script_log(obs.LOG_DEBUG,"Scene "+str(scene)) sceneitem = obs.obs_scene_find_source(scene, sourcename) #obs.script_log(obs.LOG_DEBUG,"Scene item "+str(sceneitem)) source = obs.obs_sceneitem_get_source(sceneitem) obs.obs_source_set_volume(source, volume) set_source_speed(source, speed) obs.obs_sceneitem_set_visible(sceneitem, False) settings = obs.obs_source_get_settings(source) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_data_set_string(settings, "local_file", audiofolder + filename) #obs.script_log(obs.LOG_DEBUG,str(obs.obs_data_get_json(settings))) obs.obs_source_update(source, settings) obs.obs_sceneitem_set_visible(sceneitem, True) obs.obs_data_release(settings) obs.obs_source_release(scenesource)
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_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 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 should_switch_scenes(): current = obs.obs_frontend_get_current_scene() name = obs.obs_source_get_name(current) obs.obs_source_release(current) if name in scene_names and name != scene_names[get_active_monitor()]: return True return False
def on_frontend_event(event): global TALLY_STATUS if event in (obs.OBS_FRONTEND_EVENT_SCENE_CHANGED, obs.OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED): # Check the status of the tally sources program_source = obs.obs_frontend_get_current_scene() preview_source = obs.obs_frontend_get_current_preview_scene() program_scene = obs.obs_scene_from_source(program_source) preview_scene = obs.obs_scene_from_source(preview_source) try: for source_name in TALLY_STATUS.keys(): color = "000000" source = obs.obs_scene_find_source(preview_scene, source_name) if source: color = "00ff00" source = obs.obs_scene_find_source(program_scene, source_name) if source: color = "ff0000" if TALLY_STATUS[source_name] != color: CLIENT.publish("cmnd/%s/COLOR" % source_name, color) TALLY_STATUS[source_name] = color finally: obs.obs_source_release(program_source) obs.obs_source_release(preview_source)
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_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 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 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 dup(self): current_scene = S.obs_scene_from_source( S.obs_frontend_get_current_scene()) scene_item = S.obs_scene_find_source(current_scene, self.source_name) info = S.obs_transform_info() crop = S.obs_sceneitem_crop() S.obs_sceneitem_get_info(scene_item, info) S.obs_sceneitem_get_crop(scene_item, crop) duplicate = S.obs_sceneitem_get_source(scene_item) duplicated = S.obs_source_duplicate(duplicate, "duplicate" + self.source_name, False) scenes = S.obs_frontend_get_scenes() for scene in scenes: name = S.obs_source_get_name(scene) if name == self.scene_name: scene = S.obs_scene_from_source(scene) scene_item2 = S.obs_scene_add(scene, duplicated) S.obs_sceneitem_set_info(scene_item2, info) S.obs_sceneitem_set_crop(scene_item2, crop) S.obs_scene_release(scene) S.obs_source_release(duplicated) S.source_list_release(scenes) S.obs_scene_release(current_scene)
def getCurrentSceneItem(self, itemName): source = obs.obs_frontend_get_current_scene() item = '' scene = obs.obs_scene_from_source(source) item = obs.obs_scene_find_source(scene, itemName) obs.obs_source_release(source) return item
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 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 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 handle_program_change(): global program_items program_source = obs.obs_frontend_get_current_scene() program_items = get_item_names_by_scene(program_source) set_lights_by_items(program_items, program_color, program_brightness) obs.obs_source_release(program_source) set_idle_lights()
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 get_sceneitem_from_source_name_in_current_scene(name): result_sceneitem = None current_scene_as_source = obs.obs_frontend_get_current_scene() if current_scene_as_source: current_scene = obs.obs_scene_from_source(current_scene_as_source) result_sceneitem = obs.obs_scene_find_source_recursive(current_scene, name) obs.obs_source_release(current_scene_as_source) return result_sceneitem
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 currentSceneName(): src = obs.obs_frontend_get_current_scene() if src is None: return None name = obs.obs_source_get_name(src) obs.obs_source_release(src) if name is None: return None return name
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 toggle(source): scene = obs.obs_frontend_get_current_scene() sceneitem = obs.obs_scene_find_source(obs.obs_scene_from_source(scene), source) obs.obs_sceneitem_set_visible(sceneitem, not obs.obs_sceneitem_visible(sceneitem)) obs.obs_source_release(scene) obs.obs_source_release(sceneitem)
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)