obs = obslua -- Variablen für die Überwachung der Streaming-Zeit local stream_start_time = nil local stream_running = false local stream_counter = 0 local text_source_name = "" local counter_threshold = 30 local prefix = "" local suffix = "" local update_interval = 60000 -- in Millisekunden (60 Sekunden) -- Diese Funktion wird aufgerufen, wenn das Streaming startet function on_event(event) if event == obs.OBS_FRONTEND_EVENT_STREAMING_STARTING then stream_start_time = os.time() stream_running = true stream_counter = stream_counter + 1 update_text_source(stream_counter) elseif event == obs.OBS_FRONTEND_EVENT_STREAMING_STOPPING then stream_running = false local current_time = os.time() local elapsed_time = current_time - stream_start_time if elapsed_time < (counter_threshold * 60) then stream_counter = stream_counter - 1 update_text_source(stream_counter) end end end -- Diese Funktion überprüft die Streaming-Zeit function check_stream_time() if stream_running and stream_start_time then local current_time = os.time() local elapsed_time = current_time - stream_start_time if elapsed_time >= (counter_threshold * 60) then -- counter_threshold Minuten in Sekunden umrechnen stream_running = false -- Zähler bleibt bestehen, wenn die Schwelle erreicht ist end end end -- Diese Funktion aktualisiert die Text-Quelle in OBS function update_text_source(counter) if text_source_name == "" then print("Warnung: Kein Textquellenname angegeben.") return end local source = obs.obs_get_source_by_name(text_source_name) if source then local settings = obs.obs_data_create() local formatted_text = prefix .. tostring(counter) .. suffix obs.obs_data_set_string(settings, "text", formatted_text) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) else print("Quelle nicht gefunden: " .. text_source_name) end end -- Skript-Update-Funktion, die regelmäßig aufgerufen wird function script_tick() check_stream_time() end -- Skript-Initialisierungsfunktion function script_load(settings) obs.obs_frontend_add_event_callback(on_event) obs.timer_add(script_tick, update_interval) -- Überprüft in regelmäßigen Abständen (60 Sekunden) end -- Skript-Beschreibung function script_description() return "Zählt die Anzahl der Streams, die mindestens eine festgelegte Anzahl von Minuten dauerten, und aktualisiert eine Text-Quelle. Wird der Stream unterhalb der festgelegten Dauer beendet, dann korrigiert sich der Zähler nach unten." end -- Funktion zum Laden der Skript-Einstellungen function script_defaults(settings) obs.obs_data_set_default_int(settings, "stream_counter", 0) obs.obs_data_set_default_string(settings, "text_source_name", "") obs.obs_data_set_default_int(settings, "counter_threshold", 30) obs.obs_data_set_default_string(settings, "prefix", "") obs.obs_data_set_default_string(settings, "suffix", "") end -- Funktion zum Speichern der Skript-Einstellungen function script_save(settings) obs.obs_data_set_int(settings, "stream_counter", stream_counter) obs.obs_data_set_string(settings, "text_source_name", text_source_name) obs.obs_data_set_int(settings, "counter_threshold", counter_threshold) obs.obs_data_set_string(settings, "prefix", prefix) obs.obs_data_set_string(settings, "suffix", suffix) end -- Funktion zum Erstellen der Benutzeroberfläche function script_properties() local props = obs.obs_properties_create() local current_counter = obs.obs_properties_add_text(props, "current_counter", "Aktueller Zähler", obs.OBS_TEXT_DEFAULT) obs.obs_property_set_enabled(current_counter, false) -- Schreibgeschützt obs.obs_properties_add_button(props, "increase_counter", "Zähler erhöhen", increase_counter) obs.obs_properties_add_button(props, "decrease_counter", "Zähler verringern", decrease_counter) obs.obs_properties_add_text(props, "text_source_name", "Name der Textquelle", obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_int(props, "counter_threshold", "Zählerschwelle (Minuten)", 1, 120, 1) obs.obs_properties_add_text(props, "prefix", "Präfix", obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "suffix", "Suffix", obs.OBS_TEXT_DEFAULT) return props end -- Funktion zum Aktualisieren der Skript-Einstellungen function script_update(settings) stream_counter = obs.obs_data_get_int(settings, "stream_counter") text_source_name = obs.obs_data_get_string(settings, "text_source_name") counter_threshold = obs.obs_data_get_int(settings, "counter_threshold") prefix = obs.obs_data_get_string(settings, "prefix") suffix = obs.obs_data_get_string(settings, "suffix") -- Überprüfe, ob die Textquelle existiert if text_source_name ~= "" then local source = obs.obs_get_source_by_name(text_source_name) if not source then print("Warnung: Die angegebene Textquelle wurde nicht gefunden: " .. text_source_name) else obs.obs_source_release(source) end end -- Aktualisiere den angezeigten Zählerwert obs.obs_data_set_string(settings, "current_counter", "Stream # " .. tostring(stream_counter)) -- Aktualisiere die Textquelle in OBS update_text_source(stream_counter) end -- Funktion zum manuellen Erhöhen des Zählers function increase_counter(props, p) stream_counter = stream_counter + 1 update_text_source(stream_counter) local settings = obs.obs_data_create() obs.obs_data_set_int(settings, "stream_counter", stream_counter) obs.obs_data_set_string(settings, "current_counter", "Stream # " .. tostring(stream_counter)) obs.obs_properties_apply_settings(script_properties(), settings) obs.obs_data_release(settings) return true end -- Funktion zum manuellen Verringern des Zählers function decrease_counter(props, p) stream_counter = stream_counter - 1 update_text_source(stream_counter) local settings = obs.obs_data_create() obs.obs_data_set_int(settings, "stream_counter", stream_counter) obs.obs_data_set_string(settings, "current_counter", "Stream # " .. tostring(stream_counter)) obs.obs_properties_apply_settings(script_properties(), settings) obs.obs_data_release(settings) return true end -- Debug-Funktion zum Protokollieren von Nachrichten function print(message) obs.script_log(obs.LOG_INFO, message) end