コード例 #1
0
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)
コード例 #2
0
def monitor_source_callback(calldata):
    source = obs.calldata_source(calldata, 'source')
    if not source:
        return

    if obs.obs_source_get_type(source) == obs.OBS_SOURCE_TYPE_INPUT:
        monitor_source(source)
コード例 #3
0
def set_audio_sources():

    sources = obs.obs_enum_sources()

    for source in sources:

        if obs.obs_source_get_type(source) == obs.OBS_SOURCE_TYPE_INPUT:
            capabilities = obs.obs_source_get_output_flags(source)
            has_audio = capabilities & obs.OBS_SOURCE_AUDIO
            if has_audio:
                audio_sources.append(source)

    obs.source_list_release(sources)
コード例 #4
0
def script_load(settings_):
    global settings

    settings = settings_

    # monitor all shown sources on load
    sources = obs.obs_enum_sources()
    for source in sources:
        if obs.obs_source_showing(source) and obs.obs_source_get_type(
                source) == obs.OBS_SOURCE_TYPE_INPUT:
            monitor_source(source)
    obs.source_list_release(sources)

    # connect to 'source_show' event to monitor all added sources when shown
    obs.signal_handler_connect(obs.obs_get_signal_handler(), 'source_show',
                               monitor_source_callback)
コード例 #5
0
def list_audio_sources():
    audio_sources = []
    sources = obs.obs_enum_sources()

    for source in sources:
        if obs.obs_source_get_type(source) == obs.OBS_SOURCE_TYPE_INPUT:
            # output flag bit field: https://obsproject.com/docs/reference-sources.html?highlight=sources#c.obs_source_info.output_flags
            capabilities = obs.obs_source_get_output_flags(source)

            has_audio = capabilities & obs.OBS_SOURCE_AUDIO
            # has_video = capabilities & obs.OBS_SOURCE_VIDEO
            # composite = capabilities & obs.OBS_SOURCE_COMPOSITE

            if has_audio:
                audio_sources.append(obs.obs_source_get_name(source))

    obs.source_list_release(sources)

    return audio_sources
コード例 #6
0
def on_event(event):
    if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED:
        if get_current_scene_name() == closing_scene:
            if manage_recording and obs.obs_frontend_recording_active():
                if stop_recording_delay == 0:
                    stop_recording()
                else:
                    obs.timer_add(stop_recording, stop_recording_delay * 1000)
            if manage_streaming and obs.obs_frontend_streaming_active():
                if stop_streaming_delay == 0:
                    stop_streaming()
                else:
                    obs.timer_add(stop_streaming, stop_streaming_delay * 1000)
        else:
            if manage_recording and obs.obs_frontend_recording_active():
                obs.timer_remove(stop_recording)
            if manage_streaming and obs.obs_frontend_streaming_active():
                obs.timer_remove(stop_streaming)
    elif not (obs.obs_frontend_streaming_active()
              or obs.obs_frontend_recording_active()) and (
                  event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTING
                  or event == obs.OBS_FRONTEND_EVENT_RECORDING_STARTING
              ) and get_current_scene_name() != start_scene:
        scenes = obs.obs_frontend_get_scenes()
        if scenes != None:
            for scene_source in scenes:
                print(str(obs.obs_source_get_type(scene_source)))
                scene_name = obs.obs_source_get_name(scene_source)
                if scene_name == start_scene:
                    print(scene_name)
                    obs.obs_frontend_set_current_scene(scene_source)
                    break
            obs.source_list_release(scenes)
    elif (event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPING
          and not obs.obs_frontend_recording_active()) or (
              event == obs.OBS_FRONTEND_EVENT_RECORDING_STOPPING
              and not obs.obs_frontend_streaming_active()):
        obs.obs_frontend_remove_event_callback(on_event)