-
-
Save PAEz/d3a9be2471dbd39084136d974cdb9dd3 to your computer and use it in GitHub Desktop.
--[[ | |
Copyright 2015-2016 surrim | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
]]-- | |
function descriptor() | |
return { | |
title = "VLC Delete"; | |
version = "0.1"; | |
author = "surrim"; | |
url = "https://github.com/surrim/vlc-delete/"; | |
shortdesc = "Remove current file from playlist and disk"; | |
description = [[ | |
<h1>vlc-delete</h1>" | |
When you're playing a file, use VLC Delete to | |
delete the current file from your playlist and <b>disk</b> with one click.<br> | |
This extension has been tested on GNU Linux with VLC 2.1.5.<br> | |
The author is not responsible for damage caused by this extension. | |
]]; | |
} | |
end | |
-- Windows - Check if file exists | |
function fileExists(file) | |
return io.popen("if exist "..file.." (echo 1)"):read'*l'=='1' | |
end | |
function sleep(n) -- seconds | |
local t0 = os.clock() | |
local tOriginal=t0 | |
while os.clock() - t0 <= n and os.clock()>=tOriginal do end | |
end | |
-- Windows - try and delete a file with multiple attempts and a pause between each try - waiting for the file to unlock | |
function windowsDelete(file,trys,pause) | |
if not fileExists('"'..file..'"') then return nil,'File does not exist' end | |
for i = trys,1,-1 | |
do | |
retval, err = os.remove(file) | |
--retval, err = os.execute('del ' .. file ) | |
if retval==true then | |
return true | |
end | |
sleep(pause) -- wish i had a better timer than one second, want misc.mdate..could just bash it but you shouldnt ever wait more than one second so meh | |
end | |
return {nil,'Unable to delete file'} | |
end | |
function removeItem() | |
local id = vlc.playlist.current() | |
vlc.playlist.delete(id) | |
vlc.playlist.gotoitem(id + 1) | |
vlc.deactivate() | |
end | |
function activate() | |
local item = vlc.input.item() | |
local uri = item:uri() | |
uri = string.gsub(uri, '^file:///', '') | |
uri = vlc.strings.decode_uri(uri) | |
vlc.msg.info("[vlc-delete] removing: " .. uri) | |
-- check for non windows | |
if (package.config:sub(1,1) == "/") then | |
retval, err = os.execute("trash-put --help > /dev/null") | |
if (retval ~= nil) then | |
uri = "/" .. uri | |
retval, err = os.execute("trash-put \"" .. uri .. "\"") | |
else | |
retval, err = os.execute("rm --help > /dev/null") | |
if (retval ~= nil) then | |
uri = "/" .. uri | |
retval, err = os.execute("rm \"" .. uri .. "\"") | |
end | |
end | |
if (retval ~= nil) then removeItem() end | |
else | |
--windows, remove from playlist first so the file isnt locked by vlc | |
removeItem() | |
uri = string.gsub(uri, "/", "\\") | |
retval, err = windowsDelete(uri,3,1) | |
end | |
if (retval == nil) then | |
vlc.msg.info("[vlc-delete] error: " .. err) | |
d = vlc.dialog("VLC Delete") | |
d:add_label("Could not remove \"" .. uri .. "\"", 1, 1, 1, 1) | |
d:add_label(err, 1, 2, 1, 1) | |
d:add_button("OK", click_ok, 1, 3, 1, 1) | |
d:show() | |
end | |
end | |
function click_ok() | |
d:delete() | |
vlc.deactivate() | |
end | |
function deactivate() | |
vlc.deactivate() | |
end | |
function close() | |
deactivate() | |
end | |
function meta_changed() | |
end |
I copied in the extensions folder. How to run the script in VLC when it is opened?
@FelipeCostaGualberto
I have a SHOCKING memory and hardly remember making this, but just tried it in VLC 3.0.12 on Windows 10 and it still works.
After you add it to the directory you should see a new menu option under View "Remove current file from playlist and disk".
There is no hot key because I could not find a way to add one. Had another look just now and from my limited understanding I can only add a hot key if it has a dialog, which this doesnt. If I remember correctly the time I made it I think I used something like AutoHotKey to get a hot key. Sucks huh?
If anyone ever hears/learns of a way to add a hot key Id LOVE to hear it.
@FelipeCostaGualberto I have a SHOCKING memory and hardly remember making this, but just tried it in VLC 3.0.12 on Windows 10 and it still works. After you add it to the directory you should see a new menu option under View "Remove current file from playlist and disk". There is no hot key because I could not find a way to add one. Had another look just now and from my limited understanding I can only add a hot key if it has a dialog, which this doesnt. If I remember correctly the time I made it I think I used something like AutoHotKey to get a hot key. Sucks huh?
If anyone ever hears/learns of a way to add a hot key Id LOVE to hear it.
Thanks you are right.
Just going to View menu >> Remove current file from playlist and disk
do the job.
I can't get this to work on windows with latest VLC, file is removed from playlist but not from disk :(
Hey, this looks great! I was trying to get this to work with VLC 3.0.6 on Win 10, but haven't been having any luck... It shows up as installed, but I assume it's meant to add a button, but I don't see one anywhere? And the original Ctrl-Alt-D keystroke doesn't seem to work either.
Any tips?