Support for encoding mode and thumbfast and some other new features and improvements
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using MpvNet.Help;
|
||||
|
||||
namespace MpvNet;
|
||||
@@ -17,15 +18,16 @@ public class Command
|
||||
["play-pause"] = PlayPause,
|
||||
["shell-execute"] = args => ProcessHelp.ShellExecute(args[0]),
|
||||
["show-text"] = args => ShowText(args[0], Convert.ToInt32(args[1]), Convert.ToInt32(args[2])),
|
||||
["show-commands"] = args => ShowCommands(),
|
||||
["cycle-audio"] = args => CycleAudio(),
|
||||
["cycle-subtitles"] = args => CycleSubtitles(),
|
||||
["playlist-first"] = args => PlaylistFirst(),
|
||||
["playlist-last"] = args => PlaylistLast(),
|
||||
|
||||
|
||||
// deprecated
|
||||
["playlist-add"] = args => PlaylistAdd(Convert.ToInt32(args[0])), // deprecated
|
||||
["show-progress"] = args => ShowProgress(), // deprecated
|
||||
["cycle-audio"] = args => CycleAudio(), // deprecated
|
||||
["cycle-subtitles"] = args => CycleSubtitles(), // deprecated
|
||||
["playlist-first"] = args => PlaylistFirst(), // deprecated
|
||||
["playlist-last"] = args => PlaylistLast(), // deprecated
|
||||
["playlist-random"] = args => PlaylistRandom(), // deprecated
|
||||
};
|
||||
|
||||
@@ -50,6 +52,37 @@ public class Command
|
||||
}
|
||||
}
|
||||
|
||||
public static void ShowCommands()
|
||||
{
|
||||
string json = Core.GetPropertyString("command-list");
|
||||
var enumerator = JsonDocument.Parse(json).RootElement.EnumerateArray();
|
||||
var commands = enumerator.OrderBy(it => it.GetProperty("name").GetString());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (var cmd in commands)
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(cmd.GetProperty("name").GetString());
|
||||
|
||||
foreach (var args in cmd.GetProperty("args").EnumerateArray())
|
||||
{
|
||||
string value = args.GetProperty("name").GetString() + " <" +
|
||||
args.GetProperty("type").GetString()!.ToLower() + ">";
|
||||
|
||||
if (args.GetProperty("optional").GetBoolean())
|
||||
value = "[" + value + "]";
|
||||
|
||||
sb.AppendLine(" " + value);
|
||||
}
|
||||
}
|
||||
|
||||
string header = BR +
|
||||
"https://mpv.io/manual/master/#list-of-input-commands" + BR2 +
|
||||
"https://github.com/stax76/mpv-scripts#command_palette" + BR;
|
||||
|
||||
ShowTextWithEditor("Input Commands", header + sb.ToString());
|
||||
}
|
||||
|
||||
public static void ShowText(string text, int duration = 0, int fontSize = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
@@ -64,43 +97,15 @@ public class Command
|
||||
Player.Command("show-text \"${osd-ass-cc/0}{\\\\fs" + fontSize +
|
||||
"}${osd-ass-cc/1}" + text + "\" " + duration);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public static void PlaylistAdd(int value)
|
||||
|
||||
public static void ShowTextWithEditor(string name, string text)
|
||||
{
|
||||
int pos = Player.PlaylistPos;
|
||||
int count = Player.GetPropertyInt("playlist-count");
|
||||
|
||||
if (count < 2)
|
||||
return;
|
||||
|
||||
pos += value;
|
||||
|
||||
if (pos < 0)
|
||||
pos = count - 1;
|
||||
|
||||
if (pos > count - 1)
|
||||
pos = 0;
|
||||
|
||||
Player.SetPropertyInt("playlist-pos", pos);
|
||||
string file = Path.Combine(Path.GetTempPath(), name + ".txt");
|
||||
App.TempFiles.Add(file);
|
||||
File.WriteAllText(file, BR + text.Trim() + BR);
|
||||
ProcessHelp.ShellExecute(file);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public void ShowProgress()
|
||||
{
|
||||
TimeSpan position = TimeSpan.FromSeconds(Player.GetPropertyDouble("time-pos"));
|
||||
TimeSpan duration = TimeSpan.FromSeconds(Player.GetPropertyDouble("duration"));
|
||||
|
||||
string text = FormatTime(position.TotalMinutes) + ":" +
|
||||
FormatTime(position.Seconds) + " / " +
|
||||
FormatTime(duration.TotalMinutes) + ":" +
|
||||
FormatTime(duration.Seconds) + " " +
|
||||
DateTime.Now.ToString("H:mm dddd d MMMM", CultureInfo.InvariantCulture);
|
||||
|
||||
Player.CommandV("show-text", text, "5000");
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public static void CycleAudio()
|
||||
{
|
||||
Player.UpdateExternalTracks();
|
||||
@@ -129,7 +134,6 @@ public class Command
|
||||
}
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public static void CycleSubtitles()
|
||||
{
|
||||
Player.UpdateExternalTracks();
|
||||
@@ -162,13 +166,31 @@ public class Command
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public static void PlaylistAdd(int value)
|
||||
{
|
||||
int pos = Player.PlaylistPos;
|
||||
int count = Player.GetPropertyInt("playlist-count");
|
||||
|
||||
if (count < 2)
|
||||
return;
|
||||
|
||||
pos += value;
|
||||
|
||||
if (pos < 0)
|
||||
pos = count - 1;
|
||||
|
||||
if (pos > count - 1)
|
||||
pos = 0;
|
||||
|
||||
Player.SetPropertyInt("playlist-pos", pos);
|
||||
}
|
||||
|
||||
public static void PlaylistFirst()
|
||||
{
|
||||
if (Player.PlaylistPos != 0)
|
||||
Player.SetPropertyInt("playlist-pos", 0);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public static void PlaylistLast()
|
||||
{
|
||||
int count = Player.GetPropertyInt("playlist-count");
|
||||
@@ -183,4 +205,19 @@ public class Command
|
||||
int count = Player.GetPropertyInt("playlist-count");
|
||||
Player.SetPropertyInt("playlist-pos", new Random().Next(count));
|
||||
}
|
||||
|
||||
// deprecated
|
||||
public void ShowProgress()
|
||||
{
|
||||
TimeSpan position = TimeSpan.FromSeconds(Player.GetPropertyDouble("time-pos"));
|
||||
TimeSpan duration = TimeSpan.FromSeconds(Player.GetPropertyDouble("duration"));
|
||||
|
||||
string text = FormatTime(position.TotalMinutes) + ":" +
|
||||
FormatTime(position.Seconds) + " / " +
|
||||
FormatTime(duration.TotalMinutes) + ":" +
|
||||
FormatTime(duration.Seconds) + " " +
|
||||
DateTime.Now.ToString("H:mm dddd d MMMM", CultureInfo.InvariantCulture);
|
||||
|
||||
Player.CommandV("show-text", text, "5000");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user