示例#1
0
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 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
示例#3
0
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)
示例#4
0
 def update_text(self):
     with source_auto_release(self.source_name) as source:
         if source is not None:
             data = str(next(datacycle))
             with data_auto_release() as settings:
                 obs.obs_data_set_string(settings, "text", data)
                 obs.obs_source_update(source, settings)
示例#5
0
 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)
示例#6
0
    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 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)
示例#8
0
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():
    """
    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)
示例#10
0
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)
示例#11
0
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 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 reset_match_info(prop=None, props=None):
        obs.obs_data_set_string(settings, 'match_type', 'qualification')
        obs.obs_data_set_int(settings, 'match_pair', 1)
        obs.obs_data_set_int(settings, 'match_number', 1)
        obs.obs_data_set_int(settings, 'match_code', 1)

        print(f'Match info reset')
        print()
 def update_text(self, scripted_text, color=None):
     """takes scripted_text , sets its value in obs  """
     with source_ar(self.source_name) as source, data_ar() as settings:
         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)
示例#15
0
def script_load(settings):
    Data._format_ = obs.obs_data_get_string(settings, 'format')
    Data._timerDuration_ = obs.obs_data_get_int(settings, 'timer_duration')
    if not Data._format_:
        Data._format_ = Data._defaultFormat_

    obs.obs_data_set_string(settings, 'format', Data._format_)
    obs.obs_data_set_int(settings, 'timer_duration', Data._timerDuration_)
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)
示例#17
0
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 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')
 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)
示例#20
0
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)
示例#21
0
def script_load(settings):
    obs.obs_frontend_add_event_callback(on_load)

    rtgg_obs.timer.use_podium_colors = obs.obs_data_get_bool(
        settings, "use_podium")

    rtgg_obs.media_player.last_session_race = obs.obs_data_get_string(
        settings, "last_session_race")

    obs.obs_data_set_string(settings, "race", sp.none_races)
示例#22
0
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 script_load(settings):
    Data._format_ = obs.obs_data_get_string(settings, 'format')
    Data._timeBetweenMessages_ = obs.obs_data_get_int(settings,
                                                      'seconds_between_lines')
    if not Data._format_:
        Data._format_ = Data._defaultFormat_

    obs.obs_data_set_string(settings, 'format', Data._format_)
    obs.obs_data_set_int(settings, 'seconds_between_lines',
                         Data._timeBetweenMessages_)
示例#24
0
def script_load(settings):
    obs.obs_frontend_add_event_callback(on_event)
    Data._format_ = obs.obs_data_get_string(settings, 'format')
    Data._autoStart_ = obs.obs_data_get_bool(settings, 'auto_start')

    if not Data._format_:
        Data._format_ = Data._defaultFormat_

    obs.obs_data_set_string(settings, 'format', Data._format_)
    obs.obs_data_set_bool(settings, 'auto_start', Data._autoStart_)
def add_random_text_source(scene):
    r = " random text # " + str(randint(0, 10))
    with data_ar() as settings:
        S.obs_data_set_string(settings, "text", f"random text value {r}")
        with source_create_ar("text_ft2_source", f"random text{r}", settings) as source:
            pos = S.vec2()
            pos.x = randint(0, 1920)
            pos.y = randint(0, 1080)
            scene_item = S.obs_scene_add(scene, source)
            S.obs_sceneitem_set_pos(scene_item, pos)
示例#26
0
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)
示例#27
0
 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)
示例#28
0
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)
示例#29
0
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)
示例#30
0
 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)
示例#31
0
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)