Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9c2150c47 | ||
|
|
b77bbd5aec | ||
|
|
92b58873e2 | ||
|
|
c8214b2d94 | ||
|
|
f77defecfd | ||
|
|
6fec4bada7 | ||
|
|
c508761c36 |
45
README.md
45
README.md
@@ -10,7 +10,7 @@ mpv manual: https://mpv.io/manual/master/
|
|||||||
|
|
||||||
- Customizable context menu defined in the same file as the keybindings
|
- Customizable context menu defined in the same file as the keybindings
|
||||||
- Addon API for .NET languages
|
- Addon API for .NET languages
|
||||||
- Python scripting implemented with IronPython
|
- 5 different scripting languages are supported, Python scripting implemented with IronPython, C# implemented with CS-Script, Lua and JavaScript implemented in libmpv and PowerShell
|
||||||
- C# scripting implemented with CS-Script
|
- C# scripting implemented with CS-Script
|
||||||
- mpv's OSC, IPC, Lua/JS, conf files and more
|
- mpv's OSC, IPC, Lua/JS, conf files and more
|
||||||
|
|
||||||
@@ -28,7 +28,13 @@ https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input_conf.txt
|
|||||||
|
|
||||||
### C# Scripting
|
### C# Scripting
|
||||||
|
|
||||||
A simple C# script located at: C:\Users\Frank\AppData\Roaming\mpv\scripts\test.cs
|
A simple C# script located at:
|
||||||
|
|
||||||
|
C:\Users\Frank\AppData\Roaming\mpv\scripts\test.cs
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts\test.cs
|
||||||
|
|
||||||
```
|
```
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
@@ -51,7 +57,13 @@ class Script
|
|||||||
|
|
||||||
### Python Scripting
|
### Python Scripting
|
||||||
|
|
||||||
A simple Python script located at: C:\Users\user\AppData\Roaming\mpv\scripts
|
A simple Python script located at:
|
||||||
|
|
||||||
|
C:\Users\user\AppData\Roaming\mpv\scripts
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts
|
||||||
|
|
||||||
```
|
```
|
||||||
# when seeking displays position and
|
# when seeking displays position and
|
||||||
@@ -82,8 +94,35 @@ def add_zero(val):
|
|||||||
mp.register_event("seek", seek) # or use: mp.Seek += seek
|
mp.register_event("seek", seek) # or use: mp.Seek += seek
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### PowerShell Scripting
|
||||||
|
|
||||||
|
A simple PowerShell script located at:
|
||||||
|
|
||||||
|
C:\Users\user\AppData\Roaming\mpv\scripts
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
startup\scripts
|
||||||
|
|
||||||
|
Please note that PowerShell don't allow assigning to events and mpv.net uses as workaround the script filename.
|
||||||
|
|
||||||
|
```
|
||||||
|
$position = [mp]::get_property_number("time-pos");
|
||||||
|
[mp]::commandv("show-text", $position.ToString() + " seconds")
|
||||||
|
```
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
|
### 1.3
|
||||||
|
|
||||||
|
- besides Lua/JavaScript/C#/Python there is now PowerShell supported as fifth scripting language
|
||||||
|
|
||||||
|
- in case there isn't yet a mpv.conf file mpv.net creates the file with certain default settings that were previously set on every mpv.net start. This was changed to provide transparency on which settings mpv.net uses. These default settings can be seen here: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpv.conf.txt
|
||||||
|
|
||||||
|
### 1.2
|
||||||
|
|
||||||
|
- a thread synchonisation bug which caused the shutdown to be delayed or frozen was fixed, it also caused the Shutdown event not to fire which caused the rating plugin not to work
|
||||||
|
|
||||||
### 1.1
|
### 1.1
|
||||||
|
|
||||||
- added support for Python scripting via IronPython
|
- added support for Python scripting via IronPython
|
||||||
|
|||||||
@@ -31,10 +31,6 @@ namespace mpvnet
|
|||||||
Instance = this;
|
Instance = this;
|
||||||
Hwnd = Handle;
|
Hwnd = Handle;
|
||||||
ChangeFullscreen((mp.mpvConv.ContainsKey("fullscreen") && mp.mpvConv["fullscreen"] == "yes") || (mp.mpvConv.ContainsKey("fs") && mp.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.Opened += CMS_Opened;
|
|
||||||
ContextMenuStrip = CMS;
|
|
||||||
BuildMenu();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -44,14 +40,6 @@ namespace mpvnet
|
|||||||
|
|
||||||
public void BuildMenu()
|
public void BuildMenu()
|
||||||
{
|
{
|
||||||
if (!File.Exists(mp.InputConfPath))
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(mp.mpvConfFolderPath))
|
|
||||||
Directory.CreateDirectory(mp.mpvConfFolderPath);
|
|
||||||
|
|
||||||
File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
|
foreach (var i in File.ReadAllText(mp.InputConfPath).SplitLinesNoEmpty())
|
||||||
{
|
{
|
||||||
if (!i.Contains("#menu:"))
|
if (!i.Contains("#menu:"))
|
||||||
@@ -129,7 +117,7 @@ namespace mpvnet
|
|||||||
private void mp_Shutdown()
|
private void mp_Shutdown()
|
||||||
{
|
{
|
||||||
if (!IsClosed)
|
if (!IsClosed)
|
||||||
Invoke(new Action(() => Close()));
|
BeginInvoke(new Action(() => Close()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFullscreen
|
public bool IsFullscreen
|
||||||
@@ -293,6 +281,15 @@ namespace mpvnet
|
|||||||
mp.PlaybackRestart += mp_PlaybackRestart;
|
mp.PlaybackRestart += mp_PlaybackRestart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnShown(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnShown(e);
|
||||||
|
CMS = new ContextMenuStripEx(components);
|
||||||
|
CMS.Opened += CMS_Opened;
|
||||||
|
ContextMenuStrip = CMS;
|
||||||
|
BuildMenu();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnFormClosed(FormClosedEventArgs e)
|
protected override void OnFormClosed(FormClosedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnFormClosed(e);
|
base.OnFormClosed(e);
|
||||||
@@ -302,7 +299,7 @@ namespace mpvnet
|
|||||||
for (int i = 0; i < 99; i++)
|
for (int i = 0; i < 99; i++)
|
||||||
{
|
{
|
||||||
if (mp.IsShutdownComplete) break;
|
if (mp.IsShutdownComplete) break;
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
129
mpv.net/PowerShellScript.cs
Normal file
129
mpv.net/PowerShellScript.cs
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Management.Automation.Runspaces;
|
||||||
|
|
||||||
|
using static mpvnet.StaticUsing;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace mpvnet
|
||||||
|
{
|
||||||
|
public class PowerShellScript
|
||||||
|
{
|
||||||
|
public static object Execute(string code, string[] parameters)
|
||||||
|
{
|
||||||
|
using (Runspace runspace = RunspaceFactory.CreateRunspace())
|
||||||
|
{
|
||||||
|
runspace.ApartmentState = ApartmentState.STA;
|
||||||
|
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
|
||||||
|
runspace.Open();
|
||||||
|
|
||||||
|
using (Pipeline pipeline = runspace.CreatePipeline())
|
||||||
|
{
|
||||||
|
pipeline.Commands.AddScript(
|
||||||
|
@"Using namespace mpvnet;
|
||||||
|
Using namespace System;
|
||||||
|
[System.Reflection.Assembly]::LoadWithPartialName(""mpvnet"")");
|
||||||
|
|
||||||
|
pipeline.Commands.AddScript(code);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ret = pipeline.Invoke(parameters);
|
||||||
|
|
||||||
|
if (ret.Count > 0)
|
||||||
|
return ret[0];
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (Pipeline pipeline2 = runspace.CreatePipeline())
|
||||||
|
{
|
||||||
|
pipeline2.Commands.AddScript("$PSVersionTable.PSVersion.Major * 10 +" +
|
||||||
|
"$PSVersionTable.PSVersion.Minor");
|
||||||
|
|
||||||
|
if (Convert.ToInt32(pipeline2.Invoke()[0].ToString()) < 51)
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MsgError("PowerShell Setup Problem\r\n\r\nEnsure you have at least PowerShell 5.1 installed.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MsgError(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Init(string filePath)
|
||||||
|
{
|
||||||
|
foreach (var eventInfo in typeof(mp).GetEvents())
|
||||||
|
{
|
||||||
|
if (eventInfo.Name.ToLower() ==
|
||||||
|
Path.GetFileNameWithoutExtension(filePath).ToLower().Replace("-", ""))
|
||||||
|
{
|
||||||
|
PowerShellEventObject eventObject = new PowerShellEventObject();
|
||||||
|
MethodInfo mi;
|
||||||
|
eventObject.FilePath = filePath;
|
||||||
|
|
||||||
|
if (eventInfo.EventHandlerType == typeof(Action))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.Invoke));
|
||||||
|
}
|
||||||
|
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeEndFileEventMode));
|
||||||
|
}
|
||||||
|
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
||||||
|
{
|
||||||
|
mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeStrings));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception();
|
||||||
|
|
||||||
|
eventObject.EventInfo = eventInfo;
|
||||||
|
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
||||||
|
eventObject.Delegate = handler;
|
||||||
|
eventInfo.AddEventHandler(eventObject, handler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(filePath), new string[] {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PowerShellEventObject
|
||||||
|
{
|
||||||
|
public EventInfo EventInfo { get; set; }
|
||||||
|
public Delegate Delegate { get; set; }
|
||||||
|
public string FilePath { get; set; }
|
||||||
|
|
||||||
|
public void Invoke()
|
||||||
|
{
|
||||||
|
Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { }); });
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeEndFileEventMode(EndFileEventMode arg)
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { arg.ToString() });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InvokeStrings(string[] args)
|
||||||
|
{
|
||||||
|
Task.Run(() => {
|
||||||
|
PowerShellScript.Execute(File.ReadAllText(FilePath), args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.1.0.0")]
|
[assembly: AssemblyVersion("1.3.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
[assembly: AssemblyFileVersion("1.3.0.0")]
|
||||||
|
|||||||
28
mpv.net/Properties/Resources.Designer.cs
generated
28
mpv.net/Properties/Resources.Designer.cs
generated
@@ -19,7 +19,7 @@ namespace mpvnet.Properties {
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources {
|
||||||
@@ -61,11 +61,37 @@ namespace mpvnet.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to # mpv.net key bindings, mouse bindings and context menu configuration
|
||||||
|
///
|
||||||
|
/// o script-message mpv.net open-files #menu: O ; Open Files...
|
||||||
|
/// _ ignore #menu: _ ; -
|
||||||
|
/// Space cycle pause #menu: Space, Enter ; Play/Pause
|
||||||
|
/// Enter cycle pause
|
||||||
|
/// s stop #menu: S ; Stop
|
||||||
|
/// _ ignore #menu: _ ; -
|
||||||
|
/// f cycle fullscreen #menu: F ; Toggle Fullscreen
/// [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string input_conf {
|
internal static string input_conf {
|
||||||
get {
|
get {
|
||||||
return ResourceManager.GetString("input_conf", resourceCulture);
|
return ResourceManager.GetString("input_conf", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to input-ar-delay = 500
|
||||||
|
///input-ar-rate = 20
|
||||||
|
///volume = 50
|
||||||
|
///hwdec = yes
|
||||||
|
///vo = direct3d
|
||||||
|
///keep-open = yes
|
||||||
|
///keep-open-pause = no
|
||||||
|
///osd-playing-msg = '${filename}'
|
||||||
|
///screenshot-directory = ~~desktop/.
|
||||||
|
/// </summary>
|
||||||
|
internal static string mpv_conf {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("mpv_conf", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,9 @@
|
|||||||
</resheader>
|
</resheader>
|
||||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="input_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\input_conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
<value>..\Resources\input.conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||||
|
</data>
|
||||||
|
<data name="mpv_conf" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\mpv.conf.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -7,12 +7,12 @@ using static mpvnet.StaticUsing;
|
|||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
{
|
{
|
||||||
public class PyScript
|
public class PythonScript
|
||||||
{
|
{
|
||||||
ScriptEngine engine;
|
ScriptEngine engine;
|
||||||
ScriptScope scope;
|
ScriptScope scope;
|
||||||
|
|
||||||
public PyScript(string code)
|
public PythonScript(string code)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
w add panscan -0.1 #menu: W ; Pan && Scan > Decrease Height
|
w add panscan -0.1 #menu: W ; Pan && Scan > Decrease Height
|
||||||
W add panscan +0.1 #menu: Shift+W ; Pan && Scan > Increase Height
|
W add panscan +0.1 #menu: Shift+W ; Pan && Scan > Increase Height
|
||||||
_ ignore #menu: _ ; Pan && Scan > -
|
_ ignore #menu: _ ; Pan && Scan > -
|
||||||
Shift+BS set video-zoom 0 ; set video-pan-x 0 ; set video-pan-y 0 #menu: Alt+Backspace ; Pan && Scan > Reset
|
Shift+BS set video-zoom 0 ; set video-pan-x 0 ; set video-pan-y 0 #menu: Shift+Backspace ; Pan && Scan > Reset
|
||||||
|
|
||||||
Ctrl+1 add contrast -1 #menu: Ctrl+1 ; Video > Decrease Contrast
|
Ctrl+1 add contrast -1 #menu: Ctrl+1 ; Video > Decrease Contrast
|
||||||
Ctrl+2 add contrast 1 #menu: Ctrl+2 ; Video > Increase Contrast
|
Ctrl+2 add contrast 1 #menu: Ctrl+2 ; Video > Increase Contrast
|
||||||
@@ -74,7 +74,6 @@
|
|||||||
_ ignore #menu: _ ; Subtitle > -
|
_ ignore #menu: _ ; Subtitle > -
|
||||||
_ add sub-scale -0.1 #menu: _ ; Subtitle > Decrease Subtitle Font Size
|
_ add sub-scale -0.1 #menu: _ ; Subtitle > Decrease Subtitle Font Size
|
||||||
_ add sub-scale +0.1 #menu: _ ; Subtitle > Increase Subtitle Font Size
|
_ add sub-scale +0.1 #menu: _ ; Subtitle > Increase Subtitle Font Size
|
||||||
_ ignore #menu: _ ; Subtitle > -
|
|
||||||
|
|
||||||
+ add volume 10 #menu: + ; Volume > Up
|
+ add volume 10 #menu: + ; Volume > Up
|
||||||
- add volume -10 #menu: - ; Volume > Down
|
- add volume -10 #menu: - ; Volume > Down
|
||||||
11
mpv.net/Resources/mpv.conf.txt
Normal file
11
mpv.net/Resources/mpv.conf.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://mpv.io/manual/master/
|
||||||
|
|
||||||
|
input-ar-delay = 500
|
||||||
|
input-ar-rate = 20
|
||||||
|
volume = 50
|
||||||
|
hwdec = yes
|
||||||
|
vo = direct3d
|
||||||
|
keep-open = yes
|
||||||
|
keep-open-pause = no
|
||||||
|
osd-playing-msg = ${filename}
|
||||||
|
screenshot-directory = ~~desktop/
|
||||||
@@ -60,7 +60,7 @@ namespace mpvnet
|
|||||||
public static string mpvConfFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
public static string mpvConfFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\";
|
||||||
public static string InputConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf";
|
public static string InputConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf";
|
||||||
public static string mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf";
|
public static string mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf";
|
||||||
public static List<PyScript> PyScripts { get; } = new List<PyScript>();
|
public static List<PythonScript> PythonScripts { get; } = new List<PythonScript>();
|
||||||
public static bool IsShutdownComplete { get; set; }
|
public static bool IsShutdownComplete { get; set; }
|
||||||
|
|
||||||
private static Dictionary<string, string> _mpvConv;
|
private static Dictionary<string, string> _mpvConv;
|
||||||
@@ -88,18 +88,18 @@ namespace mpvnet
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
if (!Directory.Exists(mp.mpvConfFolderPath))
|
||||||
|
Directory.CreateDirectory(mp.mpvConfFolderPath);
|
||||||
|
|
||||||
|
if (!File.Exists(mp.mpvConfPath))
|
||||||
|
File.WriteAllText(mp.mpvConfPath, Properties.Resources.mpv_conf);
|
||||||
|
|
||||||
|
if (!File.Exists(mp.InputConfPath))
|
||||||
|
File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf);
|
||||||
|
|
||||||
LoadLibrary("mpv-1.dll");
|
LoadLibrary("mpv-1.dll");
|
||||||
MpvHandle = mpv_create();
|
MpvHandle = mpv_create();
|
||||||
SetIntProp("input-ar-delay", 500);
|
|
||||||
SetIntProp("input-ar-rate", 20);
|
|
||||||
SetIntProp("volume", 50);
|
|
||||||
SetStringProp("hwdec", "yes");
|
|
||||||
SetStringProp("vo", "direct3d");
|
|
||||||
SetStringProp("input-default-bindings", "yes");
|
SetStringProp("input-default-bindings", "yes");
|
||||||
SetStringProp("osd-playing-msg", "'${filename}'");
|
|
||||||
SetStringProp("screenshot-directory", "~~desktop/");
|
|
||||||
SetStringProp("keep-open", "yes");
|
|
||||||
SetStringProp("keep-open-pause", "no");
|
|
||||||
SetStringProp("osc", "yes");
|
SetStringProp("osc", "yes");
|
||||||
SetStringProp("config", "yes");
|
SetStringProp("config", "yes");
|
||||||
SetStringProp("wid", MainForm.Hwnd.ToString());
|
SetStringProp("wid", MainForm.Hwnd.ToString());
|
||||||
@@ -122,10 +122,19 @@ namespace mpvnet
|
|||||||
|
|
||||||
foreach (var scriptPath in startupScripts)
|
foreach (var scriptPath in startupScripts)
|
||||||
if (Path.GetExtension(scriptPath) == ".py")
|
if (Path.GetExtension(scriptPath) == ".py")
|
||||||
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
|
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||||
|
|
||||||
foreach(var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "scripts", "*.py"))
|
foreach (var scriptPath in startupScripts)
|
||||||
PyScripts.Add(new PyScript(File.ReadAllText(scriptPath)));
|
if (Path.GetExtension(scriptPath) == ".ps1")
|
||||||
|
PowerShellScript.Init(scriptPath);
|
||||||
|
|
||||||
|
foreach (var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "Scripts"))
|
||||||
|
{
|
||||||
|
if (Path.GetExtension(scriptPath) == ".py")
|
||||||
|
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||||
|
else if (Path.GetExtension(scriptPath) == ".ps1")
|
||||||
|
PowerShellScript.Init(scriptPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EventLoop()
|
public static void EventLoop()
|
||||||
@@ -251,7 +260,7 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EventObject
|
public class PythonEventObject
|
||||||
{
|
{
|
||||||
public PyRT.PythonFunction PythonFunction { get; set; }
|
public PyRT.PythonFunction PythonFunction { get; set; }
|
||||||
public EventInfo EventInfo { get; set; }
|
public EventInfo EventInfo { get; set; }
|
||||||
@@ -273,7 +282,7 @@ namespace mpvnet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<EventObject> EventObjects = new List<EventObject>();
|
private static List<PythonEventObject> PythonEventObjects = new List<PythonEventObject>();
|
||||||
|
|
||||||
public static void register_event(string name, PyRT.PythonFunction pyFunc)
|
public static void register_event(string name, PyRT.PythonFunction pyFunc)
|
||||||
{
|
{
|
||||||
@@ -281,22 +290,22 @@ namespace mpvnet
|
|||||||
{
|
{
|
||||||
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
|
if (eventInfo.Name.ToLower() == name.Replace("-", ""))
|
||||||
{
|
{
|
||||||
EventObject eventObject = new EventObject();
|
PythonEventObject eventObject = new PythonEventObject();
|
||||||
EventObjects.Add(eventObject);
|
PythonEventObjects.Add(eventObject);
|
||||||
eventObject.PythonFunction = pyFunc;
|
eventObject.PythonFunction = pyFunc;
|
||||||
MethodInfo mi;
|
MethodInfo mi;
|
||||||
|
|
||||||
if (eventInfo.EventHandlerType == typeof(Action))
|
if (eventInfo.EventHandlerType == typeof(Action))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.Invoke));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.Invoke));
|
||||||
}
|
}
|
||||||
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
else if (eventInfo.EventHandlerType == typeof(Action<EndFileEventMode>))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeEndFileEventMode));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeEndFileEventMode));
|
||||||
}
|
}
|
||||||
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
else if (eventInfo.EventHandlerType == typeof(Action<string[]>))
|
||||||
{
|
{
|
||||||
mi = eventObject.GetType().GetMethod(nameof(EventObject.InvokeStrings));
|
mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeStrings));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
@@ -305,13 +314,14 @@ namespace mpvnet
|
|||||||
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
|
||||||
eventObject.Delegate = handler;
|
eventObject.Delegate = handler;
|
||||||
eventInfo.AddEventHandler(eventObject, handler);
|
eventInfo.AddEventHandler(eventObject, handler);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregister_event(PyRT.PythonFunction pyFunc)
|
public static void unregister_event(PyRT.PythonFunction pyFunc)
|
||||||
{
|
{
|
||||||
foreach (var eventObjects in EventObjects)
|
foreach (var eventObjects in PythonEventObjects)
|
||||||
if (eventObjects.PythonFunction == pyFunc)
|
if (eventObjects.PythonFunction == pyFunc)
|
||||||
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
|
eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,9 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -132,7 +135,13 @@
|
|||||||
<Compile Include="Menu.cs">
|
<Compile Include="Menu.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="PyScript.cs" />
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="PowerShellScript.cs" />
|
||||||
|
<Compile Include="PythonScript.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">
|
||||||
@@ -155,15 +164,11 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
</Compile>
|
|
||||||
<None Include="app.manifest" />
|
<None Include="app.manifest" />
|
||||||
|
<None Include="packages.config" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
@@ -173,6 +178,7 @@
|
|||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Content Include="Resources\mpv.conf.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
@@ -180,7 +186,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="mpv.ico" />
|
<Content Include="mpv.ico" />
|
||||||
<Content Include="screenshot.jpg" />
|
<Content Include="screenshot.jpg" />
|
||||||
<None Include="Resources\input_conf.txt" />
|
<Content Include="Resources\input.conf.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
4
mpv.net/packages.config
Normal file
4
mpv.net/packages.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Microsoft.PowerShell.5.ReferenceAssemblies" version="1.1.0" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
@@ -4,7 +4,7 @@ $version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion
|
|||||||
$desktopDir = [Environment]::GetFolderPath("Desktop")
|
$desktopDir = [Environment]::GetFolderPath("Desktop")
|
||||||
$targetDir = $desktopDir + "\mpv.net-" + $version
|
$targetDir = $desktopDir + "\mpv.net-" + $version
|
||||||
Copy-Item $scriptDir\mpv.net\bin\Debug $targetDir -recurse
|
Copy-Item $scriptDir\mpv.net\bin\Debug $targetDir -recurse
|
||||||
$addonDir = $targetDir + "\Addons"
|
copy-item $scriptDir\README.md $targetDir\README.md
|
||||||
$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
|
||||||
Reference in New Issue
Block a user