obs = obslua -- Struktur zur Speicherung der Einstellungen für jede Textquelle source_settings = { {name = "", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false} } -- Setze die deutsche Locale os.setlocale("de_DE.UTF-8") -- Variable zur Verfolgung der letzten Aktualisierungszeit last_update_time = 0 function script_description() return "Ermöglicht das Aktualisieren von bis zu fünf Textquellen mit individuellen Einstellungen für Uhrzeit, 'Uhr'-Text, Datum, Wochentag und Kalenderwoche alle 30 Sekunden. Aktualisierung alle 30 Sekunden spart Ressourcen." end function script_update(settings) for i = 1, 5 do source_settings[i].name = obs.obs_data_get_string(settings, "source" .. i) source_settings[i].show_time = obs.obs_data_get_bool(settings, "show_time" .. i) source_settings[i].show_uhr_text = obs.obs_data_get_bool(settings, "show_uhr_text" .. i) source_settings[i].show_weekday = obs.obs_data_get_bool(settings, "show_weekday" .. i) source_settings[i].show_calendar_week = obs.obs_data_get_bool(settings, "show_calendar_week" .. i) source_settings[i].show_date = obs.obs_data_get_bool(settings, "show_date" .. i) end end function script_properties() local props = obs.obs_properties_create() for i = 1, 5 do local p = obs.obs_properties_add_list(props, "source" .. i, "Quelle " .. i, obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) add_sources(p) obs.obs_properties_add_bool(props, "show_time" .. i, "Uhrzeit anzeigen") obs.obs_properties_add_bool(props, "show_uhr_text" .. i, "'Uhr' hinter Zeit anzeigen") obs.obs_properties_add_bool(props, "show_date" .. i, "Datum anzeigen") obs.obs_properties_add_bool(props, "show_weekday" .. i, "Wochentag anzeigen") obs.obs_properties_add_bool(props, "show_calendar_week" .. i, "Kalenderwoche anzeigen") end return props end function add_sources(property) local sources = obs.obs_enum_sources() if sources ~= nil then for _, source in ipairs(sources) do local source_id = obs.obs_source_get_unversioned_id(source) if source_id == "text_gdiplus" or source_id == "text_ft2_source" then local name = obs.obs_source_get_name(source) obs.obs_property_list_add_string(property, name, name) end end end obs.source_list_release(sources) end function script_tick(seconds) local current_time = os.time() if current_time - last_update_time >= 50 then for i, setting in ipairs(source_settings) do update_source(setting.name, setting.show_time, setting.show_uhr_text, setting.show_weekday, setting.show_calendar_week, setting.show_date) end last_update_time = current_time end end function update_source(source_name, show_time, show_uhr_text, show_weekday, show_calendar_week, show_date) local source = obs.obs_get_source_by_name(source_name) if source ~= nil then local time_format = "%H:%M" local date_format = "%d.%m.%Y" local weekday_format = "%a" local calendar_week_format = "%U" local text = "" if show_time then text = os.date(time_format) if show_uhr_text then text = text .. " Uhr" end end if show_date then local date = os.date(date_format) text = date .. " " .. text end if show_weekday then local weekday = os.date(weekday_format) text = weekday .. " " .. text end if show_calendar_week then local calendar_week = os.date(calendar_week_format) text = "KW " .. calendar_week .. " " .. text end local 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) end end