just a simple extension--paste current time to clipboard

Discuss your Lua playlist, album art and interface scripts.
valuex
New Cone
New Cone
Posts: 2
Joined: 17 May 2012 10:18

just a simple extension--paste current time to clipboard

Postby valuex » 17 May 2012 11:27

1.
I want to get the current time of vlc on to clipboard. The following is an extension for this purpose.
I am new to LUA.
This extension is modified based on Time.
http://addons.videolan.org/content/show ... ent=149618
Many thanks to lubozle.
2.
Putting this simple extension here, I hope those who is not familiar with LUA can get something from it.
Also, if there is any bug with this extension, you are welcomed to point it out.
3.
I use

Code: Select all

strCmd = 'echo '..var..' |clip' os.execute(strCmd)
to put variable into clipboard, is there a direct way to do this in LUA?

Code: Select all

-- Time2Clip.lua -- VLC extension -- --[[ INSTALLATION: Put the file in the VLC subdir /lua/extensions, by default: * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\ Restart the VLC. Then you simply use the extension by going to the "View" menu and selecting it. --]] function descriptor() return { title = "Time2Clip"; version = "1.0"; author = "valuex"; url = 'http://addons.videolan.org/content/show.php?content=149618'; shortdesc = "Time2Clip"; description = "<div style=\"background-color:lightgreen;\"><b>just a simple VLC extension </b></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 function input_events_handler(var, old, new, data) end function create_dialog() w = vlc.dialog("Time2Clip") w1 = w:add_label("<b>CurrentTime:</b>",1,1,1,1) w2 = w:add_text_input("0",2,1,1,1) w3 = w:add_button("jumpto", click_SEEK,1,2,1,1) w4 = w:add_button("Save_to_Clip", click_SAVE,2,2,1,1) end function click_SAVE() local input = vlc.object.input() if input then local curtime=vlc.var.get(input, "time") w2:set_text( curtime ) save_to_clipboard(curtime) end end function click_SEEK() local time_togo = w2:get_text() local input = vlc.object.input() if input then vlc.var.set(input, "time", time_togo) --jump to specified time end end function save_to_clipboard(var) strCmd = 'echo '..var..' |clip' os.execute(strCmd) end

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: just a simple extension--paste current time to clipboard

Postby mederi » 17 May 2012 17:14

Thanks for the script bringing new ideas.
You should also tell users to download "clip.exe" from Internet as it is not available in all Windows versions. At least my Windows XP SP2 does not have one. Copy Command Line Output to Windows Clipboard Directly

You can remove some more redundancies from the script that you do not need there at all:
capabilities = {"input-listener"}
input_callback("add")
input_callback("del")
function input_changed()
function input_callback(action)
function input_events_handler(var, old, new, data)
Please edit your post and remove these functions from the code to make it simpler and more understandable.
Good work. Thanks.

valuex
New Cone
New Cone
Posts: 2
Joined: 17 May 2012 10:18

Re: just a simple extension--paste current time to clipboard

Postby valuex » 18 May 2012 06:52

Thanks for the script bringing new ideas.
You should also tell users to download "clip.exe" from Internet as it is not available in all Windows versions. At least my Windows XP SP2 does not have one. Copy Command Line Output to Windows Clipboard Directly

You can remove some more redundancies from the script that you do not need there at all:
capabilities = {"input-listener"}
input_callback("add")
input_callback("del")
function input_changed()
function input_callback(action)
function input_events_handler(var, old, new, data)
Please edit your post and remove these functions from the code to make it simpler and more understandable.
Good work. Thanks.
Mederi, thanks for your wonderful reply.
I've modified this extension according to your suggestions.
Now it looks more concise.
Here is the results.

Code: Select all

-- Time2Clip.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\ (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. Note: This extension has been tested for VLC 2.0.1 on Win7 sp1. Because the function save_to_clipboard needs clip.exe, you've to make sure your windows system has it (just type "echo a |clip" in the cmd prompt window to check whether letter "a" has been put in the system clipboard). If it doesn't exist, you can download it from here: http://www.labnol.org/software/tutorials/copy-dos-command-line-output-clipboard-clip-exe/2506/ --]] function descriptor() return { title = "Time2Clip"; version = "1.0"; author = "valuex"; url = 'http://addons.videolan.org/content/show.php?content=149618'; shortdesc = "Time2Clip"; description = "<div style=\"background-color:lightgreen;\"><b>just a simple VLC extension </b></div>"; } end function activate() create_dialog() end function deactivate() end function close() vlc.deactivate() end function create_dialog() w = vlc.dialog("Time2Clip") w1 = w:add_label("<b>CurrentTime:</b>",1,1,1,1) w2 = w:add_text_input("0",2,1,1,1) w3 = w:add_button("jumpto", click_SEEK,1,2,1,1) w4 = w:add_button("Save_to_Clip", click_SAVE,2,2,1,1) end function click_SAVE() local input = vlc.object.input() if input then local curtime=vlc.var.get(input, "time") w2:set_text( curtime ) save_to_clipboard(curtime) end end function click_SEEK() local time_togo = w2:get_text() local input = vlc.object.input() if input then vlc.var.set(input, "time", time_togo) --jump to specified time end end function save_to_clipboard(var) strCmd = 'echo '..var..' |clip' os.execute(strCmd) 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: just a simple extension--paste current time to clipboard

Postby Jean-Baptiste Kempf » 21 May 2012 17:33

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.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 1 guest