-- Version 3.0
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
SCENEAB = {}
SOURCEAB = {}
togg = 1
enabled = true
function toggle(x)
local xx = x - 1
return (1 - xx) + 1
end
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 = "0" end
local tsecond = t:gsub('%.', '')
local ssecond = tsecond:gsub(',', '%.')
SKIP = ssecond --SKIP = milli
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 browser 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(SOURCEAB[togg])
if source == nil then return end
local settings = o.obs_data_create()
local URL = "file:///" .. VIDPATH .. "#t=" .. SKIP
print(URL)
o.obs_data_set_string(settings, "url", URL)
o.obs_source_update(source, settings)
o.obs_data_release(settings)
o.obs_source_release(source)
cue_media()
end
function cue_media()
local targetscene = o.obs_get_source_by_name(SCENEAB[togg])
if targetscene then
o.obs_frontend_set_current_scene(targetscene)
end
o.obs_source_release(targetscene)
togg = toggle(togg)
end
function timer_callback()
read_txt_file(TEXTFILE)
if VIDFILE ~= PVIDFILE then
refresh_media()
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 sca = o.obs_properties_add_list(p, "scenea", "Scene A", o.OBS_COMBO_TYPE_EDITABLE, o.OBS_COMBO_FORMAT_STRING)
local objScene
local sceneitems
local sceneitem
local scenes = o.obs_frontend_get_scenes()
if scenes ~= nil then
for _, objScene in ipairs(scenes) do
local scene_source = o.obs_scene_from_source(objScene)
local scenename = o.obs_source_get_name(objScene)
o.obs_property_list_add_string(sca, scenename, scenename)
end
o.source_list_release(scene_source)
end
o.source_list_release(scenes)
local soa = o.obs_properties_add_list(p, "sourcea", "Scene A 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 == "browser_source" then
local name = o.obs_source_get_name(source)
o.obs_property_list_add_string(soa, name, name)
end
end
end
o.source_list_release(sources)
local scb = o.obs_properties_add_list(p, "sceneb", "Scene B", o.OBS_COMBO_TYPE_EDITABLE, o.OBS_COMBO_FORMAT_STRING)
local scenes = o.obs_frontend_get_scenes()
if scenes ~= nil then
for _, objScene in ipairs(scenes) do
local scene_source = o.obs_scene_from_source(objScene)
local scenename = o.obs_source_get_name(objScene)
o.obs_property_list_add_string(scb, scenename, scenename)
end
o.source_list_release(scene_source)
end
o.source_list_release(scenes)
local sob = o.obs_properties_add_list(p, "sourceb", "Scene B 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
local source_id = o.obs_source_get_id(source)
if source_id == "browser_source" then
local name = o.obs_source_get_name(source)
o.obs_property_list_add_string(sob, 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")
table.insert(SCENEAB, o.obs_data_get_string(s, "scenea"))
table.insert(SCENEAB, o.obs_data_get_string(s, "sceneb"))
table.insert(SOURCEAB, o.obs_data_get_string(s, "sourcea"))
table.insert(SOURCEAB, o.obs_data_get_string(s, "sourceb"))
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