Skip to content

Instantly share code, notes, and snippets.

@superbiche
Created October 10, 2015 17:11
Show Gist options
  • Save superbiche/e85cd613ec4d59ef6223 to your computer and use it in GitHub Desktop.
Save superbiche/e85cd613ec4d59ef6223 to your computer and use it in GitHub Desktop.
VLC plugin - delete currently playing file
--[[
INSTALLATION (create directories if they don't exist):
- put the file in the VLC subdir /lua/extensions, by default:
* 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/
* Windows: not supported - getting permission error on delete...
- Restart VLC.
]]--
--[[ Extension description ]]
function descriptor()
return {
title = "Diskdelete" ;
version = "0.1" ;
author = "Ingo Fischer (Inspired by solution of Mark Morschhäuser)" ;
shortdesc = "Delete currently playing file from disk";
description = "<h1>Delete current file</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.";
}
end
function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
-- Activate on Ctrl+Alt+D
function key_press( var, old, new, data )
local key = new
CTRL_ALT_D = 83886180
if key == CTRL_ALT_D then
delete()
end
end
--[[ Hooks ]]
-- Activation hook
function activate()
vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
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.msg.info(item)
for key,value in pairs(item:info()) do
print("found member " .. key);
end
filename = split(filename, "file://")[2]
vlc.msg.info("Deleting file: " .. 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.info("[Diskdelete] error: " .. err)
d = vlc.dialog("Error deleting file")
d:add_label(err)
d:show()
else
vlc.playlist.skip(1)
end
end
function meta_changed()
end
@e-desouza
Copy link

That didn't work on OSX so I modified it to this: https://gist.github.com/e-desouza/9c340a5373492befb1203428e458bbf5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment