[image was here]
Code: Select all
-- File name: "subtitler.lua"
-- Extension description
function descriptor()
return { title = "subtitler" ;
version = "0" ;
author = "" ;
url = 'http://forum.videolan.org/viewtopic.php?f=29&t=97791';
shortdesc = "external subtitles displayer";
description = "<b>subtitler</b><hr />"
.. "VLC Extension that displays another subtitles.";
capabilities = { "input-listener", "meta-listener" } }
end
-- Activation hook
function activate()
vlc.msg.dbg("[subtitler] activate")
create_dialog()
end
-- Deactivation hook
function deactivate()
vlc.msg.dbg("[subtitler] deactivate")
end
-- Dialog close hook
function close()
-- Deactivate this extension
vlc.msg.dbg("[subtitler] close")
vlc.deactivate()
end
-- Global variables
dlg = nil -- Dialog
lbl_subtitle = nil -- Label widget
btn_start = nil -- Button widget
-- Create the dialog
function create_dialog()
dlg = vlc.dialog("subtitler")
--subtitle = dlg:add_label("<center><h1><font face=\"courier\" color=\"red\">The first subtitle row.</font><br />The second subtitle row.</h1></center>", 1, 1, 1, 1)
sf1 = "<center style=\"font-family:verdana;font-size:40px;font-weight:bold;color:yellow;background-color:black;\">" -- subtitle format string start
sf2 = "</center>" -- subtitle format string end
lbl_subtitle = dlg:add_label(sf1.."Countdown.<br />Subtitles sample."..sf2, 1, 1, 3, 1)
w2 = dlg:add_text_input("subtitle_file.srt", 1, 2, 2, 1) -- 2. widget
w3 = dlg:add_button("Browse...", click_browse, 3, 2, 1, 1)
w4 = dlg:add_button("START", click_start,1,3,1,1) -- btn_start
w5 = dlg:add_button("REFRESH PREVIEW", click_preview,2,3,1,1) -- btn_preview
w6 = dlg:add_button("SAVE", click_save,3,3,1,1) -- btn_save
w7 = dlg:add_label("Output:",1,4,1,1)
w8 = dlg:add_dropdown(2,4,1,1) -- output
w8:add_value("OSD & this", "1")
w8:add_value("OSD", "2")
w8:add_value("this", "3")
w9 = dlg:add_dropdown(3,4,1,1) -- osd_position
w9:add_value("OSD top", "1")
w9:add_value("OSD center", "2")
w9:add_value("OSD bottom", "3")
w10 = dlg:add_label("Font encoding:",1,5,1,1)
w11 = dlg:add_dropdown(2,5,2,1) -- encode
w11:add_value("Central European Windows-1250", "Windows-1250")
w11:add_value("Central European ISO-8859-2 (Latin 2)", "ISO-8859-2")
w11:add_value("Unicode UTF-8", "UTF-8")
w11:add_value("more ...", "more")
w12 = dlg:add_label("Font type:",1,6,1,1)
w13 = dlg:add_dropdown(2,6,2,1) -- font
w13:add_value("Verdana", "verdana")
w13:add_value("Arial", "arial")
w13:add_value("Courier", "courier")
w13:add_value("more ...", "more")
w14 = dlg:add_label("Font size [px]:",1,7,1,1)
w15 = dlg:add_text_input("40",2,7,1,1)
w16 = dlg:add_check_box("bold",true,2,8,1,1) -- font_weight
w17 = dlg:add_label("Font color (html standard):",1,9,1,1)
w18 = dlg:add_text_input("yellow",2,9,1,1)
w19 = dlg:add_label("Background color (html standard - color name or #rrggbb):",1,10,2,1)
w20 = dlg:add_text_input("#000000",3,10,1,1)
w21 = dlg:add_label("Background type:",1,11,2,1)
w22 = dlg:add_dropdown(3,11,1,1) -- bg_type
w22:add_value("Solid", "solid")
w22:add_value("Outline", "outline")
w23 = dlg:add_label("Background size [px]:",1,12,2,1)
w24 = dlg:add_text_input("0",3,12,1,1)
end
function click_start()
-- clear the dialog box
--[[ how to construct the name of indexed variable? Is it possible to convert a string into variable?
for i=2,24,1 do
if "w"..i then dlg:del_widget("w"..i) end
end
--]]
if w2 then dlg:del_widget(w2) end
if w3 then dlg:del_widget(w3) end
if w4 then dlg:del_widget(w4) end
if w5 then dlg:del_widget(w5) end
if w6 then dlg:del_widget(w6) end
if w7 then dlg:del_widget(w7) end
if w8 then dlg:del_widget(w8) end
if w9 then dlg:del_widget(w9) end
if w10 then dlg:del_widget(w10) end
if w11 then dlg:del_widget(w11) end
if w12 then dlg:del_widget(w12) end
if w13 then dlg:del_widget(w13) end
if w14 then dlg:del_widget(w14) end
if w15 then dlg:del_widget(w15) end
if w16 then dlg:del_widget(w16) end
if w17 then dlg:del_widget(w17) end
if w18 then dlg:del_widget(w18) end
if w19 then dlg:del_widget(w19) end
if w20 then dlg:del_widget(w20) end
if w21 then dlg:del_widget(w21) end
if w22 then dlg:del_widget(w22) end
if w23 then dlg:del_widget(w23) end
if w24 then dlg:del_widget(w24) end
w2 = nil
w3 = nil
w4 = nil
w5 = nil
w6 = nil
w7 = nil
w8 = nil
w9 = nil
w10 = nil
w11 = nil
w12 = nil
w13 = nil
w14 = nil
w15 = nil
w16 = nil
w17 = nil
w18 = nil
w19 = nil
w20 = nil
w21 = nil
w22 = nil
w23 = nil
w24 = nil
if lbl_subtitle then
dlg:del_widget(lbl_subtitle)
lbl_subtitle = dlg:add_label("",1,1,3,1)
end
dlg:update()
-- countdown as an example of subtitles in action
for i=10,1,-1 do
lbl_subtitle:set_text(sf1..i..sf2)
dlg:update()
for j=0,1,.5 do
vlc.osd.message(i,channel1)
vlc.misc.mwait(vlc.misc.mdate() + 500000)
end
dlg:del_widget(lbl_subtitle)
lbl_subtitle = dlg:add_label("",1,1,3,1)
dlg:update()
vlc.osd.message("",channel1)
vlc.misc.mwait(vlc.misc.mdate() + 1000000)
end
lbl_subtitle:set_text(sf1.."& Press the button<br />to repeat the countdown :o)"..sf2)
w2 = dlg:add_button("START", click_start, 1, 2, 1, 1)
end
function click_preview()
end
function click_save()
end
function click_browse()
end
- transparent (invisible) window frame of dialog box of running subtitles
- font encoding (charset, code page)
- font format - proper solid/outline
- graphical color palettes to choose or mix desired font/background colors
- immediate automatic visual changes of preview sample =>
- to replace "Refresh preview" button by "Load defaults" button to load initial default settings or to copy settings from internal subtitles.
I will try to make the working Lua extension but really I am not sure about the usable result because of limitations of Lua VLC scripting. If I learn how to I will do the following:
- to load settings from external configuration file or to load defaults settings if the configuration file does not exist
- to save (the "Save" button) new settings in configuration file
- after start (the "Start" button) to open a subtitles text file (srt) and to parse it - arrays (start time, stop time, subtitle text)
- to think out an algorithm to display subtitles in right times - show/hide. I am thinking of checking and comparing times in certain rate - check rate - every 1/2 second to compare actual playback position with subtitle times stored in array variables.
- font encoding?
- scripting speed can be critical.
If there is a similar script already available that I do not know about please let me know so I do not waste a time.
And if you find these ideas useful your help is welcome and needed - advice, tips, algorithms or straight a working result