add script delete_file.lua

This commit is contained in:
zenyd 2017-10-19 21:26:02 +02:00
parent 2d0388fc90
commit 5cccb90061
2 changed files with 49 additions and 0 deletions

View File

@ -21,6 +21,7 @@ Key Bind|Effect
`alt + '+'`|Increase speedup
`alt + '-'`|Decrease speedup
## subselect
A lua script for downloading subtitles using a GUI and automatically loading them in mpv. It lets you input the name of the video but mainly tries to guess it based on the video title. Uses subliminal for subtitle download and Python tkinter for GUI. Works both on Windows and Linux (possibly macOS too?).
@ -53,3 +54,9 @@ sub_language=deu
### Usage
First invoke the script using `alt + u`, input a movie name, or use the one provided by the script, search and download subtitles. If you want to change the language for the subtitles append `;[3-letter ISO-639-3 code]`. So if you want to search for e.g. german subtitles append `;deu`.
## delete-file
As the name suggests this is a small script for deleting files played through mpv. You can mark a file to be deleted and can unmark it if desired. Once quitting mpv, the script starts the deletion process. This is platform-agnostic so should work everywhere.
`ctrl + DEL`: mark/unmark file to be deleted

42
delete_file.lua Normal file
View File

@ -0,0 +1,42 @@
local utils = require "mp.utils"
del_list = {}
function contains_item(l, i)
for k, v in pairs(l) do
if v == i then
mp.osd_message("undeleting current file")
l[k] = nil
return true
end
end
mp.osd_message("deleting current file")
return false
end
function mark_delete()
local work_dir = mp.get_property_native("working-directory")
local file_path = mp.get_property_native("path")
local s = file_path:find(work_dir, 0, true)
local final_path
if s and s == 0 then
final_path = file_path
else
final_path = utils.join_path(work_dir, file_path)
end
if not contains_item(del_list, final_path) then
table.insert(del_list, final_path)
end
end
function delete(e)
if e.reason == "quit" then
for i, v in pairs(del_list) do
print("deleting: "..v)
os.remove(v)
end
end
end
mp.add_key_binding("ctrl+DEL", "delete_file", mark_delete)
mp.register_event("end-file", delete)