obs = obslua -- Struktur zur Speicherung der Einstellungen für jede Textquelle source_settings = { {name = "", separator = ", ", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", separator = ", ", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", separator = ", ", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", separator = ", ", show_time = true, show_uhr_text = true, show_weekday = false, show_calendar_week = false, show_date = false}, {name = "", separator = ", ", 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 update_interval = 20 -- Aktualisierungsintervall auf 20 Sekunden gesetzt 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 20 Sekunden. Aktualisierung alle 20 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].separator = obs.obs_data_get_string(settings, "separator" .. i) if source_settings[i].separator == "" then source_settings[i].separator = " " end 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 -- Sofortige Aktualisierung auslösen und Timer neu starten last_update_time = 0 script_tick(0) 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_text(props, "separator" .. i, "Trennzeichen", obs.OBS_TEXT_DEFAULT) 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 >= update_interval then for i, setting in ipairs(source_settings) do update_source(setting.name, setting.separator, 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 get_calendar_week() local current_date = os.date("*t") local jan1 = os.time{year = current_date.year, month = 1, day = 1} local day_of_year = os.date("%j") local jan1_weekday = os.date("%w", jan1) local week_num = math.ceil((day_of_year + jan1_weekday - 1) / 7) return week_num end function update_source(source_name, separator, 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 components = {} if show_calendar_week then table.insert(components, "KW " .. get_calendar_week()) end if show_weekday then table.insert(components, os.date(weekday_format)) end if show_date then table.insert(components, os.date(date_format)) end if show_time then local time_text = os.date(time_format) if show_uhr_text then time_text = time_text .. " Uhr" end table.insert(components, time_text) end local text = table.concat(components, separator) 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