用Python写一个OBS脚本

源码obs.py

import requests
import obspython
import time

url = ""
source_name = ""
inverval = 1


def script_load(setting):
    obspython.script_log(obspython.LOG_INFO, "脚本载入成功")


def script_description():
    return """
这个脚本用来实时显示时间
https://toodo.fun
123
    """


def script_properties():
    pros = obspython.obs_properties_create()
    obspython.obs_properties_add_text(pros, "url", "URL", obspython.OBS_TEXT_DEFAULT)
    obspython.obs_properties_add_int(pros, "interval", "更新间隔(1-60秒)", 1, 60, 1)
    text_source = obspython.obs_properties_add_list(pros, "source_name", "文字源", obspython.OBS_COMBO_TYPE_LIST,
                                                    obspython.OBS_COMBO_FORMAT_STRING)
    sources = obspython.obs_enum_sources()
    if sources:
        for source in sources:
            source_id = obspython.obs_source_get_unversioned_id(source)
            if source_id in ("text_gdiplus", "text_ft2_source"):
                name = obspython.obs_source_get_name(source)
                obspython.obs_property_list_add_string(text_source, name, name)
        obspython.source_list_release(sources)
    obspython.obs_properties_add_button(pros, "refresh", "立即刷新数据", refresh_pressed)
    return pros


def refresh_pressed(pros, prop):
    update()


def script_defaults(settings):
    obspython.obs_data_set_default_int(settings, "interval", 1)


def script_update(setting):
    global inverval
    global source_name

    source_name = obspython.obs_data_get_string(setting, "source_name")
    interval = obspython.obs_data_get_int(setting, "interval")

    obspython.timer_remove(update)
    obspython.timer_add(update, interval * 1000)


def update():
    global source_name
    source = obspython.obs_get_source_by_name(source_name)
    if source:
        setting = obspython.obs_data_create()
        msm = "Hello World"
        obspython.obs_data_set_string(setting, "text", f"{msm}")
        obspython.obs_source_update(source, setting)
        obspython.obs_data_release(setting)
    obspython.obs_source_release(source)

results matching ""

    No results matching ""