diff --git a/README.md b/README.md index 687d44e..7002187 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/delete_file.lua b/delete_file.lua new file mode 100644 index 0000000..b71be7b --- /dev/null +++ b/delete_file.lua @@ -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) \ No newline at end of file