Delete current file from harddisk

Discuss your Lua playlist, album art and interface scripts.
147852369
Blank Cone
Blank Cone
Posts: 55
Joined: 01 Mar 2013 12:18

Delete current file from harddisk

Postby 147852369 » 01 Mar 2013 15:14

--- EDIT ---
# Board index ‹ VLC media player ‹ VLC media player Feature Requests \ Delete current file from harddisk
-------------

I tried to debug this code, but anything I did I get an error message. "Permisson denied"...

Code: Select all

--[[ INSTALLATION (create directories if they don't exist): - 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/ - Restart VLC. ]]-- --[[ Extension description ]] function descriptor() return { title = "Diskdelete" ; version = "0.2" ; author = "Mark Morschhäuser" ; shortdesc = "DELETE current playing FILE FROM DISK"; description = "<h1>Diskdelete</h1>" .. "When you're playing a file, use Diskdelete to " .. "easily delete this file <b>from your disk</b> with one click." .. "<br>This will NOT change your playlist, it will <b>ERASE the file</b> itself!" .. "<br>It will not use the Recycle Bin, the file will be gone immediately!" .. "<br>This extension has been tested on GNU Linux with VLC 2.0.3." .. "<br>The author is not responsible for damage caused by this extension."; url = "https://github.com/VanNostrand/Diskdelete" } end --[[ Hooks ]] -- Activation hook function activate() vlc.msg.dbg("[Diskdelete] Activated") d = vlc.dialog("Diskdelete") 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.") d:add_button("DELETE CURRENT FILE PERMANENTLY FROM DISK WITHOUT ASKING", delete) d:show() end -- Deactivation hook function deactivate() vlc.msg.dbg("[Diskdelete] Deactivated") vlc.deactivate() end function close() deactivate() end --[[ The file deletion routine ]] function delete() item = vlc.input.item() -- get the current playing file uri = item:uri() -- extract it's URI filename = vlc.strings.decode_uri(uri) -- decode %foo stuff from the URI vlc.playlist.skip(1) --[[ --vlc.misc.mwait(vlc.misc.mdate() + 3000000) --vlc.var.add_callback(vlc.object.input(), "time", vlc.playlist.skip(1), 3000000) ]]-- --retval, err = os.chmod(filename, 0777) filename = string.sub(filename,9) -- remove 'file://' prefix which is 7 chars long vlc.msg.dbg("[Diskdelete] selected for deletion: " .. filename) retval, err = os.remove(filename) -- delete the file with this filename from disk if(retval == nil) -- error handling; if deletion failed, print why then vlc.msg.dbg("[Diskdelete] error: " .. err) end end -- This empty function is there, because vlc pested me otherwise function meta_changed() 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: Delete current file from harddisk

Postby mederi » 01 Mar 2013 16:21

Window does not allow to delete files currently in use by VLC. The extension script probably works only on Linux.

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

Re: Delete current file from harddisk

Postby 147852369 » 01 Mar 2013 16:51

This is why I wrote "vlc.playlist.skip(1)" before deleting the file to unblock the file.

If I skip the file manually, after then delete the file through the windows explorer, it works! Why not with a script?

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 » 01 Mar 2013 18:54

It seems that it is not possible to delete anything using the Lua script.
os.remove() does not work. "Permission denied".

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

Re: Delete current file from harddisk

Postby 147852369 » 02 Mar 2013 00:25

Is there an other oppertunity to programming a extension for the VLC player to delete current video files from harddisk under Windows? Should I use an other programming language?

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

Re: Delete current file from harddisk

Postby 147852369 » 02 Mar 2013 01:32

It works on Debian.
How can I delete a file from the PLAYLIST with LUA?

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 » 02 Mar 2013 22:09

It seems that it is not possible to delete anything using the Lua script.
os.remove() does not work. "Permission denied".
It works if a file has not read-only attribute and it is not currently used by VLC. The script does not wait until "vlc.playlist.skip(1)" releases the current file.

I have a working 2-button solution for you:

Code: Select all

function descriptor() return { title = "Diskdelete (2 buttons)" } 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("SELECT CURRENT FILE", click_select,1,2) d:add_button("DELETE SELECTED 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_select() item = vlc.input.item() -- get the current playing file uri = item:uri() -- extract it's URI vlc.playlist.skip(1) 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) end function click_delete() 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!</b>") end filename=nil end end
Issues to solve:
* 1-button solution using "capabilities = {"input-listener", "meta-listener", "playing-listener"}" and probably also some callback. Already playing next item? => Possible to delete previous one.
* write the list of files not possible to delete - read-only files
* if there is one item in the playlist, then stop playback instead of trying to play next one - itself
* remove deleted files also from actual playlist - Playlist Cleaner - "vlc.playlist.delete()"

Are you the author of Diskdelete extension script?
If you do not mind I will try to move this topic (starting from the second post here) in Lua scripting section on the forum.

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

Re: Delete current file from harddisk

Postby 147852369 » 02 Mar 2013 22:31

Hey, very thanks.

I will look at this script in the next time.

No, I'm not the author of this script.

It would be nice, if there was a hotkey to delete the current file and a button next to the play button.

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 » 03 Mar 2013 13:01

For adding custom hotkeys in extension, please check following extension: Previous frame

Code: Select all

... function activate() vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press_handler ) end ... function key_press_handler( var, old, new, data ) if new==custom_key_code then -- do something end end ...

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

Re: Delete current file from harddisk

Postby 147852369 » 20 Jul 2013 00:36

I am trying to code a version for Windows.
But I have issues in my code. I don't know why

Code: Select all

vlc.playlist.current()
select the NEXT file in the playlist and not the current.
If I click on the "mark" button to call the mark() function, VLC crashes.

Code: Select all

--[[ INSTALLATION (create directories if they don't exist): - 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\ - Restart VLC. ]]-- --[[ Extension description ]] function descriptor() return { title = "Diskdelete for Windows" ; version = "0.1" ; author = "Caglar Yanik" ; shortdesc = "DELETE current playing FILE FROM DISK for WINDOWS"; description = "<h1>Diskdelete</h1>" .. "Windows does not delete files because of write permissions. " .. "<br>This extension saves the paths of the files to be deleted in a text file," .. "<br>then reads the batch file and deletes the files on CMD." .. "<br>It will not use the Recycle Bin, the file will be gone immediately!" .. "<br>This extension has been tested on Windows 7 64 bit with VLC 2.0.7." .. "<br>The author is not responsible for damage caused by this extension."; url = "" } end --[[ Hooks ]] -- Activation hook function activate() vlc.msg.dbg("[Diskdelete] Activated") d = vlc.dialog("Diskdelete") d:add_label("<b>Zum Löschen freigeben?</b>") d:add_button("JA, ZUM LÖSCHEN MARKIEREN!", mark) d:add_button("Next File!", nextFile) d:show() datei = io.open("C:/Users/ph/Desktop/VLC_toDelete.txt", "a+") end --activate -- Deactivation hook function deactivate() datei:close() vlc.msg.dbg("[Diskdelete for Windows] Deactivated") vlc.deactivate() end --deactivate function close() deactivate() end --close --[[ The file deletion routine ]] function mark() item = vlc.input.item() -- get the current playing file uri = item:uri() -- extract it's URI filename = vlc.strings.decode_uri(uri) -- decode %foo stuff from the URI filename = string.sub(filename,9) -- remove 'file://' prefix which is 8 chars long -- 9 on Windows filename = string.gsub(filename, "/", "\\") -- / replace \ for batch-file vlc.msg.dbg("[Diskdelete] selected for deletion: " .. filename) retval, err = datei:write(filename .. "\n") if(retval == nil) -- if write failed, print why then vlc.msg.dbg("[Diskdelete] error: " .. err) errord = io.open("C:/Users/ph/Desktop/VLC_toDeleteERRORS.txt", "a+") errord:write(filename .. "\t" .. err .. "\n") errord:close() else currentID = vlc.playlist.current() vlc.playlist.delete(currentID) nextFile() filename=nil currentID=nil end --if end --mark function nextFile() vlc.playlist.skip(1) end --next -- This empty function is there, because vlc pested me otherwise function meta_changed() 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: Delete current file from harddisk

Postby mederi » 21 Jul 2013 13:42

Then use currentID-1.
There is also an issue: if you remove actual item from playlist, it does not play next file. It is just like you would press Stop and then try to press Next button. Or try to manually delete currently playing item in the playlist (mark item with mouse, then press Delete keyboard key), then press Next button.

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

Re: Delete current file from harddisk

Postby 147852369 » 22 Jul 2013 23:00

I've tried currentID-1. You're right with that issue.
Your suggestion is that what I wanna avoid with this script to work efficient.
I just want to click on "Delete", which deletes the current file from the playlist and writes its path in a text-doc.

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 » 23 Jul 2013 12:28

Try to use function meta_changed() to delete items in playlist and files from harddisk. The function is automatically called several times when starting to play an item and once at the end of it. Just compare currentID with newID: if newID does not equal to currentID, then VLC is already playing another item and so it is possible to delete previous item/file (currentID). I think it is possible to do it this way.

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

Re: Delete current file from harddisk

Postby 147852369 » 23 Jul 2013 20:39

I'm fed up. :D Maybe I will try to programme this next time. My extension works fine for me at the moment without the feature to delete the playlist. Whatever.

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 » 24 Jul 2013 18:56

O.K. And what do you do with the generated list of paths "VLC_toDelete.txt" that is available as soon as the extension is closed (deactivated)?

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

Re: Delete current file from harddisk

Postby 147852369 » 01 Jan 2014 23:15

Sorry for late posting.
I wrote a batch file, that reads the lines of VLC_toDelete.txt and delete the files in CMD. That works fine in Windows.

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 » 09 Jan 2014 14:49

Let meta_changed() do the deleting of current item when starting the next one. Try this:

Code: Select all

function descriptor() return { title = "Diskdelete for Windows", capabilities = {"meta-listener"} } end function activate() vlc.msg.dbg("[Diskdelete] Activated") d = vlc.dialog("Diskdelete") label=d:add_label("<b>Diskdelete</b>",1,1,2,1) d:add_button("Play Next", play_Next,1,2) d:add_button("Delete", click_Delete,2,2) d:show() end function deactivate() vlc.msg.dbg("[Diskdelete for Windows] Deactivated") end function close() vlc.deactivate() end counter=0 function meta_changed() vlc.msg.info("[Diskdelete] meta_changed: " .. os.clock()) newID = vlc.playlist.current() if currentID and currentID~=newID then counter=counter+1 if counter==4 then vlc.playlist.delete(currentID-1) currentID=nil counter=0 Delete_file() end end end function click_Delete() item = vlc.input.item() status = vlc.playlist.status() if item and (status=="playing" or status=="paused") then uri = item:uri() filename = vlc.strings.decode_uri(uri) filename = string.sub(filename,9) filename = string.gsub(filename, "/", "\\") vlc.msg.dbg("[Diskdelete] selected for deletion: " .. filename) currentID = vlc.playlist.current() play_Next() end end function play_Next() vlc.playlist.next() end function Delete_file() 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(filename.."<br /><b>DELETED!</b>") end filename=nil end end

yoestiee
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 17:17

Re: Delete current file from harddisk

Postby yoestiee » 11 Jan 2014 17:19

In how much time this feature will be coded ? Can't wait for it !!!

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

Re: Delete current file from harddisk

Postby 147852369 » 11 Jan 2014 17:23

I can't test your code the next time. Sorry. I won't be at home on my pc.

But what is the difference between your and my code?

@yoestiee: You can use the code. It works, but there are some issues to solve.
My code runs under older VLC versions and I use hot keys.

I will post my finally code when I'll be at home in few weeks.

Edit: Ok. I'm sorry. The difference is, that you solve the playlist issue, right?

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 » 12 Jan 2014 13:55

Yes, it really removes items from playlist in VLC and also deletes files. Now somebody could gather all ideas into one universal extension (Windows&Linux; options: direct delete if possible, list only, batch, ...). :)
I wrote a batch file, that reads the lines of VLC_toDelete.txt and delete the files in CMD.
Can you share it?

yoestiee
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 17:17

Re: Delete current file from harddisk

Postby yoestiee » 12 Jan 2014 19:50

I would say move to recycle bin, most programs do this...

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

Re: Delete current file from harddisk

Postby 147852369 » 13 Jan 2014 20:12

That's fine.
I'm not at home.
But the batch file was like this:

Code: Select all

@ECHO OFF &SETLOCAL FOR /f "delims=" %%a IN (VLC_toDelete.txt) DO ( IF EXIST "%%~a" ( DEL "%%~a" 2>&1 |findstr . >nul &&echo %%a wurde nicht gelöscht. || echo %%a erfolgreich gelöscht. ) ELSE ( ECHO %%a nicht gefunden. ) )

Or this:

Code: Select all

:: Diese Batch-Datei gehört zu "Diskdelete for Windows". Diskdelete for Windows speichert die Pfade der zu löschenden Bilder in einer Textdatei. :: Diskdelete kann unter Windows die Dateien nicht direkt von der Festplatte löschen, da Windows diese nicht freigibt, weil sie gerade in Verwendung sind. Unter Linux funktioniert Disklete. :: Deswegen habe ich Diskdelete so modifiziert, dass die zu löschenden Dateien letztendlich über CMD gelöscht werden können. :: TO-DO: error-log, delete line of successfull deleted files, Error = color red @ECHO OFF &SETLOCAL title DiskdeleteForWindowsBatch set PFAD=C:\Users\ph\Desktop\VLC_toDelete.txt FOR /f "delims=" %%a IN (%PFAD%) DO ( IF EXIST "%%~a" ( DEL "%%~a" /F /Q 2>&1 |findstr . >nul &&echo %%a wurde nicht gel”scht. || echo %%a erfolgreich gel”scht. ) ELSE ( ECHO %%a nicht gefunden. ) ) echo. echo. echo. echo Drcke eine beliebige Taste, um die Konsole zu schlieáen... pause > NUL

yoestiee
New Cone
New Cone
Posts: 5
Joined: 11 Jan 2014 17:17

Re: Delete current file from harddisk

Postby yoestiee » 16 Jan 2014 17:03

This will be implemented in next version of VLC ?

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

Re: Delete current file from harddisk

Postby 147852369 » 16 Jan 2014 17:06

No. Sorry. This is just an extension which you have to install by yourself. At the moment it works just in older VLC versions because of LUA.

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 » 18 Jan 2014 13:13

Dankeschön :)
The list of chosen files is actually m3u playlist. It could be used also for other purposes, for example for copying files to a destination directory: https://forum.videolan.org/viewtopic.ph ... 88#p395688
This could be another function of an "universal" VLC Extension. In this case a sum of file sizes would be a useful information.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: Anet26 and 2 guests