diff --git a/README.md b/README.md index b0e43d2..a6b4764 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This OBS Studio Lua script writes your current stream uptime to a text file, wit 4. Click the `+` button and select `obs_uptime_to_file.lua`. 5. Set the `Output File Path` to where you want the uptime to be written. 6. (Optional) Set the `Format String` to customize how the uptime appears. +7. (Optional) Set the `Update Interval (seconds)` to control how often the file is updated (default: 1 second). ## Format String You can control how the uptime is displayed using the `Format String` property. Use these placeholders: @@ -32,7 +33,7 @@ You can control how the uptime is displayed using the `Format String` property. - `{M} minutes` → `83 minutes` ## How It Works -- When you start streaming, the script begins writing the uptime to your chosen file every second. +- When you start streaming, the script begins writing the uptime to your chosen file at the interval you set (default: every second). - When you stop streaming, the file is erased (emptied), so nothing will display if you use it as a text source. ## Use Case diff --git a/obs_uptime_to_file.lua b/obs_uptime_to_file.lua index a773ff3..a3437ab 100644 --- a/obs_uptime_to_file.lua +++ b/obs_uptime_to_file.lua @@ -6,7 +6,8 @@ source_name = "" output_path = "" format_string = "{h}:{m}:{s}" -interval = 1000 -- ms +interval_sec = 1 -- seconds +interval = 1000 -- ms (default, will be set in script_update) start_time = nil hotkey_id = obs.OBS_INVALID_HOTKEY_ID @@ -20,6 +21,8 @@ function script_properties() obs.obs_properties_add_text(props, "format_string", "Format String", obs.OBS_TEXT_DEFAULT) obs.obs_property_set_long_description(obs.obs_properties_get(props, "format_string"), "Use {h} for hours, {m} for minutes, {s} for seconds. Example: {h}:{m}:{s}, {h}h {m}m, {m} minutes, etc.") + local interval_prop = obs.obs_properties_add_int(props, "interval_sec", "Update Interval (seconds)", 1, 60, 1) + obs.obs_property_set_long_description(interval_prop, "How often to update the file, in seconds (default: 1)") return props end @@ -31,6 +34,9 @@ function script_update(settings) else format_string = "{h}:{m}:{s}" end + interval_sec = obs.obs_data_get_int(settings, "interval_sec") + if interval_sec < 1 then interval_sec = 1 end + interval = interval_sec * 1000 end function on_event(event) @@ -42,6 +48,11 @@ function on_event(event) erase_uptime_file() start_time = nil end + -- If timer is running, update interval + obs.timer_remove(update_uptime) + if start_time then + obs.timer_add(update_uptime, interval) + end end function update_uptime()