-
Notifications
You must be signed in to change notification settings - Fork 14
/
vlc-delete.lua
142 lines (124 loc) · 3.73 KB
/
vlc-delete.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
--[[
Copyright 2015-2023 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 filesystem";
description = [[
<h1>vlc-delete</h1>"
When you're playing a file, use VLC Delete to
delete the current file from your playlist <b>and filesystem</b> with one click.<br />
This extension has been tested on GNU Linux with VLC 2.x and 3.x.<br />
The author is not responsible for damage caused by this extension.
]];
}
end
function file_exists(file)
retval, err = os.execute("if exist \"" .. file .. "\" (exit 0) else (exit 1)")
return type(retval) == "number" and retval == 0
end
function sleep(seconds)
local t_0 = os.clock()
while os.clock() - t_0 <= seconds do end
end
function windows_delete(file, trys, pause)
if not file_exists(file) then
return nil, "File does not exist"
end
for i = trys, 1, -1
do
os.execute("del /q \"" .. file .. "\"")
if not file_exists(file) then
return true
end
sleep(pause)
end
return nil, "Unable to delete file"
end
function remove_from_playlist_and_filesystem()
local id = vlc.playlist.current()
vlc.playlist.next()
sleep(1)
vlc.playlist.delete(id)
end
function command_exists(command)
retval, err = os.execute(command)
return retval ~= nil
end
function current_uri_and_os()
local item = (vlc.player or vlc.input).item()
local uri = item:uri()
local is_posix = (package.config:sub(1, 1) == "/")
if uri:find("^file:///") ~= nil then
uri = string.gsub(uri, "^file:///", "")
uri = vlc.strings.decode_uri(uri)
if is_posix then
uri = "/" .. uri
else
uri = string.gsub(uri, "/", "\\")
end
end
return uri, is_posix
end
function activate()
local uri, is_posix = current_uri_and_os()
if is_posix then
local trash_put_exists = command_exists("trash-put --version > /dev/null")
local rm_exists = command_exists("rm --version > /dev/null")
if trash_put_exists then
vlc.msg.info("[vlc-delete] removing: " .. uri .. " (using trash-put)")
uri = string.gsub(uri, "\"", "\\\"")
retval, err = os.execute("trash-put \"" .. uri .. "\"")
elseif rm_exists then
vlc.msg.info("[vlc-delete] removing: " .. uri .. " (using rm)")
uri = string.gsub(uri, "\"", "\\\"")
retval, err = os.execute("rm \"" .. uri .. "\"")
else
vlc.msg.info("[vlc-delete] removing: " .. uri .. " (using os.remove)")
retval, err = os.remove(file)
end
if retval ~= nil then
remove_from_playlist_and_filesystem()
end
else
vlc.msg.info("[vlc-delete] removing: " .. uri)
remove_from_playlist_and_filesystem() -- remove first so the file isn't locked by VLC
retval, err = windows_delete(uri, 3, 1)
end
if retval == nil then
vlc.msg.info("[vlc-delete] error: " .. (err or "nil"))
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()
else
deactivate()
end
end
function click_ok()
d:delete()
deactivate()
end
function deactivate()
vlc.deactivate()
end
function close()
deactivate()
end
function meta_changed()
end