This LUA should display the filename of the video being played...

NAZARUIZ

New Member
I tried to create a LUA file using chatgpt but it doesn't work and I don't why because I'm not a developer or something like that... What do you think is happening?

1. In the first few lines of the script, we are defining the global variables video_source_name and text_source_name. These variables store the names of the video and text sources in OBS that will be used.

2. Then we have the function getFileNameWithoutExtension which takes a file path and returns the name of the file without the extension. This function uses regular expressions to extract the file name and remove the extension.

3. The main function is updateTextSource. This function will be executed every time the scene is changed in OBS. First, we get the current scene using obs.obs_frontend_get_current_scene().

4. Next, we use obs.obs_scene_find_source_recursive to find the VLC video source in the current scene. If the source is found, we get the video source object with obs.obs_sceneitem_get_source .

5. Next, we create a settings object for the text font. We use obs.obs_data_create() to create the object and obs.obs_data_set_string to set the text on the settings object. The text we set is the file name without the extension obtained above.

6. We then get the text source by obs.obs_get_source_by_name using the name of the text source specified in the text_source_name variable. Next, we update the text source using obs.obs_source_update passing the settings object.

7. Finally, we free the memory of the objects and sources used by obs.obs_data_release and obs.obs_source_release .

8. The script_load function is called when the script is loaded into OBS. In this function, we register updateTextSource as a callback for the OBS_FRONTEND_EVENT_SCENE_CHANGED event. This ensures that every time the scene is changed, updateTextSource is called to update the text on the screen.

9. The script_unload function is executed when the script is unloaded. No operation is performed on this function in this case.

In short, the script looks up the VLC video source in the current scene and gets the name of the file being played. It then updates a text font with that filename (without the extension), and this is repeated each time the scene is changed.

Lua:
obs = obslua

-- Global variables
local video_source_name = "VIDEO_PLAYING"
local text_source_name = "VIDEO_TITLE"

-- Function to get the filename without extension
local function getFileNameWithoutExtension(filepath)
  local filename = string.match(filepath, "[^/\\]+$") -- Get the filename from the full path
  local filenameWithoutExtension = string.gsub(filename, "%..+$", "") -- Remove the extension from the filename
  return filenameWithoutExtension
end

-- Function to update the text source
local function updateTextSource()
  local current_scene = obs.obs_frontend_get_current_scene()
  local scene_item = obs.obs_scene_find_source_recursive(current_scene, video_source_name)

  if scene_item ~= nil then
    local video_source = obs.obs_sceneitem_get_source(scene_item)
    obs.obs_source_release(scene_item)

    local settings = obs.obs_data_create()
    local filepath = obs.obs_source_get_unversioned_file(video_source)
    local filenameWithoutExtension = getFileNameWithoutExtension(filepath)
    obs.obs_data_set_string(settings, "text", filenameWithoutExtension)

    local text_source = obs.obs_get_source_by_name(text_source_name)
    obs.obs_source_update(text_source, settings)

    obs.obs_data_release(settings)
    obs.obs_source_release(video_source)
    obs.obs_source_release(text_source)
  end

  obs.obs_source_release(current_scene)
end

-- Script load function
function script_load(settings)
  obs.obs_frontend_add_event_callback(updateTextSource, obs.OBS_FRONTEND_EVENT_SCENE_CHANGED)
end

-- Script unload function
function script_unload()
end
 
Top