obs = obslua local last_update_time = 0 -- Function to get the local IP address function get_ip_address() local handle = io.popen("ipconfig") local result = handle:read("*a") handle:close() -- Search for the IPv4 address for line in result:gmatch("[^\r\n]+") do if line:match("IPv4 Address") or line:match("IPv4%-Adresse") then local ip = line:match("%d+%.%d+%.%d+%.%d+") if ip then return ip end end end return "IP address not found" end -- Variables to store the IP address and other settings local ip_address = get_ip_address() local source_name = "" local prefix = "" local suffix = ":" -- Initialization of the script in OBS function script_description() return "K_STYER's Dynamic IP Source: This script displays the current network IP address and updates a local media source with this IP." end -- Script properties function script_properties() local props = obs.obs_properties_create() obs.obs_properties_add_button(props, "button_update", "Update", function() update_source(true) end) obs.obs_properties_add_text(props, "source_name", "Media Source Name", obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "prefix", "Prefix", obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "current_ip", "Current IP Address", obs.OBS_TEXT_DEFAULT) obs.obs_properties_add_text(props, "suffix", "Suffix", obs.OBS_TEXT_DEFAULT) return props end -- Update script settings function script_update(settings) source_name = obs.obs_data_get_string(settings, "source_name") prefix = obs.obs_data_get_string(settings, "prefix") suffix = obs.obs_data_get_string(settings, "suffix") obs.obs_data_set_string(settings, "current_ip", ip_address) end -- Function to update the media source function update_source(manual) local current_time = os.time() local twelve_hours_in_seconds = 12 * 60 * 60 if manual or (current_time - last_update_time) >= twelve_hours_in_seconds then ip_address = get_ip_address() local source = obs.obs_get_source_by_name(source_name) if source then local settings = obs.obs_source_get_settings(source) local url = prefix .. ip_address .. suffix obs.obs_data_set_string(settings, "input", url) obs.obs_source_update(source, settings) obs.obs_data_release(settings) obs.obs_source_release(source) last_update_time = current_time if manual then obs.script_log(obs.LOG_INFO, "Media source updated with IP address: " .. ip_address) obs.script_log(obs.LOG_INFO, "Updated with URL: " .. prefix .. ip_address .. suffix) end else obs.script_log(obs.LOG_WARNING, "Source not found: " .. source_name) end end end -- Load and periodically update the script every 60 seconds function script_load(settings) last_update_time = obs.obs_data_get_int(settings, "last_update_time") or (os.time() - (12 * 60 * 60)) -- Set last update time to 12 hours ago to force an immediate update if no value is present obs.timer_add(function() update_source(false) end, 60000) -- Check every 60 seconds if an update is required end function script_save(settings) -- Save the last update time obs.obs_data_set_int(settings, "last_update_time", last_update_time) end function script_unload() obs.timer_remove(function() update_source(false) end) end