misc
This commit is contained in:
11
Changelog.md
11
Changelog.md
@@ -1,10 +1,15 @@
|
||||
|
||||
### 5.4.4.2
|
||||
|
||||
- new: flag cli switches support now --no-flag in addition to --flag=no
|
||||
- new: cli switches can also start with single - instead of double --
|
||||
- new: flag cli switches support now `--no-flag` in addition to `--flag=no`
|
||||
- new: cli switches can also start with single `-` instead of double `--`
|
||||
- new: the PowerShell script host was completely rewritten, events can
|
||||
can be assigned to using `Register-ObjectEvent`
|
||||
can be assigned to using `Register-ObjectEvent`, the scripting
|
||||
wiki page was updated
|
||||
- new: Context Menu > View > Show Profiles
|
||||
- new: default mpv.conf is now generated with `osd-duration=2000` and
|
||||
`script-opts=...,console-scale=<DPI scale>` to
|
||||
workaround mpv using broken High DPI defaults
|
||||
|
||||
### 5.4.4.1
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
// This extension implements the C# scripting feature of mpv.net which
|
||||
// is based on CS-Script (https://www.cs-script.net).
|
||||
|
||||
@@ -13,7 +14,8 @@ using System.IO;
|
||||
using mpvnet;
|
||||
using CSScriptLibrary;
|
||||
|
||||
namespace ScriptingExtension // the file name of extensions must end with 'Extension'
|
||||
// the file name of extensions must end with 'Extension'
|
||||
namespace ScriptingExtension
|
||||
{
|
||||
[Export(typeof(IExtension))]
|
||||
public class ScriptingExtension : IExtension
|
||||
@@ -23,24 +25,29 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten
|
||||
public ScriptingExtension()
|
||||
{
|
||||
//Script = new Script();
|
||||
List<string> scriptFiles = new List<string>();
|
||||
List<string> files = new List<string>();
|
||||
|
||||
if (Directory.Exists(mp.ConfigFolder + "scripts"))
|
||||
scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs"));
|
||||
if (Directory.Exists(mp.ConfigFolder + "scripts-cs"))
|
||||
files.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts-cs", "*.cs"));
|
||||
|
||||
if (Directory.Exists(Folder.Startup + "scripts"))
|
||||
foreach (string path in Directory.GetFiles(Folder.Startup + "scripts", "*.cs"))
|
||||
scriptFiles.AddRange(Directory.GetFiles(Folder.Startup + "scripts", "*.cs"));
|
||||
files.AddRange(Directory.GetFiles(Folder.Startup + "scripts", "*.cs"));
|
||||
|
||||
if (files.Count == 0)
|
||||
return;
|
||||
|
||||
if (scriptFiles.Count == 0) return;
|
||||
CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
|
||||
foreach (var i in scriptFiles)
|
||||
foreach (string file in files)
|
||||
{
|
||||
try {
|
||||
CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(i));
|
||||
} catch (Exception e) {
|
||||
Msg.ShowException(e);
|
||||
try
|
||||
{
|
||||
CSScriptLibrary.CSScript.Evaluator.LoadCode(File.ReadAllText(file));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
App.ShowException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using UI;
|
||||
|
||||
using static libmpv;
|
||||
using static Common;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mpvnet
|
||||
|
||||
@@ -8,6 +8,10 @@ using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
|
||||
using VB = Microsoft.VisualBasic;
|
||||
using ScriptHost;
|
||||
|
||||
using static Common;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
@@ -38,6 +42,7 @@ namespace mpvnet
|
||||
case "show-info": ShowInfo(); break;
|
||||
case "playlist-first": PlaylistFirst(); break;
|
||||
case "playlist-last": PlaylistLast(); break;
|
||||
case "show-profiles": ShowProfiles(); break;
|
||||
case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019
|
||||
default: Msg.ShowError($"No command '{id}' found."); break;
|
||||
}
|
||||
@@ -293,5 +298,32 @@ namespace mpvnet
|
||||
mp.commandv("show-text", audTracks[aid - 1].Text.Substring(3), "5000");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowProfiles()
|
||||
{
|
||||
string psCode = @"
|
||||
foreach ($item in ($mpvjson | ConvertFrom-Json))
|
||||
{
|
||||
$item.name
|
||||
''
|
||||
|
||||
foreach ($option in $item.options)
|
||||
{
|
||||
' ' + $option.key + ' = ' + $option.value
|
||||
}
|
||||
|
||||
''
|
||||
}";
|
||||
|
||||
string json = mp.get_property_string("profile-list");
|
||||
PowerShell ps = new PowerShell();
|
||||
ps.Print = false;
|
||||
ps.Scripts.Add(psCode);
|
||||
string file = Path.GetTempPath() + @"\mpv profiles.txt";
|
||||
File.WriteAllText(file, BR + string.Join("\r\n", (ps.Invoke("mpvjson", json)
|
||||
as IEnumerable<object>).Select(x => x.ToString())).ToString());
|
||||
Process.Start(file);
|
||||
ps.Runspace.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,9 @@ public class WinAPI
|
||||
return GetWindowLong32(hWnd, nIndex);
|
||||
}
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
|
||||
@@ -144,6 +144,7 @@
|
||||
F8 script-binding show-playlist #menu: View > Show Playlist
|
||||
F9 show-text ${track-list} 5000 #menu: View > Show Audio/Video/Subtitle List
|
||||
p show-progress #menu: View > Show Progress
|
||||
Ctrl+p script-message mpv.net show-profiles #menu: View > Show Profiles
|
||||
` script-binding console/enable #menu: View > Show REPL
|
||||
|
||||
c script-message mpv.net show-conf-editor #menu: Settings > Show Config Editor
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
input-default-bindings = no
|
||||
|
||||
input-default-bindings = no
|
||||
input-ar-delay = 500
|
||||
input-ar-rate = 20
|
||||
keep-open = yes
|
||||
keep-open-pause = no
|
||||
osd-duration = 2000
|
||||
osd-playing-msg = '${filename}'
|
||||
script-opts = osc-scalewindowed=1.5
|
||||
script-opts = osc-scalewindowed=1.5,osc-hidetimeout=2000,console-scale=1
|
||||
screenshot-directory = '~~desktop/'
|
||||
cscale = spline36
|
||||
dscale = spline36
|
||||
scale = spline36
|
||||
hwdec = yes
|
||||
|
||||
[protocol.https]
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace ScriptHost
|
||||
|
||||
string BR = Environment.NewLine;
|
||||
|
||||
public object Invoke()
|
||||
public object Invoke() => Invoke(null, null);
|
||||
|
||||
public object Invoke(string variable, object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -39,6 +41,9 @@ namespace ScriptHost
|
||||
|
||||
Runspace.SessionStateProxy.SetVariable("ScriptHost", this);
|
||||
|
||||
if (!string.IsNullOrEmpty(variable))
|
||||
Runspace.SessionStateProxy.SetVariable(variable, obj);
|
||||
|
||||
if (Print)
|
||||
{
|
||||
Pipeline.Output.DataReady += Output_DataReady;
|
||||
@@ -65,7 +70,7 @@ namespace ScriptHost
|
||||
var output = sender as PipelineReader<PSObject>;
|
||||
|
||||
while (output.Count > 0)
|
||||
ConsoleHelp.Write(output.Read().ToString(), Module);
|
||||
ConsoleHelp.Write(output.Read(), Module);
|
||||
}
|
||||
|
||||
public void Error_DataReady(object sender, EventArgs e)
|
||||
@@ -73,7 +78,7 @@ namespace ScriptHost
|
||||
var output = sender as PipelineReader<Object>;
|
||||
|
||||
while (output.Count > 0)
|
||||
ConsoleHelp.WriteError(output.Read().ToString(), Module);
|
||||
ConsoleHelp.WriteError(output.Read(), Module);
|
||||
}
|
||||
|
||||
public void RedirectEventJobStreams(PSEventJob job)
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using UI;
|
||||
using ScriptHost;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
@@ -294,18 +295,6 @@ namespace mpvnet
|
||||
height = Convert.ToInt32(height * scale);
|
||||
int width = Convert.ToInt32(height * size.Width / (double)size.Height);
|
||||
|
||||
if (height > screen.WorkingArea.Height * 0.9)
|
||||
{
|
||||
height = Convert.ToInt32(screen.WorkingArea.Height * 0.9);
|
||||
width = Convert.ToInt32(height * size.Width / (double)size.Height);
|
||||
}
|
||||
|
||||
if (width > screen.WorkingArea.Width * 0.9)
|
||||
{
|
||||
width = Convert.ToInt32(screen.WorkingArea.Width * 0.9);
|
||||
height = Convert.ToInt32(width * size.Height / (double)size.Width);
|
||||
}
|
||||
|
||||
if (height < screen.WorkingArea.Height * mp.AutofitSmaller)
|
||||
{
|
||||
height = Convert.ToInt32(screen.WorkingArea.Height * mp.AutofitSmaller);
|
||||
@@ -318,6 +307,18 @@ namespace mpvnet
|
||||
width = Convert.ToInt32(height * size.Width / (double)size.Height);
|
||||
}
|
||||
|
||||
if (height > screen.WorkingArea.Height * 0.95)
|
||||
{
|
||||
height = Convert.ToInt32(screen.WorkingArea.Height * 0.95);
|
||||
width = Convert.ToInt32(height * size.Width / (double)size.Height);
|
||||
}
|
||||
|
||||
if (width > screen.WorkingArea.Width * 0.95)
|
||||
{
|
||||
width = Convert.ToInt32(screen.WorkingArea.Width * 0.95);
|
||||
height = Convert.ToInt32(width * size.Height / (double)size.Width);
|
||||
}
|
||||
|
||||
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
|
||||
var rect = new WinAPI.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));
|
||||
NativeHelp.AddWindowBorders(Handle, ref rect);
|
||||
@@ -687,8 +688,8 @@ namespace mpvnet
|
||||
if (!mp.ShutdownAutoResetEvent.WaitOne(10000))
|
||||
Msg.ShowError("Shutdown thread failed to complete within 10 seconds.");
|
||||
|
||||
//foreach (var i in PowerShell1.Instances)
|
||||
// i.RS.Close();
|
||||
foreach (PowerShell ps in PowerShell.Instances)
|
||||
ps.Runspace.Dispose();
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
|
||||
@@ -170,7 +170,8 @@ namespace mpvnet
|
||||
|
||||
if (!Directory.Exists(_ConfigFolder))
|
||||
{
|
||||
string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\mpv.net\";
|
||||
string appdataFolder = Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData) + @"\mpv.net\";
|
||||
|
||||
using (TaskDialog<string> td = new TaskDialog<string>())
|
||||
{
|
||||
@@ -217,7 +218,17 @@ namespace mpvnet
|
||||
File.WriteAllText(_ConfigFolder + "input.conf", Properties.Resources.inputConf);
|
||||
|
||||
if (!File.Exists(_ConfigFolder + "mpv.conf"))
|
||||
File.WriteAllText(_ConfigFolder + "mpv.conf", Properties.Resources.mpvConf);
|
||||
{
|
||||
string conf = Properties.Resources.mpvConf;
|
||||
Graphics gx = Graphics.FromHwnd(IntPtr.Zero);
|
||||
float scale = GetDeviceCaps(gx.GetHdc(), 88 /*LOGPIXELSX*/) / 96.0f;
|
||||
|
||||
if (scale != 1)
|
||||
conf = conf.Replace("console-scale=1", "console-scale=" + scale);
|
||||
|
||||
gx.Dispose();
|
||||
File.WriteAllText(_ConfigFolder + "mpv.conf", conf);
|
||||
}
|
||||
}
|
||||
|
||||
return _ConfigFolder;
|
||||
@@ -262,26 +273,29 @@ namespace mpvnet
|
||||
{
|
||||
if (Directory.Exists(Folder.Startup + "Scripts"))
|
||||
{
|
||||
foreach (string scriptPath in Directory.GetFiles(Folder.Startup + "Scripts"))
|
||||
foreach (string file in Directory.GetFiles(Folder.Startup + "Scripts"))
|
||||
{
|
||||
if (KnownScripts.Contains(Path.GetFileName(scriptPath)))
|
||||
if (KnownScripts.Contains(Path.GetFileName(file)))
|
||||
{
|
||||
if (scriptPath.EndsWith(".py"))
|
||||
App.RunAction(() => PythonScripts.Add(new PythonScript(scriptPath)));
|
||||
else if (scriptPath.EndsWith(".ps1"))
|
||||
App.RunAction(() => InvokePowerShellScript(scriptPath));
|
||||
if (file.EndsWith(".py"))
|
||||
App.RunAction(() => PythonScripts.Add(new PythonScript(file)));
|
||||
else if (file.EndsWith(".ps1"))
|
||||
App.RunAction(() => InvokePowerShellScript(file));
|
||||
}
|
||||
else
|
||||
Msg.ShowError("Failed to load script", scriptPath + BR + "Only scripts that ship with mpv.net are allowed in <startup>\\scripts\n\nUser scripts have to use <config folder>\\scripts\n\nNever copy or install a new mpv.net version over a old mpv.net version.");
|
||||
Msg.ShowError("Failed to load script", file + BR2 +
|
||||
"Only scripts that ship with mpv.net are allowed in <startup>\\scripts" + BR2 +
|
||||
"Never copy or install a new mpv.net version over a old mpv.net version.");
|
||||
}
|
||||
}
|
||||
|
||||
if (Directory.Exists(ConfigFolder + "scripts"))
|
||||
foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "scripts"))
|
||||
if (scriptPath.EndsWith(".py"))
|
||||
App.RunAction(() => PythonScripts.Add(new PythonScript(scriptPath)));
|
||||
else if (scriptPath.EndsWith(".ps1"))
|
||||
App.RunAction(() => InvokePowerShellScript(scriptPath));
|
||||
if (Directory.Exists(ConfigFolder + "scripts-py"))
|
||||
foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "scripts-py", "*.py"))
|
||||
App.RunAction(() => PythonScripts.Add(new PythonScript(scriptPath)));
|
||||
|
||||
if (Directory.Exists(ConfigFolder + "scripts-ps"))
|
||||
foreach (string file in Directory.GetFiles(ConfigFolder + "scripts-ps", "*.ps1"))
|
||||
App.RunAction(() => InvokePowerShellScript(file));
|
||||
}
|
||||
|
||||
public static void InvokePowerShellScript(string file)
|
||||
@@ -396,6 +410,7 @@ namespace mpvnet
|
||||
{
|
||||
var data = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
|
||||
string[] args = ConvertFromUtf8Strings(data.args, data.num_args);
|
||||
|
||||
if (args.Length > 1 && args[0] == "mpv.net")
|
||||
Command.Execute(args[1], args.Skip(2).ToArray());
|
||||
else if (args.Length > 0)
|
||||
|
||||
Reference in New Issue
Block a user