VLC extension, watch folder player craching

Discuss your Lua playlist, album art and interface scripts.
perquin
New Cone
New Cone
Posts: 6
Joined: 26 Mar 2013 12:01

VLC extension, watch folder player craching

Postby perquin » 12 Apr 2013 13:09

Hi,

I making a small extension that play/broadcast in loop all files with a given extension that are in a specific folder.

Code: Select all

-- afptvfbroad.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/ (create directories if they don't exist) Relaunch the VLC with something like: "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" --file-logging --logfile="c:\toto\pp-vlc-log.txt" --scale=0.25 --log-verbose=2 --sout=#duplicate{dst=display,dst="standard{mux=ts,dst=158.50.181.255:10012,access=udp}"} or just the player Then you simply use the extension by going to the "View" menu and selecting it. --]] -----------CORE----------------- function descriptor() return { title = "AFTV FILES UDP BROADCASTER"; version = "0.9"; author = "work.philippe.perquin@gmail.com"; url = ''; shortdesc = "AFTV FILES UDP BROADCASTER"; description = "<div style=\"background-color:lightgreen;\"><b>AFTV FILES UDP BROADCASTER</b> AFTV FILES UDP BROADCASTER is VLC extension (extension script \"afptvfbroad.lua\") that UDP broadcast files in a folder.</div>"; capabilities = {"input-listener", "playing-listener", "meta-listener"} } end counter_update=0 function activate() display = vlc.dialog( "Playlist Update for: "..video_extension.." In folder: "..video_path ) display1=display:add_label( string.format("0") ,1,1,1,1) systemTime = os.date("%H:%M:%S") display2=display:add_label( string.format("0"),2,1,1,1) display3=display:add_button( "OK", function () display:hide() end,4,2,1,1 ) display:show() vlc.playlist.clear() update_playlist_add() update_playlist_delete() input_callback("add") if not vlc.input.is_playing() then vlc.playlist.play() vlc.playlist.loop("on") end end function deactivate() input_callback("del") if vlc.input.is_playing() then vlc.playlist.loop("off") vlc.playlist.stop() end end function close() vlc.deactivate() end function input_changed() input_callback("toggle") end function meta_changed() end function playing_changed() end old_input="titi" 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 AFPTV!") elseif input and callback==true and action=="del" then callback=false vlc.var.del_callback(input, "intf-event", input_events_handler, "Hello AFPTV!") end end last_call = 0 function input_events_handler(var, old, new, data) --Ordinarily one would do this to only act every 2 seconds. local current_call=os.clock() local result_call=current_call - last_call if result_call < 10 then return end last_call = current_call update_playlist_delete() update_playlist_add() display1:set_text( string.format("Process complete. Removed: " .. totaldelete .. " Added: " ..totaladd.. " Staying: " ..total_in_playlist) ,1,1,1,1) systemTime = os.date("%H:%M:%S") display2:set_text( string.format("Last update : " ..systemTime.." Updated: "..counter_update),2,1,1,1) display3:set_text( "OK", function () display:hide() end,4,2,1,1 ) display:update() local current_input = vlc.input.item() local current_input_name = current_input:name() local path_saved_file=string.format(video_path.."lastplay.txt") local saved_file = io.open(path_saved_file, "w") saved_file:write(string.format(systemTime.." Last file read : "..current_input_name)) saved_file:flush() saved_file:close() end ----------------------------REGLAGES --video_path="/Users/pil/Desktop/test liste/" video_path="C:/test liste/mp4/" video_extension=".mp4" ip_for_broadcast="" totaldelete=0 totaladd=0 total_in_playlist=0 ----------------------------CASE DELETE-- --verify if file from playlist are delete and delete them in playlist function update_playlist_delete() local counter = 0 for i, v in pairs(vlc.playlist.get("playlist",false).children) do -- check if delete if (string.find(v.name,video_extension)== nil) then --case delete delete it from playlist vlc.playlist.delete(tonumber(v.id)) --count deleted counter = counter + 1 end end --for all video in playlist for i, v in pairs(vlc.playlist.get("playlist",false).children) do -- check if delete if check_delete(v.path)==true then --case delete delete it from playlist vlc.playlist.delete(tonumber(v.id)) --count deleted counter = counter + 1 end end --return number of deleted totaldelete = counter -----------TEMP counter_update = counter_update + 1 end function check_delete(filepath) -- remove the file:/// from filepath local pathval = string.gsub(filepath, "file:\/\/\/", "") -- if pathval is NULL return if pathval==nil then return false end -- remove escape char from pathval pathval = unescape(pathval) -- try to acces the file local file,err,code = io.open(pathval, "r") -- if error and code 2 then file is deletete if err and code==2 then return true end return false end function unescape(str) -- translate the %% in file path local newstr = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end) if newstr==nil then newstr=str end return newstr end ----------------------------CASE ADD-- --verify if new files are in folder and add files with good video_extension in playlist function update_playlist_add() local counter = 0 local counter_in_playlist = 0 local file_allready_exist = false local new_item = {} -- Load directory contents into a table local contents_in_directory = vlc.net.opendir(video_path) -- for each file in directory for _, file_in_dir in pairs(contents_in_directory) do -- compare with each entry in the playlist for _, in_playlist in pairs(vlc.playlist.get("playlist",false).children) do --if exits stop compare saying it exist if in_playlist.name==file_in_dir then file_allready_exist=true end end -- if not exist add it to playlist if not file_allready_exist then new_item.path = "file:///"..video_path..file_in_dir new_item.name = file_in_dir --verify if it s good extension if not (string.find(file_in_dir,video_extension)== nil) then --add it to playlist not playing vlc.playlist.enqueue({new_item}) -- count as added counter = counter + 1 end end file_allready_exist=false end -- count total of video staying in playlist for _, in_playlist in pairs(vlc.playlist.get("playlist",false).children) do counter_in_playlist = counter_in_playlist + 1 end totaladd = counter total_in_playlist = counter_in_playlist -----------TEMP counter_update = counter_update + 1 end
The extension is working in windows and ubuntu, not in osx that not seem to be compatible with callback.

This extension seem to work with 2.05 and 2.06 but VLC crach after a few moment (sometime 5 minutes, 2 hours, 30 minutes). And i need to use it 24/24.

Can it comme from Lua?

Regards,

Philippe

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

Watch folder - Update playlist

Postby mederi » 13 Apr 2013 15:23

Yes, I have experienced similar unstability also in my extensions. While my first VLC Extension, Time, works very well, others suffer from occasional or frequent crash of VLC. There are some functions causing troubles if they are used in a script. For example, in my Subtitler (lite) fixed path works very well, while the autodetection not so well and there is just vlc.input.item():uri() used in function media_path(extension). There is another script relating playlists on the forum, Playlist randomizer, that also does not work very well. The bug must be somewhere around playlist and metadata.

You could try to debug the script by making a static extension instead of using callbacks, as has been suggested here: viewtopic.php?f=7&t=106236#p360372
You could also strip the working core, then add new functions to it and test particular stages. Perhaps you could find a stable workaround.

perquin
New Cone
New Cone
Posts: 6
Joined: 26 Mar 2013 12:01

Re: VLC extension, watch folder player craching

Postby perquin » 15 Apr 2013 09:18

Hi mederi,

I will try to test it by function, else i goes to powersell and ffmpeg.

Regards,

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, watch folder player craching

Postby Jean-Baptiste Kempf » 17 Apr 2013 01:43

Please file bugs.
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 8 guests