auto-obs-rb-restart/AutoOBSRBRestart.lua

67 lines
1.4 KiB
Lua
Raw Normal View History

2024-10-07 20:23:21 +02:00
obs = obslua
local wait_time = 7200 -- Wait 2 hours before checks
local idle_time = 120 -- Wait for any input in the last 2 minutes
function script_description()
2024-10-07 21:20:48 +02:00
return [[
Automatically restarts the replay buffer when IDLE
Author: Mylloon
]]
2024-10-07 20:23:21 +02:00
end
function script_load()
ffi = require("ffi")
ffi.cdef[[
void start_hook(void);
void stop_hook(void);
2024-10-07 22:14:33 +02:00
long long last_input_received(void);
2024-10-07 20:23:21 +02:00
]]
monitor = ffi.load(script_path() .. "monitor.dll")
2024-10-09 12:31:11 +02:00
start_loop()
2024-10-07 20:23:21 +02:00
end
function script_unload()
obs.timer_remove(check_restart)
obs.timer_remove(check_idle)
2024-10-07 22:14:33 +02:00
monitor.stop_hook()
2024-10-07 20:23:21 +02:00
end
2024-10-09 12:31:11 +02:00
function start_loop()
print("Start idle")
obs.timer_add(check_restart, wait_time * 1000)
end
2024-10-07 20:23:21 +02:00
function check_restart()
obs.timer_remove(check_restart)
2024-10-09 12:31:11 +02:00
print("Start check every " .. idle_time .. "secs")
2024-10-07 20:23:21 +02:00
monitor.start_hook()
obs.timer_add(check_idle, idle_time * 1000)
end
function check_idle()
obs.timer_remove(check_idle)
2024-10-07 20:23:21 +02:00
local current_time = os.time()
2024-10-07 22:14:33 +02:00
local last_input_time = monitor.last_input_received()
2024-10-07 20:23:21 +02:00
2024-10-07 21:20:48 +02:00
if current_time - last_input_time >= idle_time then
2024-10-07 20:23:21 +02:00
monitor.stop_hook()
2024-10-09 12:31:11 +02:00
print("No activity detected, restart replay buffer")
obs.obs_frontend_replay_buffer_stop()
2024-11-23 19:22:14 +01:00
obs.timer_add(start_replay_buffer, 4000)
else
obs.timer_add(check_idle, idle_time * 1000)
end
2024-10-07 20:23:21 +02:00
end
function start_replay_buffer()
obs.timer_remove(start_replay_buffer)
obs.obs_frontend_replay_buffer_start()
2024-10-09 12:31:11 +02:00
start_loop()
2024-10-07 20:23:21 +02:00
end