[Extension] Time

Discuss your Lua playlist, album art and interface scripts.
mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

[Extension] Time

Postby mederi » 31 Jan 2012 20:29

I have found an interesting Lua script called "When will this be over?"
I have altered the script a bit to display 24-hour format and a bit longer on screen (5 seconds).

Code: Select all

local systemHour = os.date("%H") local endingHour = math.floor((((systemSecond + remainingSecond) / 60 + (systemMinute + remainingMinute)) / 60 + systemHour + remainingHour) % 24) local outputString = string.format("%02d:%02d:%02d", endingHour, endingMinute, endingSecond) vlc.osd.message("Show will be done at " .. outputString,channel1,"top-left",5000000)
Duration and positioning of OSD text works in VLC 1.2.0 and over.
How to display OSD text longer in VLC 1.1.x? A workaround?
Is it already possible to add a Hotkey to trigger an extension (one on/off key)?
Thanks

--- EDIT (12.3.2012) ---
Topic's name changed: old name - "VLC Extension: When will this be over?", new name - "VLC extension: Time".
Last edited by mederi on 12 Mar 2012 14:16, edited 1 time in total.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 31 Jan 2012 20:37

No, only in 2.0 it is able to do so.
Not possible to add a Hotkey, no.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC Extension: When will this be over?

Postby mederi » 01 Feb 2012 15:09

You liar :) I have just found out at least how to make duration for osd.message() in VLC 1.1.x

Code: Select all

for i=1,5,.5 do vlc.osd.message("Hello!\n" .. 6-math.floor(i)) vlc.misc.mwait(vlc.misc.mdate() + 500000) end

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 01 Feb 2012 16:14

This is cheating :)
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

VLC Extension: TIME

Postby mederi » 28 Feb 2012 16:45

Here is my minimalist extension script to display actual time in a playing video. Unfortunately it does not work in new VLC2 due to disabled vlc.misc, so please use it only within VLC1.1.x.

Code: Select all

-- file: "time.lua" -- minimalist extension script to display actual time in a video function descriptor() return {title = "Time"} end function activate() while vlc.input.is_playing() do -- time loop works until video is stopped (mostly) local systemTime = os.date("%H:%M:%S") -- reads and formats OS time vlc.osd.message(systemTime) -- displays time on a screen in a video vlc.misc.mwait(vlc.misc.mdate() + 500000) -- waits half second before next time's update end fail() -- undefined function to cause error to KILL the running script end
A proper full structure of extension scripts would not make it any better here. The running loop ignores everything until the video is stopped (mostly). I have not found a better way to control the running loop yet. I have unsuccessfully tried to control it using a dialog box with a STOP button. It has not worked.

Simply VLC Lua extensions have not been designed for this purpose. However, it could be the best time to improve and enhance scripting abilities within new VLC2 to add some dynamics.

Perhaps I could make some fully-featured time extension with a dialog box with various time options to choose from (actual time, actual playback position, duration, formatting, ...).

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 28 Feb 2012 19:16

I will try to improve VLC extensions soon.

However, vlc.misc.mwait(vlc.misc.mdate() + 500000) is really a hack.

What about defining a time in vlc.osd.message?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC Extension: When will this be over?

Postby mederi » 29 Feb 2012 20:59

Hello!
vlc.osd.message() with defined time is good for one-off static information. When I use it in a loop trying to display the running time then the whole CPU power is taken and VLC is blocked. I do not know how to replace the vlc.misc.mwait() as a not-busy-wait. It is quite useful for me.

Code: Select all

-- file: "time2.lua" -- minimalist extension script to display actual time in a video function descriptor() return {title = "time2"} end function activate() ---------- if not vlc.misc then -- we are in new VLC2 without vlc.misc vlc.msg.info("We are in new VLC2") channel = vlc.osd.channel_register() --while vlc.input.is_playing() do local systemTime = os.date("%H:%M:%S") vlc.osd.message(systemTime,channel,"top-left",5000000) -- 5 seconds --end --vlc.osd.channel_clear(channel) else -- we are in older VLC supporting vlc.misc vlc.msg.info("We are in old VLC1") ---------- while vlc.input.is_playing() do -- time loop works until video is stopped (mostly) local systemTime = os.date("%H:%M:%S") -- reads and formats OS time vlc.osd.message(systemTime) -- displays time on a screen in a video vlc.misc.mwait(vlc.misc.mdate() + 500000) -- waits half second before next time's update end fail() -- undefined function to cause error to KILL the running script end end
So far I have not found out how to use vlc.var.add_callback() that would probably stop my headaches :)
http://trac.videolan.org/vlc/ticket/6169
One way to wait on an event would be to use vlc.var.add_callback on the playback time variable.
There is an example of use of vlc.var.add_callback() in hotkeys.lua. You'd probably want to use something like vlc.var.add_callback(vlc.object.input(), "time", your_function, your_data)
If you need to wait for events, then implement correct event handling.

Code: Select all

function activate() vlc.var.add_callback(vlc.object.input(), "time", your_function, your_data) end function your_function(variable_name, old_value, new_value, data) ??? end
How to use it to wait for a while? How to use it to check whether it is already the right time for action (to display/clear OSD text)? Studying of "hotkeys.lua" interface script does not help me very much.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 01 Mar 2012 11:29

Then callback on position change.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mineirtoikd
New Cone
New Cone
Posts: 2
Joined: 01 Mar 2012 19:45

Re: VLC Extension: When will this be over?

Postby mineirtoikd » 01 Mar 2012 23:59

This is for position change. Please correct me if I am wrong because I am very beginner.

Code: Select all

function descriptor() return { ... ... capabilities = { "input-listener", "meta-listener", "playing-listener" } } end function position_change(var, old, new, data) vlc.osd.message("Var:" .. tostring(var .. '\n') .. "Old:" .. tostring(old .. '\n') .. "New:" .. tostring(new .. '\n') .. "Data:" .. tostring(data)) end function activate() vlc.var.add_callback(vlc.object.input(), "position", position_change) end function deactivate() vlc.var.del_callback(vlc.object.input(), "position", position_change) end
I am not sure if i am using the callback functions correctly.

Sorry for bad English.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 02 Mar 2012 02:44

It should be fine, indeed.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC Extension: When will this be over?

Postby mederi » 02 Mar 2012 17:26

Seems that the playback time is not an event triggering a callback function. It does not work:

Code: Select all

-- test-callback-input.time.lua -- function descriptor() return {title = "test-callback-input.time";} end function time_change(var , old, new, data) --tt=os.clock() --if tt>(t+0.5) then --t=tt vlc.osd.message(tostring(var)..'\n'..tostring(old)..'\n'..tostring(new)..'\n'..tostring(data),channel1,"top-left",5000000) --end end function activate() --t=os.clock() vlc.var.add_callback(vlc.object.input(), "time", time_change) end function deactivate() vlc.var.del_callback(vlc.object.input(), "time", time_change) end function close() deactivate() end
The position reacts only if a playback position is changed by a mouse on a time slider on a control panel.

Code: Select all

-- test-callback-input.position.lua -- function descriptor() return {title = "test-callback-input.position";} end function position_change(var, old, new, data) vlc.osd.message(tostring(var)..'\n'..tostring(old)..'\n'..tostring(new)..'\n'..tostring(data),channel1,"top-left",5000000) end function activate() vlc.var.add_callback(vlc.object.input(), "position", position_change) end function deactivate() vlc.var.del_callback(vlc.object.input(), "position", position_change) end function close() deactivate() end
I really would need something like:
misc.timer(callback)
A callback function should work in a loop with a certain time pause among iterations. The rest of a script should work normally along with a looping callback function with an ability to stop the looping callback function for example by an event or by a button in a dialog box; some kind of timer killer.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 02 Mar 2012 19:02

timers and polling encourage incorrect programming.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC Extension: When will this be over?

Postby mederi » 03 Mar 2012 17:11

Jean-Baptiste, you probably want to train me to detective :) O.K. I went again through older forum topics and found it (here):
>>> Input variables <<<

Code: Select all

-- time.lua -- VLC extension -- function descriptor() return {title = "time"; capabilities = {"input-listener"} } end function activate() local input = vlc.object.input() if input then vlc.var.add_callback(input, "intf-event", input_event_handler, "Hello world!") else vlc.deactivate() end end function deactivate() --if vlc.input.is_playing() then local input = vlc.object.input() if input then vlc.var.del_callback(input, "intf-event", input_event_handler, "Hello world!") end end function input_changed() vlc.deactivate() end function input_event_handler(var, old, new, data) --vlc.osd.message(tostring(var)..'\n'..tostring(old)..'\n'..tostring(new)..'\n'..tostring(data)) local systemTime = os.date("%H:%M:%S") -- reads and formats OS time vlc.osd.message(systemTime) -- displays time on a screen in a video --vlc.msg.info(systemTime) end
Now I can also prepare some dialog box with some more options to choose from.

Great things can start to happen 8)

--- EDIT --- 6.3.2012 --- script update, bug: "input-listener" looks for meta_changed()
Last edited by mederi on 06 Mar 2012 14:26, edited 3 times in total.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC Extension: When will this be over?

Postby Jean-Baptiste Kempf » 03 Mar 2012 19:11

Cool. We need to document this.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

TYPEWRITER

Postby mederi » 06 Mar 2012 14:38

TYPEWRITER :) - a VLC2 extension script to test vlc.osd.message() capabilities => 2 bugs in positioning: "center" and "right"

Code: Select all

-- typewriter.lua -- VLC2 extension -- function descriptor() return {title = "typewriter";} end function activate() local input = vlc.object.input() if input then vlc.var.add_callback(input, "intf-event", input_event_handler, "Hello world!") create_dialog() else vlc.deactivate() end end function deactivate() local input = vlc.object.input() if input then vlc.var.del_callback(input, "intf-event", input_event_handler, "Hello world!") end end function close() vlc.deactivate() end function input_event_handler(var, old, new, data) vlc.osd.message(w1:get_text(),channel1,"top-left") vlc.osd.message(w2:get_text(),channel2,"top") vlc.osd.message(w3:get_text(),channel3,"top-right") vlc.osd.message(w4:get_text(),channel4,"left") vlc.osd.message(w5:get_text(),channel5,"center") -- bug: top-left instead vlc.osd.message(w6:get_text(),channel6,"right") -- bug: center instead vlc.osd.message(w7:get_text(),channel7,"bottom-left") vlc.osd.message(w8:get_text(),channel8,"bottom") vlc.osd.message(w9:get_text(),channel9,"bottom-right") end function create_dialog() w = vlc.dialog("typewriter") w1 = w:add_text_input("",1,1,1,1) w2 = w:add_text_input("",2,1,1,1) w3 = w:add_text_input("",3,1,1,1) w4 = w:add_text_input("",1,2,1,1) w5 = w:add_text_input("",2,2,1,1) w6 = w:add_text_input("",3,2,1,1) w7 = w:add_text_input("",1,3,1,1) w8 = w:add_text_input("",2,3,1,1) w9 = w:add_text_input("",3,3,1,1) w10 = w:add_button("CLEAR", click_CLEAR,1,4,1,1) channel1 = vlc.osd.channel_register() channel2 = vlc.osd.channel_register() channel3 = vlc.osd.channel_register() channel4 = vlc.osd.channel_register() channel5 = vlc.osd.channel_register() channel6 = vlc.osd.channel_register() channel7 = vlc.osd.channel_register() channel8 = vlc.osd.channel_register() channel9 = vlc.osd.channel_register() end function click_CLEAR() w1:set_text("") w2:set_text("") w3:set_text("") w4:set_text("") w5:set_text("") w6:set_text("") w7:set_text("") w8:set_text("") w9:set_text("") end
--- EDIT ---
Ticket #6326: capabilities = {"input-listener"}; vlc.osd.message()

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC Extension: When will this be over?

Postby mederi » 07 Mar 2012 13:47

to Jean-Baptiste:
I still think that we should have some kind of timer available to execute some callback functions at desired frequency and the ability to stop it. Something like: id=vlc.timer(callback, 0.1); and then after some event or after certain number of calls: vlc.timer.stop(id).

Input event responds luckily 4-5 times a second. So far I have used this only as a clock to read time value for the running time displayed in video. I will use input events in external subtitler I plan to do. What if I would like to show the running time in a dialog box that should work also without any loaded and playing film or song? Stop-watch updated every 100 ms (10 times per second), why not? The timer is useful and have a certain purpose.

The more functions script writers will have to choose from, the more new ideas and scripts will be written.
Thanks

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC extension: Time

Postby mederi » 12 Mar 2012 15:10

Hello!
I am happy I can finally share my complete script also with dialog box. Before uploading it to official website for VLC addons I would like you to test it first. I have also a couple of issues to discuss.

VLC extension: Time
Image

Code: Select all

-- time.lua -- VLC extension script-- -- defaults time_format = "[T]" -- [T]-ime, [O]-ver, [E]-lapsed, [D]-uration, [R]-remaining osd_position = "top-right" -- predefined time format patterns time_formats = {"[T]", "[T] >> [O]", "[E] / [D]", "-[R] / [D]", "-[R] ([T])"} function descriptor() return { title = "Time"; version = "1.0"; author = ""; url = 'http://forum.videolan.org/viewtopic.php?f=29&t=97639#p332364'; shortdesc = "Time displayer"; description = "<div style=\"background-color:lightgreen;\"><b>Time</b> is VLC extension (extension script \"time.lua\") to display running time on the screen in a playing video.</div>"; capabilities = {"input-listener"} } end function activate() input_callback("add") create_dialog() end function deactivate() input_callback("delete") end function close() vlc.deactivate() end function input_changed() input_callback("add") end function input_callback(action) local input = vlc.object.input() if input and action=="add" then vlc.var.add_callback(input, "intf-event", input_event_handler, "Hello world!") elseif input and action=="delete" then vlc.var.del_callback(input, "intf-event", input_event_handler, "Hello world!") end end t=0 function input_event_handler(var, old, new, data) tt=os.clock() if tt>=(t+.5) then -- OSD update approximately 2 times per second instead of 4-5 times t=tt --vlc.osd.message(tostring(var)..'\n'..tostring(old)..'\n'..tostring(new)..'\n'..tostring(data)) --local systemTime = os.date("%H:%M:%S") -- reads and formats OS time if time_format~=nil or time_format~="" then osd_output = decode_time_format() vlc.osd.message(osd_output, channel1, osd_position) -- displays time on the screen in a video end --vlc.msg.info(systemTime) end end function decode_time_format() local input = vlc.object.input() local elapsed_time = vlc.var.get(input, "time") --local duration = vlc.var.get(input, "length") local duration = vlc.input.item():duration() local systemHour = os.date("%H") local systemMinute = os.date("%M") local systemSecond = os.date("%S") local elapsedHour = math.floor(elapsed_time / 3600) local elapsedMinute = math.floor((elapsed_time % 3600) / 60) local elapsedSecond = math.floor(elapsed_time % 60) if duration>0 then local durationHour = math.floor(duration / 3600) local durationMinute = math.floor((duration % 3600) / 60) local durationSecond = math.floor(duration % 60) remaining_time = duration - elapsed_time local remainingHour = math.floor(remaining_time / 3600) local remainingMinute = math.floor((remaining_time % 3600) / 60) local remainingSecond = math.floor(remaining_time % 60) local endingSecond = math.floor((systemSecond + remainingSecond) % 60) local endingMinute = math.floor(((systemSecond + remainingSecond) / 60 + (systemMinute + remainingMinute)) % 60) local endingHour = math.floor((((systemSecond + remainingSecond) / 60 + (systemMinute + remainingMinute)) / 60 + systemHour + remainingHour) % 24) duration = string.format("%02d:%02d:%02d", durationHour, durationMinute, durationSecond) remaining_time = string.format("%02d:%02d:%02d", remainingHour, remainingMinute, remainingSecond) ending_time = string.format("%02d:%02d:%02d", endingHour, endingMinute, endingSecond) else duration = "--:--" remaining_time = "--:--" ending_time = "--:--" end local elapsed_time = string.format("%02d:%02d:%02d", elapsedHour, elapsedMinute, elapsedSecond) --local system_time = os.date("%H:%M:%S") local system_time = systemHour..":"..systemMinute..":"..systemSecond local osd_output = string.gsub(time_format, "%[E%]", elapsed_time) local osd_output = string.gsub(osd_output, "%[T%]", system_time) local osd_output = string.gsub(osd_output, "%[D%]", duration) local osd_output = string.gsub(osd_output, "%[R%]", remaining_time) local osd_output = string.gsub(osd_output, "%[O%]", ending_time) return osd_output end function create_dialog() w = vlc.dialog("TIME") --w1 = w:add_label("Time format: \\ Position:",1,1,2,1) w1 = w:add_label("<b>Time format:</b>",1,1,1,1) w01 = w:add_label("<b>\\ Position:</b>",2,1,1,1) w2 = w:add_dropdown(3,1,1,1) w2:add_value("top-left", 1) w2:add_value("top", 2) w2:add_value("top-right", 3) w2:add_value("left", 4) w2:add_value("center", 5) w2:add_value("right", 6) w2:add_value("bottom-left", 7) w2:add_value("bottom", 8) w2:add_value("bottom-right", 9) w2:set_text(osd_position) w3 = w:add_text_input(time_format,1,2,3,1) w4 = w:add_dropdown(1,3,2,1) w4:add_value("", 1) for i=1,#time_formats do w4:add_value(time_formats[i], i+1) end w4:set_text("") w10 = w:add_button("START", click_START,1,4,1,1) w11 = w:add_button("STOP", click_STOP,2,4,1,1) w12 = w:add_button(">> PUT^IN", click_PUTIN,3,3,1,1) w13 = w:add_button("HELP", click_HELP,3,4,1,1) end function click_STOP() time_format = "" end function click_START() time_format = w3:get_text() osd_position = w2:get_text() end function click_PUTIN() w3:set_text(w4:get_text()) w4:set_text("") w:update() end function click_HELP() local help_text="" .."<div style=\"background-color:lightgreen;\"><b>Time</b> is VLC extension (extension script \"time.lua\") to display running time on the screen in a playing video.</div>" .."<hr />" .."<center><b><a style=\"background-color:#FF7FAA;\">&nbsp;Instructions&nbsp;</a></b></center>" .."<b><a style=\"background-color:#FF7FAA;\">1.)</a></b> Choose a desired <b><a style=\"background-color:lightblue;\">position</a></b> from the drop-down menu.<br />" .."<b><a style=\"background-color:#FF7FAA;\">2.)</a></b> In <b><a style=\"background-color:lightblue;\">time format</a></b> input field write some time pattern containing time tags. The list of available tags is below.<br />" .."You can use predefined pattern from the drop-down menu. Choose one and put it in the time format field by pressing <b><nobr><a style=\"background-color:silver;\">[ >> PUT^IN ]</a></nobr></b> button.<br />" .."<b><a style=\"background-color:#FF7FAA;\">3.)</a></b> Press <b><nobr><a style=\"background-color:silver;\">[ START ]</a></nobr></b> button for changes to take effect.<br /><br />" .."<b>Following <a style=\"background-color:#FF7FAA;\">time tags</a> can be used within time format pattern:</b>" .."<div style=\"background-color:#FF7FAA;\">" .."<b>&nbsp;[T]</b> - actual system time;<br />" .."<b>&nbsp;[O]</b> - time when video will be over;<br />" .."<b>&nbsp;[E]</b> - elapsed time (current playback position);<br />" .."<b>&nbsp;[R]</b> - remaining time;<br />" .."<b>&nbsp;[D]</b> - duration (length);</div>" .." > They are automatically replaced with actual time values on the screen.<br />" .." > If duration value is not available then [D], [R], [O] is replaced with \"--:--\".<br />" .." > You can also use some short descriptions or put some delimiters among time tags.<br />" .."<div style=\"background-color:#FFFF7F;\"><b>OSD text format</b> can be customised within internal VLC settings:<br />" .."Tools > Preferences > (Show settings - Simple) > Subtitles / OSD<br />" .."Tools > Preferences > (Show settings - All) > +Video > +Subtitles / OSD > -Text renderer<br />" .."Do not forget to Save and restart VLC for changes to take effect!</div>" .."<hr />" .."<div style=\"background-color:lightblue;\">" .."<b>Homepage:</b> <a href=\"http://forum.videolan.org/viewtopic.php?f=29&t=97639#p332364\">VLC extension: Time</a><br />" .."<b>Forum:</b> <a href=\"http://forum.videolan.org/viewforum.php?f=29\">Scripting VLC in Lua</a><br />" .."Please, visit us and bring some new ideas.<br />" .."Learn how to write own scripts and share them with us.<br />" .."Help to build happy VLC community :o)</div>" .."<pre> www<br />" .." (. .)<br />" .."-ooo-(_)-ooo-</pre>" w5=w:add_html(help_text,1,5,3,1) w14 = w:add_button("HELP (x)", click_HELPx,3,4,1,1) w:update() end function click_HELPx() w:del_widget(w5) w:del_widget(w14) w5=nil w14=nil w:update() end
When stopping playback and then playing again, Messages window reports an error:
lua warning: Error while running script ...\lua\extensions\time.lua, function meta_changed() not found

In Time's dialog box - the drop-down menu with [ >> PUT^IN ] - pressing the button should also set the first empty item in drop-down menu. This setting works while initiating dialog box - please see the third option "top-right" in position drop down menu. VLC1 works like a charm with that but does not support positioning.

I would like to use some proper timer instead of using hacks or workarounds. Yes, the timer and polling that encourage incorrect programming :) But in this case it would be correct programming.

Perhaps this script could be good enough to be included in official VLC release to attract and encourage new script writers. The script should be revised and corrected by VLC developers if necessary.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC extension: Time

Postby mederi » 19 Mar 2012 16:47

A week later:
Everybody is happy, nobody cares :)

As I have found out, there is already a "Marquee" filter in VLC that is able to display running actual time: Re: Please help me to add date/time marquee
I would like to ask also here. Is it possible to use Marquee filter in extension script? I mean to control Marquee filter - on/off, text string, position, font size, color - from some dialog box of extension script.

At least I have learnt how to make own "Marquee" :D
All right, then, it goes to addons website anyway.

And let me introduce to you my next VLC extension script: Sampler.

--- EDIT (23.3.2012) ---
Time: http://addons.videolan.org/content/show ... ent=149618
Time (lite): http://addons.videolan.org/content/show ... ent=149619
Last edited by mederi on 23 Mar 2012 19:04, edited 3 times in total.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC extension: Time

Postby Jean-Baptiste Kempf » 20 Mar 2012 10:58

video filters are not exposed, I think
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC extension: Time

Postby mederi » 01 Apr 2012 13:15


Ashada
New Cone
New Cone
Posts: 2
Joined: 23 May 2012 20:17

Re: VLC extension: Time

Postby Ashada » 23 May 2012 20:30

Sup Thx for your script.
I didn't know how to make an extension to VLC but thx to you I did what I wanted to do.
I'll buy you some cookies in RL if we ever meet.

Your scirpt was lacking one function and it was total playlist duration.
I was pissed since the devs don't care about such function as seen here: viewtopic.php?f=7&t=96760
so I made it and integrated with your script.
I'm going to release my changes under WTFPL since you didn't specify a license for your code.
Teh code

Code: Select all

-- time.lua -- VLC extension -- --[[ INSTALLATION: Put the file in the VLC subdir /lua/extensions, by default: * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\ * Windows (current user): %APPDATA%\VLC\lua\extensions\ * Linux (all users): /usr/share/vlc/lua/extensions/ * Linux (current user): ~/.local/share/vlc/lua/extensions/ * Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/ (create directories if they don't exist) Restart the VLC. Then you simply use the extension by going to the "View" menu and selecting it. --]] -- defaults time_format = "[PLD]" -- [T]-ime, [O]-ver, [E]-lapsed, [D]-uration, [R]-remaining osd_position = "top-right" -- predefined time format patterns time_formats = {"[T]", "[T] >> [O]", "[E] / [D]", "-[R] / [D]", "-[R] ([T])", "[PLD]"} function descriptor() return { title = "Time"; version = "1.0"; author = "lubozle"; url = 'http://addons.videolan.org/content/show.php?content=149618'; shortdesc = "Time displayer"; description = "<div style=\"background-color:lightgreen;\"><b>Time</b> is VLC extension (extension script \"time.lua\") that displays running time on the screen in a playing video.</div>"; capabilities = {"input-listener"} } end function activate() input_callback("add") create_dialog() end function deactivate() input_callback("del") end function close() vlc.deactivate() end function input_changed() input_callback("toggle") end callback=false function input_callback(action) -- action=add/del/toggle if (action=="toggle" and callback==false) then action="add" elseif (action=="toggle" and callback==true) then action="del" end local input = vlc.object.input() if input and callback==false and action=="add" then callback=true vlc.var.add_callback(input, "intf-event", input_events_handler, "Hello world!") elseif input and callback==true and action=="del" then callback=false vlc.var.del_callback(input, "intf-event", input_events_handler, "Hello world!") end end t=0 function input_events_handler(var, old, new, data) tt=os.clock() if tt>=(t+.5) then -- OSD update approximately 2 times per second instead of 4-5 times t=tt --vlc.osd.message(tostring(var)..'\n'..tostring(old)..'\n'..tostring(new)..'\n'..tostring(data)) --local systemTime = os.date("%H:%M:%S") -- reads and formats OS time if time_format~=nil or time_format~="" then osd_output = decode_time_format() vlc.osd.message(osd_output, channel1, osd_position) -- displays time on the screen in a video end --vlc.msg.info(systemTime) end end function dur_to_time(duration) if duration>0 then local durationHour = math.floor(duration / 3600) local durationMinute = math.floor((duration % 3600) / 60) local durationSecond = math.floor(duration % 60) return durationHour, durationMinute, durationSecond else return -1 end end function playlist_duration() local sum = 0 local play_list = vlc.playlist.get("playlist",false) for k, video in pairs(play_list.children) do if video.duration ~= -1 then sum = sum + video.duration end end local h, m, s = dur_to_time(sum) return tostring(string.format("%02d:%02d:%02d", h, m, s)) end function decode_time_format() local input = vlc.object.input() local elapsed_time = vlc.var.get(input, "time") --local duration = vlc.var.get(input, "length") local duration = vlc.input.item():duration() local systemHour = os.date("%H") local systemMinute = os.date("%M") local systemSecond = os.date("%S") local elapsedHour = math.floor(elapsed_time / 3600) local elapsedMinute = math.floor((elapsed_time % 3600) / 60) local elapsedSecond = math.floor(elapsed_time % 60) if duration>0 then local durationHour = math.floor(duration / 3600) local durationMinute = math.floor((duration % 3600) / 60) local durationSecond = math.floor(duration % 60) remaining_time = duration - elapsed_time local remainingHour = math.floor(remaining_time / 3600) local remainingMinute = math.floor((remaining_time % 3600) / 60) local remainingSecond = math.floor(remaining_time % 60) local endingSecond = math.floor((systemSecond + remainingSecond) % 60) local endingMinute = math.floor(((systemSecond + remainingSecond) / 60 + (systemMinute + remainingMinute)) % 60) local endingHour = math.floor((((systemSecond + remainingSecond) / 60 + (systemMinute + remainingMinute)) / 60 + systemHour + remainingHour) % 24) duration = string.format("%02d:%02d:%02d", durationHour, durationMinute, durationSecond) remaining_time = string.format("%02d:%02d:%02d", remainingHour, remainingMinute, remainingSecond) ending_time = string.format("%02d:%02d:%02d", endingHour, endingMinute, endingSecond) else duration = "--:--" remaining_time = "--:--" ending_time = "--:--" end local elapsed_time = string.format("%02d:%02d:%02d", elapsedHour, elapsedMinute, elapsedSecond) --local system_time = os.date("%H:%M:%S") local system_time = systemHour..":"..systemMinute..":"..systemSecond local osd_output = string.gsub(time_format, "%[E%]", elapsed_time) local osd_output = string.gsub(osd_output, "%[T%]", system_time) local osd_output = string.gsub(osd_output, "%[D%]", duration) local osd_output = string.gsub(osd_output, "%[R%]", remaining_time) local osd_output = string.gsub(osd_output, "%[O%]", ending_time) local osd_output = string.gsub(osd_output, "%[PLD%]", playlist_duration()) return osd_output end function create_dialog() w = vlc.dialog("Time") --w1 = w:add_label("Time format: \\ Position:",1,1,2,1) w1 = w:add_label("<b>Time format:</b>",1,1,1,1) w01 = w:add_label("<b>\\ Position:</b>",2,1,1,1) w2 = w:add_dropdown(3,1,1,1) w2:add_value("top-left", 1) w2:add_value("top", 2) w2:add_value("top-right", 3) w2:add_value("left", 4) w2:add_value("center", 5) w2:add_value("right", 6) w2:add_value("bottom-left", 7) w2:add_value("bottom", 8) w2:add_value("bottom-right", 9) w2:set_text(osd_position) w3 = w:add_text_input(time_format,1,2,3,1) w4 = w:add_dropdown(1,3,2,1) w4:add_value("", 1) for i=1,#time_formats do w4:add_value(time_formats[i], i+1) end w4:set_text("") w10 = w:add_button("START", click_START,1,4,1,1) w11 = w:add_button("STOP", click_STOP,2,4,1,1) w12 = w:add_button(">> PUT^IN", click_PUTIN,3,3,1,1) w13 = w:add_button("HELP", click_HELP,3,4,1,1) end function click_STOP() time_format = "" end function click_START() time_format = w3:get_text() osd_position = w2:get_text() end function click_PUTIN() w3:set_text(w4:get_text()) w4:set_text("") w:update() end function click_HELP() local help_text="" .."<div style=\"background-color:lightgreen;\"><b>Time</b> is VLC extension (extension script \"time.lua\") that displays running time on the screen in a playing video.</div>" .."<hr />" .."<center><b><a style=\"background-color:#FF7FAA;\">&nbsp;Instructions&nbsp;</a></b></center>" .."<b><a style=\"background-color:#FF7FAA;\">1.)</a></b> Choose a desired <b><a style=\"background-color:lightblue;\">position</a></b> from the drop-down menu.<br />" .."<b><a style=\"background-color:#FF7FAA;\">2.)</a></b> In <b><a style=\"background-color:lightblue;\">time format</a></b> input field write some time pattern containing time tags. The list of available tags is below.<br />" .."You can use predefined pattern from the drop-down menu. Choose one and put it in the time format field by pressing <b><nobr><a style=\"background-color:silver;\">[ >> PUT^IN ]</a></nobr></b> button.<br />" .."<b><a style=\"background-color:#FF7FAA;\">3.)</a></b> Press <b><nobr><a style=\"background-color:silver;\">[ START ]</a></nobr></b> button for changes to take effect.<br /><br />" .."<b>Following <a style=\"background-color:#FF7FAA;\">time tags</a> can be used within time format pattern:</b>" .."<div style=\"background-color:#FF7FAA;\">" .."<b>&nbsp;[T]</b> - actual system time;<br />" .."<b>&nbsp;[O]</b> - time when video will be over;<br />" .."<b>&nbsp;[E]</b> - elapsed time (current playback position);<br />" .."<b>&nbsp;[R]</b> - remaining time;<br />" .."<b>&nbsp;[D]</b> - duration (length);<br />" .."<b>&nbsp;[PLD]</b> - playlist duration (length);</div>" .." > They are automatically replaced with actual time values on the screen.<br />" .." > If duration value is not available then [D], [R], [O] is replaced with \"--:--\".<br />" .." > You can also use some short descriptions or put some delimiters among time tags.<br />" .."<div style=\"background-color:#FFFF7F;\"><b>OSD text format</b> can be customised within internal VLC settings:<br />" .."Tools > Preferences > (Show settings - Simple) > Subtitles / OSD<br />" .."Tools > Preferences > (Show settings - All) > +Video > +Subtitles / OSD > -Text renderer<br />" .."Do not forget to Save and restart VLC for changes to take effect!</div>" .."<hr />" .."<div style=\"background-color:lightblue;\">" .."<b>Homepage:</b> <a href=\"http://forum.videolan.org/viewtopic.php?f=29&t=97639#p332364\">VLC extension: Time</a><br />" .."<b>Forum:</b> <a href=\"http://forum.videolan.org/viewforum.php?f=29\">Scripting VLC in Lua</a><br />" .."Please, visit us and bring some new ideas.<br />" .."Learn how to write own scripts and share them with us.<br />" .."Help to build happy VLC community :o)</div>" .."<pre> www<br />" .." (. .)<br />" .."-ooo-(_)-ooo-</pre>" w5=w:add_html(help_text,1,5,3,1) w14 = w:add_button("HELP (x)", click_HELPx,3,4,1,1) w:update() end function click_HELPx() w:del_widget(w5) w:del_widget(w14) w5=nil w14=nil w:update() end
The code might be better but I didn't want to entirely replace it so I just made a patch.
The code for playlist duration is [PLD]
Use it how ever you wish.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: VLC extension: Time

Postby Jean-Baptiste Kempf » 23 May 2012 23:45

addons.videolan.org
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: VLC extension: Time

Postby mederi » 27 May 2012 12:53

Ashada, thank you for adding new [PLD] tag for total playlist duration and demonstrating nice coding:

Code: Select all

--- function dur_to_time(duration) if duration>0 then local durationHour = math.floor(duration / 3600) local durationMinute = math.floor((duration % 3600) / 60) local durationSecond = math.floor(duration % 60) return durationHour, durationMinute, durationSecond else return -1 end end function playlist_duration() local sum = 0 local play_list = vlc.playlist.get("playlist",false) for k, video in pairs(play_list.children) do if video.duration ~= -1 then sum = sum + video.duration end end local h, m, s = dur_to_time(sum) return tostring(string.format("%02d:%02d:%02d", h, m, s)) end --- local osd_output = string.gsub(osd_output, "%[PLD%]", playlist_duration())
I will update the extension on addons.videolan.org soon. Probably I will also add some label widget in dialog box to display time information there. It will be good for music files without any video track and without visualisation turned on.

jose.mira
New Cone
New Cone
Posts: 3
Joined: 29 Jul 2012 19:44

Re: VLC extension: Time

Postby jose.mira » 29 Jul 2012 19:55

Hi.

Based on Ashada's code I develped an extension that shows a dialog with the playlist's total time.

BTW, I also changed the dur_time return value when the duration is not greater than zero, so that it return in the same format as when the duration is greater than zero.

As Ashada, I'm also releasing this as WTFPL!

If you find any problem with the script, please shout it out.

Code: Select all

-- playlistduration.lua -- VLC extension -- --[[ INSTALLATION: Put the file in the VLC subdir /lua/extensions, by default: * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\ * Windows (current user): %APPDATA%\VLC\lua\extensions\ * Linux (all users): /usr/share/vlc/lua/extensions/ * Linux (current user): ~/.local/share/vlc/lua/extensions/ * Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/ (create directories if they don't exist) Restart the VLC. Then you simply use the extension by going to the "View" menu and selecting it. --]] function descriptor() return { title = "Playlist Duration" ; version = "1.0" ; author = "abremir" ; url = ''; shortdesc = "Playlist Duration"; description = "Get the playlist duration.\n" .. "Returns the total play time of the current playlist." ; } end function activate() vlc.msg.info("[playlist duration] start") playdur = vlc.dialog("Playlist Duration") playdur:add_label("", 1, 1, 11, 2) playdur:add_label("Total time:", 12, 1, 1, 2) durlabel=playdur:add_label(playlist_duration(), 13, 1, 1, 2) playdur:add_label("", 14, 1, 11, 2) playdur:add_button("Ok", close_dialog, 12, 3, 2, 1) playdur:show() end function deactivate() vlc.msg.info("[playlist duration] stop") end function close_dialog() vlc.deactivate() end function dur_to_time(duration) if duration>0 then local durationHour = math.floor(duration / 3600) local durationMinute = math.floor((duration % 3600) / 60) local durationSecond = math.floor(duration % 60) return durationHour, durationMinute, durationSecond else return 0, 0, 0 end end function playlist_duration() local sum = 0 local play_list = vlc.playlist.get("playlist",false) for k, item in pairs(play_list.children) do if item.duration ~= -1 then sum = sum + item.duration end end local h, m, s = dur_to_time(sum) return tostring(string.format("%02d:%02d:%02d", h, m, s)) end
--- EDIT (12.3.2013, mederi) ---
Standalone forum topic for this extension: VLC Playlist Total Time Extension
Last edited by mederi on 12 Mar 2013 19:52, edited 2 times in total.
Reason: added link to standalone forum topic for this extension

Zane
Blank Cone
Blank Cone
Posts: 41
Joined: 25 Feb 2006 17:57
VLC version: latest, always!
Operating System: Win7 x64
Location: Ferrara, Italy
Contact:

Re: VLC extension: Time

Postby Zane » 17 Aug 2012 00:31

Found this Googling. Good job, guys!
Gianluigi "Zane" Zanettini


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 6 guests