Help with subtitles

Discuss your Lua playlist, album art and interface scripts.
Valchek
New Cone
New Cone
Posts: 5
Joined: 08 Mar 2024 13:47

Help with subtitles

Postby Valchek » 14 Mar 2024 15:18

Hi, i am trying to write s fairly simple script:
I want the option to be able to choose the language of the subtitles. I am looking for an option to play a video file and have let's say 3 tracks of subtitles in different languages. I want to achieve switching between the tracks(not cycle with V) like this:
Press E - the sub-track is in English
Press B - the sub-track is in Bulgarian
Press V - the sub-track is in Romanian

I read that the callback functions are gone for the newer versions of VLC so i downgreded to 2.0.5 version.
i have problems here:
vlc.var.set(input, "spu", trackNumber)
and i get this error:
lua warning: Error while running script C:\Program Files (x86)\VideoLAN\VLC\lua\extensions\toggle_subtitles.lua, function (null)(): ...86)\VideoLAN\VLC\lua\extensions\toggle_subtitles.lua:32: bad argument #-1 to 'set' (boolean expected, got number)

i can confirm that the trackNumber is 1, 2 or 3.

Here is the current code:

Code: Select all

-- "toggle_subtitles_dialog.lua" -- VLC Extension function activate() create_dialog() end function deactivate() end function create_dialog() dlg = vlc.dialog("Toggle Subtitles") -- Button for Български (Bulgarian) with hotkey B dlg:add_button("Български (B)", function() toggle_subtitle(1) end, 1, 1, 1, 1) -- Button for English with hotkey E dlg:add_button("English (E)", function() toggle_subtitle(2) end, 2, 1, 1, 1) -- Button for Românesc (Romanian) with hotkey R dlg:add_button("Românesc (R)", function() toggle_subtitle(3) end, 3, 1, 1, 1) end function toggle_subtitle(trackNumber) vlc.msg.info(trackNumber) -- Check if the track number is valid if trackNumber and type(trackNumber) == "number" then -- Set the subtitle track using vlc.var.set local input = vlc.object.input() vlc.var.set(input, "spu", trackNumber) else -- Print an error message if the track number is invalid vlc.msg.err("Invalid track number: "..tostring(trackNumber)) end end function descriptor() return { title = "Subtitles Switcher", version = "1.0", author = "Nikolay Boyadzhiev", url = "https://example.com", description = "Dialog box to toggle between subtitle tracks", capabilities = {} } end
Please any help or advise will be appriciated. I am willing to pay for someone to fix this for me asap(Revolut for example).

Valchek
New Cone
New Cone
Posts: 5
Joined: 08 Mar 2024 13:47

Re: Help with subtitles

Postby Valchek » 15 Mar 2024 15:39

Hello guys i found a workaround this and it is now working almost like expected.
I have two questions:
1. Currently I am using combination of Alt + B to switch to the 1st language, is it possible to only use "B" ?
2.How can i autostart my script when vlc is opened?

Thanks in advance.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 4 guests