This commit is contained in:
Frank Skare
2019-03-14 05:19:57 +01:00
parent a392c2c6da
commit 303355ce63
20 changed files with 242 additions and 22610 deletions

View File

@@ -11,7 +11,7 @@ Public Class CSScriptAddon
Implements IAddon Implements IAddon
Sub New() Sub New()
Dim scriptDir = mpv.mpvConfFolderPath + "scripts" Dim scriptDir = mp.mpvConfFolderPath + "scripts"
If Not Directory.Exists(scriptDir) Then Return If Not Directory.Exists(scriptDir) Then Return
Dim csFiles = Directory.GetFiles(scriptDir, "*.cs") Dim csFiles = Directory.GetFiles(scriptDir, "*.cs")
If csFiles.Count = 0 Then Return If csFiles.Count = 0 Then Return

View File

@@ -52,11 +52,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>.\CSScriptLibrary.dll</HintPath> <HintPath>.\CSScriptLibrary.dll</HintPath>
</Reference> </Reference>
<Reference Include="mpvnet, Version=0.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\mpv.net\bin\Debug\mpvnet.exe</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" /> <Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
@@ -117,5 +112,12 @@
<ItemGroup> <ItemGroup>
<Content Include="CSScriptLibrary.dll" /> <Content Include="CSScriptLibrary.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\mpv.net\mpv.net.csproj">
<Project>{1751f378-8edf-4b62-be6d-304c7c287089}</Project>
<Name>mpv.net</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project> </Project>

View File

@@ -8,11 +8,11 @@ Imports System.Runtime.InteropServices
' Review the values of the assembly attributes ' Review the values of the assembly attributes
<Assembly: AssemblyTitle("PowerShellAddon")> <Assembly: AssemblyTitle("CSScriptAddon")>
<Assembly: AssemblyDescription("")> <Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")> <Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("PowerShellAddon")> <Assembly: AssemblyProduct("CSScriptAddon")>
<Assembly: AssemblyCopyright("Copyright © 2017")> <Assembly: AssemblyCopyright("Copyright © 2019")>
<Assembly: AssemblyTrademark("")> <Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>

View File

@@ -50,8 +50,9 @@ class Script
### Changes ### Changes
### 1.? ### 1.1
- added support for Python scripting via IronPython
- show tracks and show playlist didn't work because the duration wasn't defined in the key bindings - show tracks and show playlist didn't work because the duration wasn't defined in the key bindings
### 1.0 ### 1.0

View File

@@ -14,8 +14,8 @@ namespace RatingAddon
public RatingAddon() public RatingAddon()
{ {
mpv.ClientMessage += mpv_ClientMessage; mp.ClientMessage += mpv_ClientMessage;
mpv.Shutdown += mpv_Shutdown; mp.Shutdown += mpv_Shutdown;
} }
private void mpv_Shutdown() private void mpv_Shutdown()
@@ -51,8 +51,8 @@ namespace RatingAddon
if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating)) if (args?.Length != 2 || args[0] != "rate-file" || ! int.TryParse(args[1], out rating))
return; return;
Dic[mpv.GetStringProp("path")] = rating; Dic[mp.GetStringProp("path")] = rating;
mpv.Command("show-text", $"Rating: {rating}"); mp.Command("show-text", $"Rating: {rating}");
} }
} }
} }

View File

@@ -85,6 +85,7 @@
<ProjectReference Include="..\mpv.net\mpv.net.csproj"> <ProjectReference Include="..\mpv.net\mpv.net.csproj">
<Project>{1751f378-8edf-4b62-be6d-304c7c287089}</Project> <Project>{1751f378-8edf-4b62-be6d-304c7c287089}</Project>
<Name>mpv.net</Name> <Name>mpv.net</Name>
<Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -28,7 +28,7 @@ namespace mpvnet
foreach (string i in Directory.GetDirectories(dir)) foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll")); catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll"));
dir = mpv.mpvConfFolderPath + "\\Addons"; dir = mp.mpvConfFolderPath + "\\Addons";
if (Directory.Exists(dir)) if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir)) foreach (string i in Directory.GetDirectories(dir))

View File

@@ -50,41 +50,41 @@ namespace mpvnet
d.Filter = Misc.GetFilter(Misc.FileTypes); d.Filter = Misc.GetFilter(Misc.FileTypes);
if (d.ShowDialog() == DialogResult.OK) if (d.ShowDialog() == DialogResult.OK)
mpv.LoadFiles(d.FileNames); mp.LoadFiles(d.FileNames);
} }
})); }));
} }
public static void open_config_folder(string[] args) public static void open_config_folder(string[] args)
{ {
Process.Start(mpv.mpvConfFolderPath); Process.Start(mp.mpvConfFolderPath);
} }
public static void show_keys(string[] args) public static void show_keys(string[] args)
{ {
Process.Start(mpv.InputConfPath); Process.Start(mp.InputConfPath);
} }
private static void CreateMpvConf() private static void CreateMpvConf()
{ {
if (!File.Exists(mpv.mpvConfPath)) if (!File.Exists(mp.mpvConfPath))
{ {
if (!Directory.Exists(mpv.mpvConfFolderPath)) if (!Directory.Exists(mp.mpvConfFolderPath))
Directory.CreateDirectory(mpv.mpvConfFolderPath); Directory.CreateDirectory(mp.mpvConfFolderPath);
File.WriteAllText(mpv.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files"); File.WriteAllText(mp.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files");
} }
} }
public static void show_prefs(string[] args) public static void show_prefs(string[] args)
{ {
CreateMpvConf(); CreateMpvConf();
Process.Start(mpv.mpvConfPath); Process.Start(mp.mpvConfPath);
} }
public static void history(string[] args) public static void history(string[] args)
{ {
var fp = mpv.mpvConfFolderPath + "history.txt"; var fp = mp.mpvConfFolderPath + "history.txt";
if (File.Exists(fp)) if (File.Exists(fp))
Process.Start(fp); Process.Start(fp);
@@ -103,7 +103,7 @@ namespace mpvnet
CreateMpvConf(); CreateMpvConf();
bool changed = false; bool changed = false;
string fp = mpv.mpvConfPath; string fp = mp.mpvConfPath;
var confLines = File.ReadAllLines(fp); var confLines = File.ReadAllLines(fp);
for (int i = 0; i < confLines.Length; i++) for (int i = 0; i < confLines.Length; i++)
@@ -130,21 +130,21 @@ namespace mpvnet
public static void show_info(string[] args) public static void show_info(string[] args)
{ {
var fi = new FileInfo(mpv.GetStringProp("path")); var fi = new FileInfo(mp.GetStringProp("path"));
using (var mi = new MediaInfo(fi.FullName)) using (var mi = new MediaInfo(fi.FullName))
{ {
var w = mi.GetInfo(MediaInfoStreamKind.Video, "Width"); var w = mi.GetInfo(MediaInfoStreamKind.Video, "Width");
var h = mi.GetInfo(MediaInfoStreamKind.Video, "Height"); var h = mi.GetInfo(MediaInfoStreamKind.Video, "Height");
var pos = TimeSpan.FromSeconds(mpv.GetIntProp("time-pos")); var pos = TimeSpan.FromSeconds(mp.GetIntProp("time-pos"));
var dur = TimeSpan.FromSeconds(mpv.GetIntProp("duration")); var dur = TimeSpan.FromSeconds(mp.GetIntProp("duration"));
string mibr = mi.GetInfo(MediaInfoStreamKind.Video, "BitRate"); string mibr = mi.GetInfo(MediaInfoStreamKind.Video, "BitRate");
if (mibr == "") if (mibr == "")
mibr = "0"; mibr = "0";
var br = Convert.ToInt32(mibr) / 1000.0 / 1000.0; var br = Convert.ToInt32(mibr) / 1000.0 / 1000.0;
var vf = mpv.GetStringProp("video-format").ToUpper(); var vf = mp.GetStringProp("video-format").ToUpper();
var fn = fi.Name; var fn = fi.Name;
if (fn.Length > 60) if (fn.Length > 60)
@@ -158,7 +158,7 @@ namespace mpvnet
((int)(fi.Length / 1024 / 1024)).ToString() + ((int)(fi.Length / 1024 / 1024)).ToString() +
$" MB - {w} x {h}\n{vf} - {br.ToString("f1")} Mb/s" + "\n" + fn; $" MB - {w} x {h}\n{vf} - {br.ToString("f1")} Mb/s" + "\n" + fn;
mpv.Command("show-text", info, "5000"); mp.Command("show-text", info, "5000");
string FormatTime(double value) => ((int)(Math.Floor(value))).ToString("00"); string FormatTime(double value) => ((int)(Math.Floor(value))).ToString("00");
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@ namespace mpvnet
SetFormPosSize(); SetFormPosSize();
Instance = this; Instance = this;
Hwnd = Handle; Hwnd = Handle;
ChangeFullscreen((mpv.mpvConv.ContainsKey("fullscreen") && mpv.mpvConv["fullscreen"] == "yes") || (mpv.mpvConv.ContainsKey("fs") && mpv.mpvConv["fs"] == "yes")); ChangeFullscreen((mp.mpvConv.ContainsKey("fullscreen") && mp.mpvConv["fullscreen"] == "yes") || (mp.mpvConv.ContainsKey("fs") && mp.mpvConv["fs"] == "yes"));
CMS = new ContextMenuStripEx(components); CMS = new ContextMenuStripEx(components);
CMS.Opened += CMS_Opened; CMS.Opened += CMS_Opened;
ContextMenuStrip = CMS; ContextMenuStrip = CMS;
@@ -44,15 +44,15 @@ namespace mpvnet
public void BuildMenu() public void BuildMenu()
{ {
if (!File.Exists(mpv.InputConfPath)) if (!File.Exists(mp.InputConfPath))
{ {
if (!Directory.Exists(mpv.mpvConfFolderPath)) if (!Directory.Exists(mp.mpvConfFolderPath))
Directory.CreateDirectory(mpv.mpvConfFolderPath); Directory.CreateDirectory(mp.mpvConfFolderPath);
File.WriteAllText(mpv.InputConfPath, Properties.Resources.input_conf); File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
} }
foreach (var i in File.ReadAllText(mpv.InputConfPath).SplitLinesNoEmpty()) foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
{ {
if (!i.Contains("#menu:")) if (!i.Contains("#menu:"))
continue; continue;
@@ -73,7 +73,7 @@ namespace mpvnet
var menuItem = CMS.Add(path, () => { var menuItem = CMS.Add(path, () => {
try try
{ {
mpv.CommandString(cmd, false); mp.CommandString(cmd, false);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -95,9 +95,9 @@ namespace mpvnet
private void mpv_PlaybackRestart() private void mpv_PlaybackRestart()
{ {
var fn = mpv.GetStringProp("filename"); var fn = mp.GetStringProp("filename");
BeginInvoke(new Action(() => { Text = fn + " - mpv.net " + Application.ProductVersion; })); BeginInvoke(new Action(() => { Text = fn + " - mpv.net " + Application.ProductVersion; }));
var fp = mpv.mpvConfFolderPath + "history.txt"; var fp = mp.mpvConfFolderPath + "history.txt";
if (LastHistory != fn && File.Exists(fp)) if (LastHistory != fn && File.Exists(fp))
{ {
@@ -166,19 +166,19 @@ namespace mpvnet
case 0x0100: // WM_KEYDOWN case 0x0100: // WM_KEYDOWN
case 0x0101: // WM_KEYUP case 0x0101: // WM_KEYUP
case 0x020A: // WM_MOUSEWHEEL case 0x020A: // WM_MOUSEWHEEL
if (mpv.MpvWindowHandle != IntPtr.Zero) if (mp.MpvWindowHandle != IntPtr.Zero)
Native.SendMessage(mpv.MpvWindowHandle, m.Msg, m.WParam, m.LParam); Native.SendMessage(mp.MpvWindowHandle, m.Msg, m.WParam, m.LParam);
break; break;
case 0x203: // Native.WM.LBUTTONDBLCLK case 0x203: // Native.WM.LBUTTONDBLCLK
if (!IsMouseInOSC()) if (!IsMouseInOSC())
mpv.CommandString("cycle fullscreen"); mp.CommandString("cycle fullscreen");
break; break;
case 0x0214: // WM_SIZING case 0x0214: // WM_SIZING
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam); var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
var r = rc; var r = rc;
NativeHelp.SubtractWindowBorders(Handle, ref r); NativeHelp.SubtractWindowBorders(Handle, ref r);
int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top; int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top;
float aspect = mpv.VideoSize.Width / (float)mpv.VideoSize.Height; float aspect = mp.VideoSize.Width / (float)mp.VideoSize.Height;
int d_w = (int)(c_h * aspect - c_w); int d_w = (int)(c_h * aspect - c_w);
int d_h = (int)(c_w / aspect - c_h); int d_h = (int)(c_w / aspect - c_h);
int[] d_corners = { d_w, d_h, -d_w, -d_h }; int[] d_corners = { d_w, d_h, -d_w, -d_h };
@@ -198,10 +198,10 @@ namespace mpvnet
void SetFormPosSize() void SetFormPosSize()
{ {
if (IsFullscreen || mpv.VideoSize.Width == 0) return; if (IsFullscreen || mp.VideoSize.Width == 0) return;
var wa = Screen.GetWorkingArea(this); var wa = Screen.GetWorkingArea(this);
int h = (int)(wa.Height * 0.6); int h = (int)(wa.Height * 0.6);
int w = (int)(h * mpv.VideoSize.Width / (float)mpv.VideoSize.Height); int w = (int)(h * mp.VideoSize.Width / (float)mp.VideoSize.Height);
Point middlePos = new Point(Left + Width / 2, Top + Height / 2); Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
var r = new Native.RECT(new Rectangle(0, 0, w, h)); var r = new Native.RECT(new Rectangle(0, 0, w, h));
NativeHelp.AddWindowBorders(Handle, ref r); NativeHelp.AddWindowBorders(Handle, ref r);
@@ -227,7 +227,7 @@ namespace mpvnet
base.OnDragDrop(e); base.OnDragDrop(e);
if (e.Data.GetDataPresent(DataFormats.FileDrop)) if (e.Data.GetDataPresent(DataFormats.FileDrop))
mpv.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]); mp.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[]);
} }
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
@@ -249,7 +249,7 @@ namespace mpvnet
var p2 = PointToScreen(e.Location); var p2 = PointToScreen(e.Location);
if (Math.Abs(p1.X - p2.X) < 10 && Math.Abs(p1.Y - p2.Y) < 10) if (Math.Abs(p1.X - p2.X) < 10 && Math.Abs(p1.Y - p2.Y) < 10)
mpv.Command("quit"); mp.Command("quit");
} }
protected override void OnMouseMove(MouseEventArgs e) protected override void OnMouseMove(MouseEventArgs e)
@@ -257,7 +257,7 @@ namespace mpvnet
base.OnMouseMove(e); base.OnMouseMove(e);
// send mouse command to make OSC show // send mouse command to make OSC show
mpv.CommandString($"mouse {e.X} {e.Y}"); mp.CommandString($"mouse {e.X} {e.Y}");
if (CursorHelp.IsPosDifferent(LastCursorPosChanged)) if (CursorHelp.IsPosDifferent(LastCursorPosChanged))
CursorHelp.Show(); CursorHelp.Show();
@@ -267,7 +267,7 @@ namespace mpvnet
{ {
base.OnFormClosed(e); base.OnFormClosed(e);
IsCloseRequired = false; IsCloseRequired = false;
mpv.Command("quit"); mp.Command("quit");
} }
bool IsMouseInOSC() bool IsMouseInOSC()
@@ -292,11 +292,11 @@ namespace mpvnet
private void MainForm_Load(object sender, EventArgs ea) private void MainForm_Load(object sender, EventArgs ea)
{ {
mpv.Init(); mp.Init();
mpv.ObserveBoolProp("fullscreen", MpvChangeFullscreen); mp.ObserveBoolProp("fullscreen", MpvChangeFullscreen);
mpv.Shutdown += Mpv_AfterShutdown; mp.Shutdown += Mpv_AfterShutdown;
mpv.VideoSizeChanged += Mpv_VideoSizeChanged; mp.VideoSizeChanged += Mpv_VideoSizeChanged;
mpv.PlaybackRestart += mpv_PlaybackRestart; mp.PlaybackRestart += mpv_PlaybackRestart;
} }
} }
} }

View File

@@ -1,14 +1,8 @@
using System; using System.Collections;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using static mpvnet.StaticUsing;
namespace mpvnet namespace mpvnet
{ {
public class Misc public class Misc
@@ -49,28 +43,4 @@ namespace mpvnet
return MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question); return MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
} }
} }
public class PyScript
{
ScriptEngine engine;
ScriptScope scope;
public PyScript(string code)
{
try
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
scope.ImportModule("clr");
engine.Execute("import clr", scope);
engine.Execute("clr.AddReference(\"mpvnet\")", scope);
engine.Execute("from mpvnet import *", scope);
engine.Execute(code, scope);
}
catch (Exception ex)
{
MsgError(ex.ToString());
}
}
}
} }

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.1.0.0")]

33
mpv.net/PyScript.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using static mpvnet.StaticUsing;
namespace mpvnet
{
public class PyScript
{
ScriptEngine engine;
ScriptScope scope;
public PyScript(string code)
{
try
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
scope.ImportModule("clr");
engine.Execute("import clr", scope);
engine.Execute("clr.AddReference(\"mpvnet\")", scope);
engine.Execute("from mpvnet import *", scope);
engine.Execute(code, scope);
}
catch (Exception ex)
{
MsgError(ex.ToString());
}
}
}
}

View File

@@ -29,6 +29,9 @@ namespace mpvnet
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref IntPtr data); public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref IntPtr data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref double data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref byte[] data); public static extern int mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref byte[] data);
@@ -102,7 +105,8 @@ namespace mpvnet
MPV_EVENT_PLAYBACK_RESTART = 21, MPV_EVENT_PLAYBACK_RESTART = 21,
MPV_EVENT_PROPERTY_CHANGE = 22, MPV_EVENT_PROPERTY_CHANGE = 22,
MPV_EVENT_CHAPTER_CHANGE = 23, MPV_EVENT_CHAPTER_CHANGE = 23,
MPV_EVENT_QUEUE_OVERFLOW = 24 MPV_EVENT_QUEUE_OVERFLOW = 24,
MPV_EVENT_HOOK = 25
} }
public enum mpv_format public enum mpv_format
@@ -168,7 +172,6 @@ namespace mpvnet
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct mpv_event_property public struct mpv_event_property
{ {
[MarshalAs(UnmanagedType.LPUTF8Str)]
public string name; public string name;
public mpv_format format; public mpv_format format;
public IntPtr data; public IntPtr data;

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -13,36 +14,43 @@ using static mpvnet.libmpv;
using static mpvnet.Native; using static mpvnet.Native;
using static mpvnet.StaticUsing; using static mpvnet.StaticUsing;
using PyRT = IronPython.Runtime;
namespace mpvnet namespace mpvnet
{ {
public delegate void MpvBoolPropChangeHandler(string propName, bool value); public delegate void MpvBoolPropChangeHandler(string propName, bool value);
public class mpv public class mp
{ {
public static event Action Shutdown;
public static event Action LogMessage;
public static event Action GetPropertyReply;
public static event Action<string[]> ClientMessage;
public static event Action PlaybackRestart;
public static event Action VideoSizeChanged; public static event Action VideoSizeChanged;
public static event Action<EndFileEventMode> EndFile; // Lua/JS evens libmpv events
public static event Action SetPropertyReply;
public static event Action CommandReply; // MPV_EVENT_NONE
public static event Action StartFile; public static event Action Shutdown; // shutdown MPV_EVENT_SHUTDOWN
public static event Action FileLoaded; public static event Action LogMessage; // log-message MPV_EVENT_LOG_MESSAGE
public static event Action TracksChanged; public static event Action GetPropertyReply; // get-property-reply MPV_EVENT_GET_PROPERTY_REPLY
public static event Action TrackSwitched; public static event Action SetPropertyReply; // set-property-reply MPV_EVENT_SET_PROPERTY_REPLY
public static event Action Idle; public static event Action CommandReply; // command-reply MPV_EVENT_COMMAND_REPLY
public static event Action Pause; public static event Action StartFile; // start-file MPV_EVENT_START_FILE
public static event Action Unpause; public static event Action<EndFileEventMode> EndFile; // end-file MPV_EVENT_END_FILE
public static event Action Tick; public static event Action FileLoaded; // file-loaded MPV_EVENT_FILE_LOADED
public static event Action ScriptInputDispatch; public static event Action TracksChanged; // MPV_EVENT_TRACKS_CHANGED
public static event Action VideoReconfig; public static event Action TrackSwitched; // MPV_EVENT_TRACK_SWITCHED
public static event Action AudioReconfig; public static event Action Idle; // idle MPV_EVENT_IDLE
public static event Action MetadataUpdate; public static event Action Pause; // MPV_EVENT_PAUSE
public static event Action Seek; public static event Action Unpause; // MPV_EVENT_UNPAUSE
public static event Action ChapterChange; public static event Action Tick; // tick MPV_EVENT_TICK
public static event Action QueueOverflow; public static event Action ScriptInputDispatch; // MPV_EVENT_SCRIPT_INPUT_DISPATCH
public static event Action<string[]> ClientMessage; // client-message MPV_EVENT_CLIENT_MESSAGE
public static event Action VideoReconfig; // video-reconfig MPV_EVENT_VIDEO_RECONFIG
public static event Action AudioReconfig; // audio-reconfig MPV_EVENT_AUDIO_RECONFIG
public static event Action MetadataUpdate; // MPV_EVENT_METADATA_UPDATE
public static event Action Seek; // seek MPV_EVENT_SEEK
public static event Action PlaybackRestart; // playback-restart MPV_EVENT_PLAYBACK_RESTART
// MPV_EVENT_PROPERTY_CHANGE
public static event Action ChapterChange; // MPV_EVENT_CHAPTER_CHANGE
public static event Action QueueOverflow; // MPV_EVENT_QUEUE_OVERFLOW
public static event Action Hook; // MPV_EVENT_HOOK
public static IntPtr MpvHandle; public static IntPtr MpvHandle;
public static IntPtr MpvWindowHandle; public static IntPtr MpvWindowHandle;
@@ -104,24 +112,19 @@ namespace mpvnet
public static void LoadScripts() public static void LoadScripts()
{ {
string[] extensions = { ".lua", ".js" }; string[] jsLua = { ".lua", ".js" };
string[] scripts = Directory.GetFiles(Application.StartupPath + "\\Scripts"); string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
foreach (var scriptPath in scripts) foreach (var scriptPath in startupScripts)
{ if (jsLua.Contains(Path.GetExtension(scriptPath).ToLower()))
string ext = Path.GetExtension(scriptPath); mp.Command("load-script", $"{scriptPath}");
if (extensions.Contains(ext.ToLower())) foreach (var scriptPath in startupScripts)
mpv.Command("load-script", $"{scriptPath}"); if (Path.GetExtension(scriptPath) == ".py")
}
foreach (var scriptPath in scripts)
{
string ext = Path.GetExtension(scriptPath);
if (ext == ".py")
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath))); PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
}
foreach(var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "scripts", "*.py"))
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
} }
public static void EventLoop() public static void EventLoop()
@@ -240,10 +243,83 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW: case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW:
QueueOverflow?.Invoke(); QueueOverflow?.Invoke();
break; break;
case mpv_event_id.MPV_EVENT_HOOK:
Hook?.Invoke();
break;
} }
} }
} }
public class EventObject
{
public PyRT.PythonFunction PythonFunction { get; set; }
public EventInfo EventInfo { get; set; }
public Delegate Delegate { get; set; }
public void Invoke()
{
PyRT.Operations.PythonCalls.Call(PythonFunction);
}
public void InvokeEndFileEventMode(EndFileEventMode arg)
{
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
}
public void InvokeStrings(string[] arg)
{
PyRT.Operations.PythonCalls.Call(PythonFunction, new[] { arg });
}
}
private static List<EventObject> EventObjects = new List<EventObject>();
public static void register_event(string name, PyRT.PythonFunction pyFunc)
{
foreach (var eventInfo in typeof(mp).GetEvents())
{
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
{
EventObject eventObject = new EventObject();
EventObjects.Add(eventObject);
eventObject.PythonFunction = pyFunc;
MethodInfo mi;
if (eventInfo.EventHandlerType == typeof(Action))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.Invoke));
}
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeEndFileEventMode));
}
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
{
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeStrings));
}
else
throw new Exception();
eventObject.EventInfo = eventInfo;
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
eventObject.Delegate = handler;
eventInfo.AddEventHandler(eventObject, handler);
}
}
}
public static void unregister_event(PyRT.PythonFunction pyFunc)
{
foreach (var eventObjects in EventObjects)
if (eventObjects.PythonFunction == pyFunc)
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
}
public static void commandv(params string[] args)
{
Command(args);
}
public static void Command(params string[] args) public static void Command(params string[] args)
{ {
if (MpvHandle == IntPtr.Zero) if (MpvHandle == IntPtr.Zero)
@@ -307,6 +383,22 @@ namespace mpvnet
return lpBuffer.ToInt32(); return lpBuffer.ToInt32();
} }
public static double get_property_number(string name)
{
return GetDoubleProp(name);
}
public static double GetDoubleProp(string name, bool throwException = true)
{
double val = 0;
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_DOUBLE, ref val);
if (err < 0 && throwException)
throw new Exception($"{name}: {(mpv_error)err}");
else
return val;
}
public static void SetIntProp(string name, int value) public static void SetIntProp(string name, int value)
{ {
Int64 val = value; Int64 val = value;
@@ -344,9 +436,9 @@ namespace mpvnet
foreach (string i in args) foreach (string i in args)
if (!i.StartsWith("--") && File.Exists(i)) if (!i.StartsWith("--") && File.Exists(i))
mpv.Command("loadfile", i, "append"); mp.Command("loadfile", i, "append");
mpv.SetStringProp("playlist-pos", "0", false); mp.SetStringProp("playlist-pos", "0", false);
foreach (string i in args) foreach (string i in args)
{ {
@@ -356,27 +448,27 @@ namespace mpvnet
{ {
string left = i.Substring(2, i.IndexOf("=") - 2); string left = i.Substring(2, i.IndexOf("=") - 2);
string right = i.Substring(left.Length + 3); string right = i.Substring(left.Length + 3);
mpv.SetStringProp(left, right); mp.SetStringProp(left, right);
} }
else else
mpv.SetStringProp(i.Substring(2), "yes"); mp.SetStringProp(i.Substring(2), "yes");
} }
} }
} }
public static void LoadFiles(string[] files) public static void LoadFiles(string[] files)
{ {
int count = mpv.GetIntProp("playlist-count"); int count = mp.GetIntProp("playlist-count");
foreach (string file in files) foreach (string file in files)
mpv.Command("loadfile", file, "append"); mp.Command("loadfile", file, "append");
mpv.SetIntProp("playlist-pos", count); mp.SetIntProp("playlist-pos", count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
mpv.Command("playlist-remove", "0"); mp.Command("playlist-remove", "0");
mpv.LoadFolder(); mp.LoadFolder();
} }
private static bool WasFolderLoaded; private static bool WasFolderLoaded;

View File

@@ -132,6 +132,7 @@
<Compile Include="Menu.cs"> <Compile Include="Menu.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="PyScript.cs" />
<Compile Include="StringExtensions.cs" /> <Compile Include="StringExtensions.cs" />
<Compile Include="libmpv.cs" /> <Compile Include="libmpv.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
@@ -141,7 +142,7 @@
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Misc.cs" /> <Compile Include="Misc.cs" />
<Compile Include="mpv.cs" /> <Compile Include="mp.cs" />
<Compile Include="Command.cs" /> <Compile Include="Command.cs" />
<Compile Include="Native.cs" /> <Compile Include="Native.cs" />
<Compile Include="NativeHelp.cs" /> <Compile Include="NativeHelp.cs" />

View File

@@ -9,4 +9,4 @@ $addonDir = $targetDir + "\Addons"
Remove-Item $addonDir -Recurse -Include *mpvnet.exe, *mpvnet.exe.config, *mpvnet.pdb Remove-Item $addonDir -Recurse -Include *mpvnet.exe, *mpvnet.exe.config, *mpvnet.pdb
$7zPath = "C:\Program Files\7-Zip\7z.exe" $7zPath = "C:\Program Files\7-Zip\7z.exe"
$args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*" $args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*"
Start-Process -FilePath $7zPath -ArgumentList $args #Start-Process -FilePath $7zPath -ArgumentList $args