From 25b94bc2c1c08e61a4f735d10d2ea23adcf76cd1 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Mon, 28 Jun 2021 10:27:24 +0200 Subject: [PATCH] new script delete-current-file.lua --- src/Scripts/Lua/delete-current-file.lua | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Scripts/Lua/delete-current-file.lua diff --git a/src/Scripts/Lua/delete-current-file.lua b/src/Scripts/Lua/delete-current-file.lua new file mode 100644 index 0000000..07d90f8 --- /dev/null +++ b/src/Scripts/Lua/delete-current-file.lua @@ -0,0 +1,59 @@ + +-- This script removes the currently playing file from the playlist +-- and moves it into the recycle bin. Works only on Windows. + +-- input.conf: + +-- KP0 script-binding delete_current_file/delete +-- 0 script-binding delete_current_file/delete +-- KP1 script-binding delete_current_file/confirm +-- 1 script-binding delete_current_file/confirm + +local utils = require 'mp.utils' + +function delete_file() + local code = [[& { + Add-Type -AssemblyName Microsoft.VisualBasic + [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('FileToDelete', 'OnlyErrorDialogs', 'SendToRecycleBin') + }]] + + code = string.gsub(code, "FileToDelete", FileToDelete) + + utils.subprocess({ + args = { 'powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', code }, + playback_only = false, + }) +end + +function delete() + FileToDelete = mp.get_property("path") + DeleteTime = os.time() + mp.commandv("show-text", "Press 1 to delete file", "10000") +end + +function confirm() + local path = mp.get_property("path") + + if FileToDelete == path and (os.time() - DeleteTime) < 10 then + mp.commandv("show-text", "") + + local count = mp.get_property_number("playlist-count") + local pos = mp.get_property_number("playlist-pos") + + if pos == count - 1 then + newPos = pos - 1 + else + newPos = pos + 1 + end + + if newPos > -1 then + mp.set_property_number("playlist-pos", newPos) + end + + mp.command("playlist-remove " .. pos) + mp.add_timeout(2, delete_file) + end +end + +mp.add_key_binding(nil, "delete", delete) +mp.add_key_binding(nil, "confirm", confirm)