-- Version 1.1
o = obslua
--Set interval in ms to how often the text file is checked for changes. Default = 1000 ms (1 second).
interval = 1000
TEXTFILE= nil
VIDFILE= nil
PVIDFILE= nil
VIDPATH= nil
SKIP = nil
source_name = nil
updated = false
enabled = true
function read_txt_file(filename)
filename = filename or ''
local line
PVIDFILE = VIDFILE
if not file_exists(filename) then return end
for line in io.lines(filename) do
if line ~= "" then
VIDFILE = line
local p, t = line:match("^([^=]+)%;(.+)$")
if p then
VIDPATH = p
if not t then t = "00:00:00" end
local shour, sminute, ssecond = line:match("(%d+):(%d+):(%d+)") --("^([^=]+)%:(.+)$")
local hour = tonumber(shour)
local minute = tonumber(sminute)
local second = tonumber(ssecond)
SKIP = (hour * 3600000) + (minute * 60000) + (second * 1000)
end
end
end
end
function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
function script_description()
return [[Reads the path of a video file from a selected text file and updates a selected media source using the new video file path. It reads the text file for changes at preditermined intervals.]]
end
function script_load()
end
function script_unload()
end
function refresh_media()
local source = o.obs_get_source_by_name(source_name)
if source == nil then return end
local settings = o.obs_data_create()
o.obs_data_set_string(settings, "local_file", VIDPATH)
o.obs_source_update(source, settings)
o.obs_data_release(settings)
o.obs_source_release(source)
updated = true
end
function cue_media()
local source = o.obs_get_source_by_name(source_name)
if source == nil then return end
o.obs_source_media_set_time(source, SKIP)
o.obs_source_release(source)
updated = false
end
function timer_callback()
if updated then
cue_media()
else
read_txt_file(TEXTFILE)
if VIDFILE ~= PVIDFILE then
refresh_media()
-- --cue_media()
end
end
end
function script_properties()
local p = o.obs_properties_create()
o.obs_properties_add_bool(p, "enable", "Enable script")
o.obs_properties_add_path(p, "theTextFile", "mAirList txt File",
o.OBS_PATH_FILE,
"Video File List (*.txt)",
nil
)
local t = o.obs_properties_add_list(p, "tsource", "Media Source", o.OBS_COMBO_TYPE_EDITABLE, o.OBS_COMBO_FORMAT_STRING)
local sources = o.obs_enum_sources()
if sources ~= nil then
for _, source in ipairs(sources) do
source_id = o.obs_source_get_id(source)
if source_id == "ffmpeg_source" then
local name = o.obs_source_get_name(source)
o.obs_property_list_add_string(t, name, name)
end
end
end
o.source_list_release(sources)
return p
end
function script_defaults(s)
o.obs_data_set_default_bool(s, "enable", false)
end
function script_update(s)
TEXTFILE = o.obs_data_get_string(s, "theTextFile")
source_name = o.obs_data_get_string(s, "tsource")
enabled = o.obs_data_get_bool(s, "enable")
if enabled then
print("Enabled")
read_txt_file(TEXTFILE)
if VIDFILE ~= PVIDFILE then
refresh_media()
end
o.timer_remove(timer_callback)
o.timer_add(timer_callback, interval)
else
print("Disabled")
o.timer_remove(timer_callback)
end
end