New media info command

This commit is contained in:
Frank Skare
2021-05-30 14:39:15 +02:00
parent f56502d8f3
commit 539f94d1c9
9 changed files with 70 additions and 15 deletions

View File

@@ -12,6 +12,8 @@ namespace mpvnet
{
public static class App
{
public static List<string> TempFiles { get; } = new List<string>();
public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; }
public static string ProcessInstance { get; set; } = "single";
public static string DarkMode { get; set; } = "always";
@@ -164,6 +166,9 @@ namespace mpvnet
Settings.Mute = Core.get_property_string("mute");
SettingsManager.Save(Settings);
foreach (string file in TempFiles)
FileHelp.Delete(file);
}
static Dictionary<string, string> _Conf;

View File

@@ -8,15 +8,13 @@ using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows;
using VB = Microsoft.VisualBasic;
using static mpvnet.Global;
namespace mpvnet
{
public class Commands
{
public static void Execute(string id, string[] args = null)
public static void Execute(string id, string[] args)
{
switch (id)
{
@@ -44,8 +42,9 @@ namespace mpvnet
case "show-info": ShowInfo(); break;
case "show-input-editor": ShowDialog(typeof(InputWindow)); break;
case "show-keys": ShowTextWithEditor("input-key-list", Core.get_property_string("input-key-list").Replace(",", BR)); break;
case "show-media-info": ShowMediaInfo(args); break;
case "show-media-search": ShowDialog(typeof(EverythingWindow)); break;
case "show-playlist": ShowPlaylist(); break;
case "show-playlist": ShowPlaylist(args); break;
case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break;
case "show-properties": ShowProperties(); break;
case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break;
@@ -54,7 +53,7 @@ namespace mpvnet
case "update-check": UpdateCheck.CheckOnline(true); break;
case "window-scale": WindowScale(float.Parse(args[0], CultureInfo.InvariantCulture)); break;
default: Msg.ShowError($"No command '{id}' found."); break;
default: App.ShowError($"No command '{id}' found."); break;
}
}
@@ -338,7 +337,8 @@ namespace mpvnet
public static void ShowTextWithEditor(string name, string text)
{
string file = Path.GetTempPath() + $"\\{name}.txt";
string file = Path.Combine(Path.GetTempPath(), name + ".txt");
App.TempFiles.Add(file);
File.WriteAllText(file, BR + text.Trim() + BR);
ProcessHelp.ShellExecute(file);
}
@@ -362,12 +362,12 @@ namespace mpvnet
"}${osd-ass-cc/1}" + text + "\" " + duration);
}
public static void ShowPlaylist(string[] args = null)
public static void ShowPlaylist(string[] args)
{
int duration = 5000;
if (args?.Length == 1)
duration = Convert.ToInt32(args[0]);
if (args.Length == 1 && int.TryParse(args[0], out int result))
duration = result;
var size = Core.get_property_number("osd-font-size");
Core.set_property_number("osd-font-size", 40);
@@ -378,5 +378,21 @@ namespace mpvnet
Core.set_property_number("osd-font-size", size);
});
}
public static void ShowMediaInfo(string[] args)
{
string path = Core.GetPropertyString("path");
if (File.Exists(path))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
{
bool full = args.Contains("full");
bool raw = args.Contains("raw");
string text = mediaInfo.GetSummary(full, raw);
ShowTextWithEditor(Path.GetFileName(path), text);
}
}
}
}
}

View File

@@ -762,6 +762,11 @@ namespace mpvnet
HandleError(err, throwException, $"error setting property: {name} = {value}");
}
public string GetPropertyString(string name, bool throwException = false)
{
return get_property_string(name, throwException);
}
public string get_property_string(string name, bool throwException = false)
{
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),

View File

@@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
@@ -11,6 +12,19 @@ using static mpvnet.Global;
namespace mpvnet
{
public static class FileHelp
{
public static void Delete(string path)
{
try {
if (File.Exists(path))
File.Delete(path);
} catch (Exception ex) {
Terminal.WriteError("Failed to delete file:" + BR + path + BR + ex.Message);
}
}
}
public static class ProcessHelp
{
public static void Execute(string file, string arguments = null)