Script to delete current playing file in Windows

Discuss your Lua playlist, album art and interface scripts.
Trevor_Sturdevant
New Cone
New Cone
Posts: 3
Joined: 22 Sep 2013 18:39

Script to delete current playing file in Windows

Postby Trevor_Sturdevant » 22 Sep 2013 20:59

This is a quick and dirty script I wrote which will mark the currently playing file for deletion in Windows.

Windows cannot delete the current playing file so long as it is currently playing since the file is open/locked and cannot be deleted because Window's sucks(that's my technical explanation). To get around this the path/filename is written to a temp file and the next time the script is activated the previously marked file will be physically removed.

Code: Select all

function descriptor() return { title = "DeleteFile for VLC" ; version = "0.003" ; author = "Trevor Sturdevant"; shortdesc = "Physically delete a file from disk"; description = "DeleteFile - Physically deletes/removed the current playing file" .. "from disk [eventually]. No confirmation is asked. If you do not want to" .. "delete the file do not click the extension. The file is not actually deleted" .. "until the next time the extension is activated. This is provided for" .. "academic purposes only. This cannot be sold or reproduced for any profit." .. "No warranties are expressed or implied by making use of this code." .. "Use at your own risk." .. "Place this into %APPDATA%\vlc\lua\extensions\delefile.lua" .. "It could be coded better but I just wanted to get it done for personal use" .. "but have decided that sharing is caring."; url = "http://none.sorry/" } end function activate() vlc.msg.dbg("DeleteFile: activated") local tempf = string.gsub(os.getenv("TEMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'r') if err then local tempf = string.gsub(os.getenv("TMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'r') if err then local tempf = string.gsub(os.getenv("USERPROFILE"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'r') end end if f~=nil then f:close() local tempwinf = string.gsub(tempf,"/","\\") local delCmd = "start /min /wait cmd /E:ON /c " .. tempwinf os.execute(delCmd) os.remove(tempf) end delete() deactivate() end function deactivate() vlc.msg.dbg("DeleteFile: deactivated") vlc.deactivate() end function close() vlc.msg.dbg("DeleteFile: closing") deactivate() end function playnext() vlc.playlist.next() end function delete() local item = vlc.input.item() local uri = item:uri() local filename = vlc.strings.decode_uri(uri) filename = string.sub(filename,9) local dosfilename = string.gsub(filename,"/","\\"); vlc.msg.dbg("DeleteFile: received \"" .. filename .. "\"") vlc.msg.dbg("DeleteFile: dos fname \"" .. dosfilename .. "\"") local tempf = string.gsub(os.getenv("TEMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'a') if err then local tempf = string.gsub(os.getenv("TMP"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'a') if err then local tempf = string.gsub(os.getenv("USERPROFILE"),"\\","/") .. "/vlc_DeleteFile_tmp.bat" local f,err = io.open(tempf, 'a') if err then vlc.msg.dbg("DeleteFile: Failed to open vlcdel.txt for writing - " .. err) end end end if f~=nil then f:write("del \"" .. dosfilename .. "\"\r\n") f:flush() f:close() vlc.playlist.next() else vlc.msg.dbg("DeleteFile: Failed to open vlcdel.txt for writing - " .. err) box = vlc.dialog("DeleteFile") box:add_label("Failed to open a temp file for writing. I tried my best.") box:add_button("CLOSE", deactive) box:show() end end function meta_changed() end

drewkeller
Blank Cone
Blank Cone
Posts: 25
Joined: 17 Sep 2013 14:59

Re: Script to delete current playing file in Windows

Postby drewkeller » 26 Sep 2013 06:03

seems like i remember something about the playlist or meta scripts being run automatically when VLC changes input. Perhaps this could be more automatic by having the deletion part made into one of these other types of scripts and also check for the batch file, so deletion occurs on either next activation or next file is played. Manual activation of course would still be the only way to place things on the deletion "queue".

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: Script to delete current playing file in Windows

Postby Jean-Baptiste Kempf » 27 Sep 2013 01:28

You could also stop playing the file.
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.

XilE
New Cone
New Cone
Posts: 1
Joined: 05 Oct 2013 00:50

Re: Script to delete current playing file in Windows

Postby XilE » 05 Oct 2013 00:57

Neat I've been doing something similar with AutoHotkey, but I like your way better.

Code: Select all

#SingleInstance, Force #IfWinActive, ahk_class QWidget #NoTrayIcon BLI: BlockInput, MouseMoveOff ~CapsLock & Delete:: KeyWait, Delete, Up KeyWait, CapsLock, Up BlockInput, MouseMove SetCapsLockState, Off SetTimer, BLI, 10000 WinActivate, ahk_class QWidget WinWaitActive, ahk_class QWidget WinGetTitle, CT, A Send, ^i WinWait, Media Information, , 10 WinActivate, Media Information WinWaitActive, Media Information WinGetPos, MIX, MIY, MIW, MIH, Media Information XP:=MIW/2 YP:=MIH-52 MouseGetPos, XS, YS CoordMode, Mouse, Relative MouseMove, %XP%, %YP%, 1 Click, 3 Send, ^c ClipWait, 10 FD:=Clipboard WinClose, Media Information WinWaitClose, Media Information WinKill, %CT% ;Send, {N Down}{N Up} ;The WinKill can be disabled and swaped with this to jump to the next video. WinActivate, ahk_class Shell_TrayWnd WinWaitActive, ahk_class Shell_TrayWnd FileDelete, %FD% MouseMove, %XS%, %YS%, 1 Clipboard:= Run, C:\Program Files (x86)\VideoLAN\VLC\vlc.exe CoordMode, Mouse, Screen MouseMove, %XS%, %YS%,1 BlockInput, MouseMoveOff Return


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 1 guest