Delete current file from harddisk

Discuss your Lua playlist, album art and interface scripts.
yoestiee
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 17:17

Re: Delete current file from harddisk

Postby yoestiee » 21 Jan 2014 15:52

Could be very cool and usefull if implemented in futures versions of VLC, will really help me to get rid of videos I don't anymore want... (I have a tons of them, but it's too long to delete manually...)

kalon
New Cone
New Cone
Posts: 1
Joined: 30 Mar 2014 06:35

Re: Delete current file from harddisk

Postby kalon » 30 Mar 2014 06:57

Hi guys,
Hoping someone could help me out. I'm trying to figure out how I might change the above scripts so that I'd have one button for immediate delete and another which would "save" the file by moving it to another directory (preferably based on filename).

The background is that I've been using Miro on Linux for a long time but I'm tired of it flaking out so I'm trying out flexget for rss downloading and just need a way to manage played videos somehow. I figured I could download everything to a temp folder which is watched by a cron job that deletes files after x days. If I could "save" files by moving them up a directory and in to their one folder that make it perfect.

Really appreciate and help or pointers.

rverboom
New Cone
New Cone
Posts: 2
Joined: 10 Mar 2011 16:50

Re: Delete current file from harddisk

Postby rverboom » 02 Apr 2014 16:30

Hi all,

I have the same problem, with directories of ripped mp3's from my CD collection.
Most not wanted on my mp3 player, but deleting with windows explorer and VLC is not handy.

My temporary solution is the directory player by 1by1
http://mpesch3.de1.cc/1by1.html
In the options you can decide to delete without a dialog.

But I am still hoping for a solution in VLC...

Rob

147852369
Blank Cone
Blank Cone
Posts: 55
Joined: 01 Mar 2013 12:18

Re: Delete current file from harddisk

Postby 147852369 » 17 Jun 2014 10:43

I don't have any ideas how to resolve this problem in newer versions of VLC in LUA.

My solution only works in older versions of VLC on Windows because of the removed callback function in current LUA. And it only works with a batch-Script to bypass the permission problem but that's fine for me. You can edit the extension and the batch script to move files to another directory or do other tings for Windows. On Linux, you can do it without the batch file as you edit just the extension file.

I wish there were a official VLC extension that can delete and move files with hot keys. And a statistic / error log would be nice.

I don't know the whole API of VLC. Is there an opportunity to programming this? So I know that the involvement enabled the interface is worthwhile for me. Otherwise I probably would not program any more extensions for me. Maybe it's natively possible.

Sorry for my English

-Caglar Yanik

coder99
New Cone
New Cone
Posts: 2
Joined: 20 Oct 2014 23:05

Re: Delete current file from harddisk

Postby coder99 » 20 Oct 2014 23:23

Extension based on code and ideas from this thread - http://addons.videolan.org/content/show ... ent=167547

Tested only on Windows 8 and VLC 2.1.1.

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: Delete current file from harddisk

Postby mederi » 21 Oct 2014 15:50

Perhaps you could improve the extension and include also another ideas discussed here to make it as universal as possible: support also for Linux; settings with various options: delete item (yes/no), write items in the file (no/always/if not deletable), display the list in html widget (easy to select and copy text), the list can be later used for deleting/copying/moving files (batch script), ...

coder99
New Cone
New Cone
Posts: 2
Joined: 20 Oct 2014 23:05

Re: Delete current file from harddisk

Postby coder99 » 23 Oct 2014 21:22

Extension based on code and ideas from this thread - http://addons.videolan.org/content/show ... ent=167547

Tested only on Windows 8 and VLC 2.1.1.
Extension deleted from addons.videolan.org, but here below is the code.

Code: Select all

function descriptor() return { title = "RealDelete", version = "1.2", shortdesc = [[ Deletes currently playing file from disk and from playlist. Usage (Windows): 1. Name extension file realdelete.lua and copy it into VLC extensions folder e.g. C:\Program Files (x86)\VideoLAN\VLC\lua\extensions\realdelete.lua 2. restart VLC; extension should be visible under View menu Tested on Windows 8 & VLC 2.1.1 Supports only ASCII file names. License: GPL http://www.gnu.org/licenses/gpl.html You use this extension at your own risk - author cannot be held responsible for any direct or indirect damage caused. Based on: * Diskdelete 0.2 by Mark Morschhäuser * https://forum.videolan.org/viewtopic.php?f=29&t=108811 (users 147852369, mederi) ]], url="" } end shouldDelete = 0 shouldClose = 0 broken = 0 metaCounter = 0 btnDelete = nil btnOk = nil btnCancel = nil deleteFromPlaylist = 0 function activate() vlc.msg.info("[RealDelete] Activated") d = vlc.dialog("RealDelete") labelInfo=d:add_label("Delete <b>from disk and from playlist</b>?",1,1,2,1) labelFile=d:add_label("",1,2,2,2) labelSpacing=d:add_label("<br/>",1,3,2,1) btnDelete = d:add_button("Delete", click_delete,1,4,1,1) btnCancel = d:add_button("Cancel", click_cancel,2,4,1,1) selectFile() d:show() end function deactivate() vlc.msg.info("[RealDelete] Deactivated") end function close() vlc.msg.info("[RealDelete] Will close now") --d:delete() -- close and delte dialog vlc.deactivate() end function selectFile() local isPlaying = vlc.input.is_playing() if isPlaying~= true then broken = 1 messageMode("File to delete should be playing") else item = vlc.input.item() uri = item:uri() filename = vlc.strings.decode_uri(uri) -- decode %foo stuff from the URI filename = string.sub(filename,9) -- remove 'file://' prefix which is 7 chars long --filepath = string.gsub(filename,"/","\\") -- Windows style path, e.g. c:\mp3\the best.mp3 vlc.msg.info("[RealDelete] selected for deletion: " .. filename) labelFile:set_text(filename) itemId = vlc.playlist.current() end end function click_cancel() close() end function click_delete() vlc.playlist.next() shouldDelete = 1 end function meta_changed() --vlc.msg.info("[RealDelete] Meta changed ") if broken == 1 then --vlc.msg.info("[RealDelete] Broken") do return end elseif shouldDelete == 1 then metaCounter = metaCounter + 1 if metaCounter > 2 then vlc.msg.info("metaCounter > 1") local nextItemId = vlc.playlist.current() if nextItemId == itemId then-- maybe only one item in playlist vlc.msg.info("Maybe only one item in playlist") vlc.playlist.next() nextItemId = vlc.playlist.current() if nextItemId == itemId then-- only one item in playlist broken = 1 messageMode("<br>Playlist should have at least two files</br>") end else shouldDelete = 0 deleteFile() end end elseif shouldClose == 1 then metaCounter = metaCounter + 1 vlc.msg.info("[RealDelete] Meta counter " .. metaCounter) if metaCounter > 7 then vlc.msg.info("[RealDelete] Meta counter " .. metaCounter) if deleteFromPlaylist == 1 then vlc.playlist.delete(itemId) end shouldClose = 0 close() end end end function messageMode(message) vlc.msg.info("messageMode()") broken = 1 -- d:del_widget(btnDelete) --d:del_widget(labelFile) --d:del_widget(labelInfo) labelInfo:set_text("") --labelFile:set_text("") labelInfo=d:add_label(message,1,1,3,1) btnDelete = d:add_button("OK", close,1,4,1,1) --btnCancel:set_text("OK") end function deleteFile() if broken == 1 then do return end end vlc.msg.info("deleteFile()") if filename~=nil then retval, err = os.remove(filename) if(retval == nil) then -- error handling; if deletion failed, print why broken = 1 local errMessage = tostring(err) vlc.msg.info("[RealDelete] error: " .. errMessage) if string.find(errMessage, "No such file or directory") then messageMode("Cannot delete files with non-ascii names :(") else messageMode(errMessage) end else vlc.msg.info("[RealDelete] File deleted") --vlc.playlist.delete(itemId) deleteFromPlaylist = 1 filename=nil --d:hide() -- hide dialog shouldClose = 1 end end end
It sometimes crashes VLC immediately after successfully deleting file. I don't know why.

147852369
Blank Cone
Blank Cone
Posts: 55
Joined: 01 Mar 2013 12:18

Re: Delete current file from harddisk

Postby 147852369 » 10 Dec 2014 13:09

I have a similar problem after skipping files with my extension: https://forum.videolan.org/viewtopic.php?f=29&t=123125

147852369
Blank Cone
Blank Cone
Posts: 55
Joined: 01 Mar 2013 12:18

Re: Delete current file from harddisk

Postby 147852369 » 05 Jan 2017 23:05

Hello!
I have good news. Here's a new topic about this problem: https://forum.videolan.org/viewtopic.ph ... 68#p451830

I started to develop a VLC Media Player based on JavaFX. You can delete files directly from hard drive also on Windows - without crashing! Please test and notify me about your experience in the new thread.

TonyPipes
New Cone
New Cone
Posts: 1
Joined: 06 Jan 2017 16:07

Re: Delete current file from harddisk

Postby TonyPipes » 06 Jan 2017 16:13

Hey Guys,

i took the liberty to adapt mederis 2 Button solution - it's now a one button solution ;)
It also removes the playlist entry for the file that has been deleted and resumes playback at the next entry...

hope this is of help to anyone

cheers!

Code: Select all

function descriptor() return { title = "Diskdelete_2 (1 button)" } end function activate() d = vlc.dialog("Diskdelete") label=d:add_label("<b>Clicking</b> this button will <b>delete</b> the currently playing file <b>from disk</b>.<br>You have to <b>be sure</b> as <b>you won't be asked</b> again!<br>You are responsible for your own actions, consider yourself warned.",1,1,2,1) d:add_button("DELETE CURRENTLY PLAYING FILE", click_delete,2,2) d:show() vlc.msg.info("[Diskdelete] Activated") end function deactivate() vlc.msg.info("[Diskdelete] Deactivated") end function close() vlc.deactivate() end function meta_changed() end function click_delete() item = vlc.input.item() -- get the current playing file uri = item:uri() -- extract it's URI vlc.playlist.skip(1) playhere = vlc.playlist.current() for i, v in pairs(vlc.playlist.get("playlist",false).children) do if( uri == v.path ) then vlc.playlist.delete(tonumber(v.id)) end end vlc.playlist.goto( playhere+1 ) vlc.playlist.play() filename = vlc.strings.decode_uri(uri) -- decode %foo stuff from the URI filename = string.sub(filename,9) -- remove 'file://' prefix which is 7 chars long filepath = string.gsub(filename,"/","\\") -- Windows style path, e.g. c:\mp3\the best.mp3 vlc.msg.info("[Diskdelete] selected for deletion: " .. filename) -- label:set_text(filepath) if filename~=nil then retval, err = os.remove(filename) if(retval == nil) -- error handling; if deletion failed, print why then label:set_text(tostring(err)) vlc.msg.info("[Diskdelete] error: " .. tostring(err)) else label:set_text(filepath.."<br /><b>DELETED!DELETED!DELETED!</b>") end filename=nil end end

JWalkerMR
New Cone
New Cone
Posts: 8
Joined: 30 Aug 2015 12:36

Re: Delete current file from harddisk

Postby JWalkerMR » 10 Mar 2017 21:23

Well, my solution is not that tricky, but it works too. As long as files are playing, starting my lua writes current filename into a batchfile; when no file is playing, starting my lua executes this batchfile, which deletes all files written there, and then deletes the batchfile.

Replace "C:\\lua\\" with some directory you want to use...

Code: Select all

function activate() if vlc.input.is_playing()~= true then os.execute("C:\\lua\\DeleteIt.bat") os.remove("C:\\lua\\DeleteIt.bat") close() else item = vlc.input.item() uri = item:uri() filename = vlc.strings.decode_uri(uri) filename = string.sub(filename,9) filename = string.gsub(filename,"/","\\") delfile=io.open("C:\\lua\\DeleteIt.bat","a+") delfile:write("del " .. filename,"\n") delfile:close() close() end end

HelmutEder
New Cone
New Cone
Posts: 1
Joined: 21 Mar 2017 12:12

Re: Delete current file from harddisk

Postby HelmutEder » 21 Mar 2017 12:15

Hi JWalkerMR,

Would you be able to post the entire .lua please?

Much appreciated!

JWalkerMR
New Cone
New Cone
Posts: 8
Joined: 30 Aug 2015 12:36

Re: Delete current file from harddisk

Postby JWalkerMR » 21 Mar 2017 19:10

oh, there isn't much more:

Code: Select all

appname = "DelBat" appver = "0.0.1" author = "JWalkerMR" function descriptor() return { title = appname; version = appver; author = author; } end function activate() if vlc.input.is_playing()~= true then os.execute("C:\\lua\\DeleteIt.bat") os.remove("C:\\lua\\DeleteIt.bat") close() else item = vlc.input.item() uri = item:uri() filename = vlc.strings.decode_uri(uri) filename = string.sub(filename,9) filename = string.gsub(filename,"/","\\") delfile=io.open("C:\\lua\\DeleteIt.bat","a+") delfile:write("del " .. filename,"\n") delfile:close() close() end end function close() vlc.deactivate() end function meta_changed() end

GBO330
New Cone
New Cone
Posts: 3
Joined: 05 Feb 2018 15:41

Re: Delete current file from harddisk

Postby GBO330 » 06 Feb 2018 23:04

Hi All, I know this is an old discussion, but has this ever been resolved in VLC for windows? (hotkey to delete current file) I can see from this discussion that vlc cannot delete stuff in windows, would it make a difference if you run VLC as administrator?
If this is simply impossible, could we perhaps just have a hotkey to save the path of currently playing file to a text file? (someone mentioned a "VLC_toDelete.txt", but couldn't get if or how it was achieved)
being able to instantly save the paths to a text doc would be significantly better than nothing.
Lastly, if all above is impossible, can we at least have a hotkey to save current file's path to windows clip-board? thanks in advance to anyone with answers!

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: Delete current file from harddisk

Postby mederi » 07 Feb 2018 16:11

Lua scripts do not support hotkeys. Extensions support a dialog box, where you can click buttons or you can activate an action just in VLC menu without the dialog box and you can write a path in a list in a file. Better if the delete feature would be built-in directly in VLC (a hotkey, a control menu button, an option in VLC menu and right-click context menu): https://trac.videolan.org/vlc/ticket/6255

Misska
New Cone
New Cone
Posts: 4
Joined: 06 Jul 2018 13:43

Re: Delete current file from harddisk

Postby Misska » 06 Jul 2018 13:56

oh yes ! please post !

ale5000
Cone that earned his stripes
Cone that earned his stripes
Posts: 125
Joined: 03 Mar 2004 16:12
Operating System: Windows
Contact:

Re: Delete current file from harddisk

Postby ale5000 » 09 Jul 2018 11:17

Extension based on code and ideas from this thread - http://addons.videolan.org/content/show ... ent=167547

Tested only on Windows 8 and VLC 2.1.1.
Extension deleted from addons.videolan.org, but here below is the code.

Code: Select all

function descriptor() return { title = "RealDelete", version = "1.2", shortdesc = [[ Deletes currently playing file from disk and from playlist. Usage (Windows): 1. Name extension file realdelete.lua and copy it into VLC extensions folder e.g. C:\Program Files (x86)\VideoLAN\VLC\lua\extensions\realdelete.lua 2. restart VLC; extension should be visible under View menu Tested on Windows 8 & VLC 2.1.1 Supports only ASCII file names. License: GPL http://www.gnu.org/licenses/gpl.html You use this extension at your own risk - author cannot be held responsible for any direct or indirect damage caused. Based on: * Diskdelete 0.2 by Mark Morschhäuser * https://forum.videolan.org/viewtopic.php?f=29&t=108811 (users 147852369, mederi) ]], url="" } end shouldDelete = 0 shouldClose = 0 broken = 0 metaCounter = 0 btnDelete = nil btnOk = nil btnCancel = nil deleteFromPlaylist = 0 function activate() vlc.msg.info("[RealDelete] Activated") d = vlc.dialog("RealDelete") labelInfo=d:add_label("Delete <b>from disk and from playlist</b>?",1,1,2,1) labelFile=d:add_label("",1,2,2,2) labelSpacing=d:add_label("<br/>",1,3,2,1) btnDelete = d:add_button("Delete", click_delete,1,4,1,1) btnCancel = d:add_button("Cancel", click_cancel,2,4,1,1) selectFile() d:show() end function deactivate() vlc.msg.info("[RealDelete] Deactivated") end function close() vlc.msg.info("[RealDelete] Will close now") --d:delete() -- close and delte dialog vlc.deactivate() end function selectFile() local isPlaying = vlc.input.is_playing() if isPlaying~= true then broken = 1 messageMode("File to delete should be playing") else item = vlc.input.item() uri = item:uri() filename = vlc.strings.decode_uri(uri) -- decode %foo stuff from the URI filename = string.sub(filename,9) -- remove 'file://' prefix which is 7 chars long --filepath = string.gsub(filename,"/","\\") -- Windows style path, e.g. c:\mp3\the best.mp3 vlc.msg.info("[RealDelete] selected for deletion: " .. filename) labelFile:set_text(filename) itemId = vlc.playlist.current() end end function click_cancel() close() end function click_delete() vlc.playlist.next() shouldDelete = 1 end function meta_changed() --vlc.msg.info("[RealDelete] Meta changed ") if broken == 1 then --vlc.msg.info("[RealDelete] Broken") do return end elseif shouldDelete == 1 then metaCounter = metaCounter + 1 if metaCounter > 2 then vlc.msg.info("metaCounter > 1") local nextItemId = vlc.playlist.current() if nextItemId == itemId then-- maybe only one item in playlist vlc.msg.info("Maybe only one item in playlist") vlc.playlist.next() nextItemId = vlc.playlist.current() if nextItemId == itemId then-- only one item in playlist broken = 1 messageMode("<br>Playlist should have at least two files</br>") end else shouldDelete = 0 deleteFile() end end elseif shouldClose == 1 then metaCounter = metaCounter + 1 vlc.msg.info("[RealDelete] Meta counter " .. metaCounter) if metaCounter > 7 then vlc.msg.info("[RealDelete] Meta counter " .. metaCounter) if deleteFromPlaylist == 1 then vlc.playlist.delete(itemId) end shouldClose = 0 close() end end end function messageMode(message) vlc.msg.info("messageMode()") broken = 1 -- d:del_widget(btnDelete) --d:del_widget(labelFile) --d:del_widget(labelInfo) labelInfo:set_text("") --labelFile:set_text("") labelInfo=d:add_label(message,1,1,3,1) btnDelete = d:add_button("OK", close,1,4,1,1) --btnCancel:set_text("OK") end function deleteFile() if broken == 1 then do return end end vlc.msg.info("deleteFile()") if filename~=nil then retval, err = os.remove(filename) if(retval == nil) then -- error handling; if deletion failed, print why broken = 1 local errMessage = tostring(err) vlc.msg.info("[RealDelete] error: " .. errMessage) if string.find(errMessage, "No such file or directory") then messageMode("Cannot delete files with non-ascii names :(") else messageMode(errMessage) end else vlc.msg.info("[RealDelete] File deleted") --vlc.playlist.delete(itemId) deleteFromPlaylist = 1 filename=nil --d:hide() -- hide dialog shouldClose = 1 end end end
It sometimes crashes VLC immediately after successfully deleting file. I don't know why.
Hi,
could you please correctly specify your license information and maybe putting the script on something like GitHub?
Saying only GPL doesn't mean nothing legally since there are 3 versions of GPL; also it should be specified if you allow future versions; possible using the standard identifier: https://spdx.org/licenses/

In your case it is probably:

Code: Select all

SPDX-License-Identifer: GPL-3.0-or-later


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 8 guests