From 3520ce6a3f4762fd6fbbf6e8c0cee1f62301b4b4 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Thu, 1 Jul 2021 14:16:05 +0200 Subject: [PATCH] script update --- src/Misc/CorePlayer.cs | 20 +++++++++++ src/Misc/PowerShell.cs | 2 +- src/Resources/mpv.conf.txt | 3 -- src/Scripts/C-Sharp/delete-current-file.cs | 40 +++++++++++----------- src/Scripts/Lua/delete-current-file.lua | 3 +- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index f8fdc63..3b79ea6 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -639,6 +639,11 @@ namespace mpvnet IsLogoVisible = false; } + public void Command(string command, bool throwException = false) + { + this.command(command, throwException); + } + public void command(string command, bool throwException = false) { mpv_error err = mpv_command_string(Handle, command); @@ -647,6 +652,11 @@ namespace mpvnet HandleError(err, throwException, "error executing command:", command); } + public void CommandV(params string[] args) + { + commandv(args); + } + public void commandv(params string[] args) { int count = args.Length + 1; @@ -737,6 +747,11 @@ namespace mpvnet HandleError(err, throwException, $"error setting property: {name} = {value}"); } + public int GetPropertyInt(string name, bool throwException = false) + { + return get_property_int(name, throwException); + } + public int get_property_int(string name, bool throwException = false) { mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), @@ -768,6 +783,11 @@ namespace mpvnet return value; } + public void SetPropertyNumber(string name, double value, bool throwException = false) + { + set_property_number(name, value, throwException); + } + public void set_property_number(string name, double value, bool throwException = false) { double val = value; diff --git a/src/Misc/PowerShell.cs b/src/Misc/PowerShell.cs index ea1582d..4793715 100644 --- a/src/Misc/PowerShell.cs +++ b/src/Misc/PowerShell.cs @@ -58,7 +58,7 @@ namespace mpvnet Pipeline.Output.DataReady += Output_DataReady; Pipeline.Error.DataReady += Error_DataReady; } - + return Pipeline.Invoke(); } catch (RuntimeException e) diff --git a/src/Resources/mpv.conf.txt b/src/Resources/mpv.conf.txt index a22a874..5e31d61 100644 --- a/src/Resources/mpv.conf.txt +++ b/src/Resources/mpv.conf.txt @@ -8,6 +8,3 @@ osd-duration = 2000 osd-playing-msg = '${filename}' script-opts = osc-scalewindowed=1.5,osc-hidetimeout=2000,console-scale=1 screenshot-directory = '~~desktop/' - -[protocol.https] -osd-playing-msg = '${media-title}' diff --git a/src/Scripts/C-Sharp/delete-current-file.cs b/src/Scripts/C-Sharp/delete-current-file.cs index 0e5612c..9458815 100644 --- a/src/Scripts/C-Sharp/delete-current-file.cs +++ b/src/Scripts/C-Sharp/delete-current-file.cs @@ -3,8 +3,11 @@ // In input.conf add: -// KP0 script-message delete-current-file ask #menu: Script > Delete current file > Ask +// KP0 script-message delete-current-file delete #menu: Script > Delete current file > Delete +// 0 script-message delete-current-file delete #menu: Script > Delete current file > Delete + // KP1 script-message delete-current-file confirm #menu: Script > Delete current file > Confirm +// 1 script-message delete-current-file confirm #menu: Script > Delete current file > Confirm using System; using System.IO; @@ -31,37 +34,34 @@ class Script if (args == null || args.Length != 2 || args[0] != "delete-current-file") return; - if (args[1] == "ask") + if (args[1] == "delete") { - FileToDelete = Core.get_property_string("path"); + FileToDelete = Core.GetPropertyString("path"); DeleteTime = DateTime.Now; - Core.commandv("show-text", "Press 1 to delete file", "10000"); + Core.CommandV("show-text", "Press 1 to delete file", "10000"); } else if (args[1] == "confirm") { TimeSpan ts = DateTime.Now - DeleteTime; - string path = Core.get_property_string("path"); + string path = Core.GetPropertyString("path"); if (FileToDelete == path && ts.TotalSeconds < 10 && File.Exists(FileToDelete)) { - Core.command("playlist-remove current"); - int pos = Core.get_property_int("playlist-pos"); + Core.CommandV("show-text", ""); - if (pos == -1) - { - int count = Core.get_property_int("playlist-count"); + int count = Core.GetPropertyInt("playlist-count"); + int pos = Core.GetPropertyInt("playlist-pos"); + int newPos = pos == count - 1 ? pos - 1 : pos + 1; - if (count > 0) - Core.set_property_int("playlist-pos", count - 1); - else - { - Core.ShowLogo(); - Core.commandv("show-text", ""); - } - } + if (newPos > -1) + Core.SetPropertyNumber("playlist-pos", newPos); - Thread.Sleep(2000); - FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + Core.Command("playlist-remove " + pos); + + App.RunTask(() => { + Thread.Sleep(2000); + FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); + }); } } } diff --git a/src/Scripts/Lua/delete-current-file.lua b/src/Scripts/Lua/delete-current-file.lua index 07d90f8..80c56da 100644 --- a/src/Scripts/Lua/delete-current-file.lua +++ b/src/Scripts/Lua/delete-current-file.lua @@ -1,6 +1,5 @@ --- This script removes the currently playing file from the playlist --- and moves it into the recycle bin. Works only on Windows. +-- This script deletes the file that is currently playing. -- input.conf: