Skip to content

Commit d5dc388

Browse files
hanatyan128claude
andcommitted
chore: Sync sample script fixes between Lua and Python variants
Align recording/replay-buffer filename-from-text sample scripts so the Lua and Python variants share the same robustness fixes: version note corrected to v1.0.9+, override_cleared flag to suppress redundant proc calls, enhanced sanitize_filename (control chars, trailing dots/spaces, Windows reserved names), BOM handling with 4KB read limit, old-filter override clearing on selection change, filter ID validation with proc return-value logging, and defensive timer_remove in script_load. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1f0c309 commit d5dc388

4 files changed

Lines changed: 421 additions & 163 deletions

File tree

data/scripts/recording-filename-from-text.lua

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ local base_format = "%CCYY-%MM-%DD %hh-%mm-%ss"
4040
local last_text = nil
4141
local last_applied_text = nil
4242
local last_applied_time = 0
43+
local override_cleared = false
4344
local THROTTLE_SECONDS = 30
4445

4546
-- Forward declaration so update_recording_format() can call clear_override()
@@ -224,16 +225,20 @@ local function update_recording_format()
224225
-- Get text from the text source
225226
local text_source = obs.obs_get_source_by_uuid(text_source_uuid)
226227
if text_source == nil then
227-
-- Text source not available: clear override
228-
clear_override()
228+
-- Text source not available: clear override (only once per state change)
229+
if not override_cleared then
230+
clear_override()
231+
end
229232
return
230233
end
231234

232235
local current_text, ok = read_text_from_source(text_source)
233236
obs.obs_source_release(text_source)
234237

235238
if not ok or current_text == nil then
236-
clear_override()
239+
if not override_cleared then
240+
clear_override()
241+
end
237242
return
238243
end
239244

@@ -261,24 +266,31 @@ local function update_recording_format()
261266
if call_override_proc(filter_uuid, new_format) then
262267
last_applied_text = current_text
263268
last_applied_time = now
269+
override_cleared = false
264270
obs.script_log(obs.LOG_INFO, LOG_LABEL .. " updated: " .. new_format)
265271
end
266272
end
267273

268274
clear_override = function()
269275
-- Clear the filename format override by sending an empty string.
276+
-- Sets override_cleared = true to suppress redundant proc calls on
277+
-- subsequent timer ticks until a new format is applied or the
278+
-- selection changes.
270279
if selected_filter == "" then
280+
override_cleared = true
271281
return
272282
end
273283

274284
local _, filter_uuid = parse_selected_filter(selected_filter)
275285
if filter_uuid == "" then
286+
override_cleared = true
276287
return
277288
end
278289

279290
if call_override_proc(filter_uuid, "") then
280291
obs.script_log(obs.LOG_INFO, LOG_LABEL .. " override cleared")
281292
end
293+
override_cleared = true
282294
end
283295

284296
local function timer_callback()
@@ -313,6 +325,7 @@ function script_properties()
313325
for _, source in ipairs(sources) do
314326
local source_id = obs.obs_source_get_unversioned_id(source)
315327
if source_id == "text_gdiplus" or source_id == "text_gdiplus_v2"
328+
or source_id == "text_gdiplus_v3"
316329
or source_id == "text_ft2_source" or source_id == "text_ft2_source_v2" then
317330
local name = obs.obs_source_get_name(source)
318331
local uuid = obs.obs_source_get_uuid(source)
@@ -370,13 +383,14 @@ function script_update(settings)
370383
last_text = nil
371384
last_applied_text = nil
372385
last_applied_time = 0
386+
override_cleared = false
373387
end
374388

375389
function script_load(settings)
376390
-- Defensive timer_remove in case of script reload.
377391
obs.timer_remove(timer_callback)
378-
-- Apply initial settings so the first tick has valid state.
379-
script_update(settings)
392+
-- script_update(settings) is called automatically by OBS after
393+
-- script_load, so we don't need to invoke it explicitly here.
380394
obs.timer_add(timer_callback, 1000)
381395
end
382396

0 commit comments

Comments
 (0)