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
@wolkenarchitekt
Copy link

This does not work with VLC > 2.05.
See https://github.com/zm33y/vlc-lua-sia and https://mailman.videolan.org/pipermail/vlc-devel/2012-March/087553.html
Seems like C is the language to go when writing VLC plugins nowadays...

@GBO330
Copy link

GBO330 commented Feb 5, 2018

Been looking for a vlc extension that acts as a 1-button delete-current-file (in windows), and from what I've found it's impossible...
Is there at least a way to -through 1 button/hotkey- copy the current file's path to clip board?

@PAEz
Copy link

PAEz commented Jan 8, 2019

@GBO330 try this...
https://gist.github.com/PAEz/d3a9be2471dbd39084136d974cdb9dd3
...seems to be working, but I really dont know lua so I hope it works for you, works for me.

@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