script update

This commit is contained in:
Frank Skare
2021-07-01 14:16:05 +02:00
parent 376f8226ab
commit 3520ce6a3f
5 changed files with 42 additions and 26 deletions

View File

@@ -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;

View File

@@ -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}'

View File

@@ -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);
});
}
}
}

View File

@@ -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: