diff --git a/CSScriptAddon/CSScriptAddon.vb b/CSScriptAddon/CSScriptAddon.vb index e6e2049..6747682 100644 --- a/CSScriptAddon/CSScriptAddon.vb +++ b/CSScriptAddon/CSScriptAddon.vb @@ -11,7 +11,7 @@ Public Class CSScriptAddon Implements IAddon Sub New() - Dim scriptDir = mp.mpvConfFolderPath + "scripts" + Dim scriptDir = mp.MpvConfFolderPath + "scripts" If Not Directory.Exists(scriptDir) Then Return Dim csFiles = Directory.GetFiles(scriptDir, "*.cs").ToList csFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\Scripts", "*.cs")) diff --git a/README.md b/README.md index e45127d..631b2a3 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Table of contents - Searchable options dialog with modern UI as mpv compatible standalone application - Searchable input (key/mouse) binding editor with modern UI as mpv compatible standalone application - Modern UI using the OS theme color and dark mode -- Rich addon API for .NET languages, over 700 available mpv properties +- Rich addon/extension API for .NET languages, over 700 available mpv properties - Rich scripting API for Python, C#, Lua, JavaScript and PowerShell - mpv's OSC (on screen controller (play control bar)), IPC, conf files @@ -73,6 +73,14 @@ https://github.com/stax76/mpv.net/wiki/Scripting-(CSharp,-Python,-JavaScript,-Lu ### Changelog +### 3.0 (20??-??-??) + +- the history feature logs only files that were opened longer than 90 seconds +- the default input command for cycling the audio tracks was replaced with an + mpv.net command that shows detailed track info and has no 'no audio' track + +[go to download page](https://github.com/stax76/mpv.net/releases) + ### 2.9 (2019-04-16) - clicking the right top corner in full screen mode @@ -96,6 +104,4 @@ https://github.com/stax76/mpv.net/wiki/Scripting-(CSharp,-Python,-JavaScript,-Lu - the context menu has a new track menu where the active track can be seen and selected, it shows video, audio and subtitle tracks with various metadata. [Menu default definition](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt#L104). - The screenshots were updated showing the [new track menu](https://github.com/stax76/mpv.net#screenshots). - -[go to download page](https://github.com/stax76/mpv.net/releases) \ No newline at end of file + The screenshots were updated showing the [new track menu](https://github.com/stax76/mpv.net#screenshots). \ No newline at end of file diff --git a/RatingAddon/RatingAddon.cs b/RatingAddon/RatingAddon.cs index b5e3b75..0d2aca8 100644 --- a/RatingAddon/RatingAddon.cs +++ b/RatingAddon/RatingAddon.cs @@ -10,7 +10,7 @@ namespace RatingAddon [Export(typeof(IAddon))] public class RatingAddon : IAddon { - private Dictionary Dic = new Dictionary(); + Dictionary Dic = new Dictionary(); public RatingAddon() { @@ -18,7 +18,7 @@ namespace RatingAddon mp.Shutdown += mpv_Shutdown; } - private void mpv_Shutdown() + void mpv_Shutdown() { foreach (var i in Dic) { @@ -44,7 +44,7 @@ namespace RatingAddon } } - private void mpv_ClientMessage(string[] args) + void mpv_ClientMessage(string[] args) { int rating; diff --git a/VBNET/TaskDialog.vb b/VBNET/TaskDialog.vb index 4bd3597..e2d6b18 100644 --- a/VBNET/TaskDialog.vb +++ b/VBNET/TaskDialog.vb @@ -58,7 +58,7 @@ Public Class Msg End Try End Sub - Private Shared ShownMessages As String + Shared ShownMessages As String Public Shared Sub ShowWarning(mainInstruction As String, Optional content As String = Nothing, @@ -421,11 +421,11 @@ Public Class TaskDialog(Of T) Private ExitTickCount As Integer - Private Function DialogProc(hwnd As IntPtr, - msg As UInteger, - wParam As IntPtr, - lParam As IntPtr, - lpRefData As IntPtr) As Integer + Function DialogProc(hwnd As IntPtr, + msg As UInteger, + wParam As IntPtr, + lParam As IntPtr, + lpRefData As IntPtr) As Integer Select Case msg Case TDN_BUTTON_CLICKED, TDN_RADIO_BUTTON_CLICKED If TypeOf SelectedValue Is MsgResult Then @@ -464,7 +464,7 @@ Public Class TaskDialog(Of T) End Select End Function - Private Sub MarshalDialogControlStructs() + Sub MarshalDialogControlStructs() If Not Buttons Is Nothing AndAlso Buttons.Count > 0 Then ButtonArray = AllocateAndMarshalButtons(Buttons) Config.pButtons = ButtonArray @@ -478,7 +478,7 @@ Public Class TaskDialog(Of T) End If End Sub - Private Shared Function AllocateAndMarshalButtons(structs As List(Of TASKDIALOG_BUTTON)) As IntPtr + Shared Function AllocateAndMarshalButtons(structs As List(Of TASKDIALOG_BUTTON)) As IntPtr Dim initialPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(TASKDIALOG_BUTTON)) * structs.Count) Dim currentPtr = initialPtr diff --git a/mpv.net/Addon.cs b/mpv.net/Addon.cs index b812e69..e486cba 100644 --- a/mpv.net/Addon.cs +++ b/mpv.net/Addon.cs @@ -14,7 +14,7 @@ namespace mpvnet [ImportMany] public IEnumerable Addons = null; - private readonly CompositionContainer CompositionContainer; + readonly CompositionContainer CompositionContainer; public Addon() { @@ -28,7 +28,7 @@ namespace mpvnet foreach (string i in Directory.GetDirectories(dir)) catalog.Catalogs.Add(new DirectoryCatalog(i, "*Addon.dll")); - dir = mp.mpvConfFolderPath + "\\Addons"; + dir = mp.MpvConfFolderPath + "\\Addons"; if (Directory.Exists(dir)) foreach (string i in Directory.GetDirectories(dir)) diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index 5d0089b..e2b5082 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; -using System.Threading.Tasks; using System.Windows.Forms; using VBNET; @@ -15,7 +15,7 @@ namespace mpvnet public string Name { get; set; } public Action Action { get; set; } - private static List commands; + static List commands; public static List Commands { @@ -58,7 +58,7 @@ namespace mpvnet public static void open_conf_folder(string[] args) { - Process.Start(mp.mpvConfFolderPath); + Process.Start(mp.MpvConfFolderPath); } public static void show_input_editor(string[] args) @@ -73,7 +73,7 @@ namespace mpvnet public static void show_history(string[] args) { - var fp = mp.mpvConfFolderPath + "history.txt"; + var fp = mp.MpvConfFolderPath + "history.txt"; if (File.Exists(fp)) Process.Start(fp); @@ -197,5 +197,22 @@ namespace mpvnet } })); } + + public static void cycle_audio(string[] args) + { + string filePath = mp.get_property_string("path", false); + if (!File.Exists(filePath)) return; + + using (MediaInfo mi = new MediaInfo(filePath)) + { + MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray(); + if (audTracks.Length < 2) return; + int aid = mp.get_property_int("aid"); + aid += 1; + if (aid > audTracks.Length) aid = 1; + mp.commandv("set", "aid", aid.ToString()); + mp.commandv("show-text", audTracks[aid - 1].Text.Substring(3), "5000"); + } + } } } \ No newline at end of file diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs index 9b0c6aa..a8cbe97 100644 --- a/mpv.net/MainForm.cs +++ b/mpv.net/MainForm.cs @@ -16,22 +16,21 @@ namespace mpvnet public partial class MainForm : Form { public static MainForm Instance { get; set; } - public static IntPtr Hwnd; + public static IntPtr Hwnd { get; set; } - private Point LastCursorPosChanged; - private int LastCursorChangedTickCount; - private bool IgnoreDpiChanged = true; - private MenuItemEx TracksMenu; - private List MediaTracks = new List(); public new ContextMenuStripEx ContextMenu; + MenuItemEx TracksMenu; - private float MpvAutofit = 0.50f; - private bool MpvFullscreen; - private int MpvScreen = -1; - private string MpvNetDarkMode = "system"; - private string MpvSid = ""; - private string MpvAid = ""; - private string MpvVid = ""; + Point LastCursorPosChanged; + int LastCursorChangedTickCount; + bool IgnoreDpiChanged = true; + float MpvAutofit = 0.50f; + bool MpvFullscreen; + int MpvScreen = -1; + string MpvNetDarkMode = "system"; + string MpvSid = ""; + string MpvAid = ""; + string MpvVid = ""; public MainForm() { @@ -67,15 +66,15 @@ namespace mpvnet } } - private void ContextMenu_Opening(object sender, CancelEventArgs e) + void ContextMenu_Opening(object sender, CancelEventArgs e) { - lock (MediaTracks) + lock (mp.MediaTracks) { TracksMenu.DropDownItems.Clear(); - MediaTrack[] audTracks = MediaTracks.Where(track => track.Type == "a").ToArray(); - MediaTrack[] subTracks = MediaTracks.Where(track => track.Type == "s").ToArray(); - MediaTrack[] vidTracks = MediaTracks.Where(track => track.Type == "v").ToArray(); + MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray(); + MediaTrack[] subTracks = mp.MediaTracks.Where(track => track.Type == "s").ToArray(); + MediaTrack[] vidTracks = mp.MediaTracks.Where(track => track.Type == "v").ToArray(); foreach (MediaTrack track in vidTracks) { @@ -284,127 +283,30 @@ namespace mpvnet } } - private void ContextMenu_Opened(object sender, EventArgs e) => CursorHelp.Show(); + void ContextMenu_Opened(object sender, EventArgs e) => CursorHelp.Show(); - private string LastHistory; + void mp_PlaybackRestart() => BeginInvoke(new Action(() => { Text = Path.GetFileName(mp.get_property_string("path")) + " - mpv.net " + Application.ProductVersion; })); - private void mp_PlaybackRestart() - { - string filePath = mp.get_property_string("path"); - BeginInvoke(new Action(() => { Text = Path.GetFileName(filePath) + " - mpv.net " + Application.ProductVersion; })); + void Mp_Idle() => BeginInvoke(new Action(() => { Text = "mpv.net " + Application.ProductVersion; })); - Task.Run(new Action(() => { - string historyFilepath = mp.mpvConfFolderPath + "history.txt"; + void CM_Popup(object sender, EventArgs e) => CursorHelp.Show(); - if (LastHistory != filePath && File.Exists(historyFilepath)) - { - File.AppendAllText(historyFilepath, DateTime.Now.ToString() + " " + - Path.GetFileNameWithoutExtension(filePath) + "\r\n"); - LastHistory = filePath; - } - - lock (MediaTracks) - { - MediaTracks.Clear(); - - using (MediaInfo mi = new MediaInfo(filePath)) - { - int count = mi.GetCount(MediaInfoStreamKind.Video); - - for (int i = 0; i < count; i++) - { - MediaTrack track = new MediaTrack(); - Add(track, mi.GetVideo(i, "Format")); - Add(track, mi.GetVideo(i, "Format_Profile")); - Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height")); - Add(track, mi.GetVideo(i, "FrameRate") + " FPS"); - Add(track, mi.GetVideo(i, "Language/String")); - Add(track, mi.GetVideo(i, "Forced") == "Yes" ? "Forced" : ""); - Add(track, mi.GetVideo(i, "Default") == "Yes" ? "Default" : ""); - Add(track, mi.GetVideo(i, "Title")); - track.Text = "V: " + track.Text.Trim(" ,".ToCharArray()); - track.Type = "v"; - track.ID = i + 1; - MediaTracks.Add(track); - } - - count = mi.GetCount(MediaInfoStreamKind.Audio); - - for (int i = 0; i < count; i++) - { - MediaTrack track = new MediaTrack(); - Add(track, mi.GetAudio(i, "Language/String")); - Add(track, mi.GetAudio(i, "Format")); - Add(track, mi.GetAudio(i, "Format_Profile")); - Add(track, mi.GetAudio(i, "BitRate/String")); - Add(track, mi.GetAudio(i, "Channel(s)/String")); - Add(track, mi.GetAudio(i, "SamplingRate/String")); - Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : ""); - Add(track, mi.GetAudio(i, "Default") == "Yes" ? "Default" : ""); - Add(track, mi.GetAudio(i, "Title")); - track.Text = "A: " + track.Text.Trim(" ,".ToCharArray()); - track.Type = "a"; - track.ID = i + 1; - MediaTracks.Add(track); - } - - count = mi.GetCount(MediaInfoStreamKind.Text); - - for (int i = 0; i < count; i++) - { - MediaTrack track = new MediaTrack(); - Add(track, mi.GetText(i, "Language/String")); - Add(track, mi.GetText(i, "Format")); - Add(track, mi.GetText(i, "Format_Profile")); - Add(track, mi.GetText(i, "Forced") == "Yes" ? "Forced" : ""); - Add(track, mi.GetText(i, "Default") == "Yes" ? "Default" : ""); - Add(track, mi.GetText(i, "Title")); - track.Text = "S: " + track.Text.Trim(" ,".ToCharArray()); - track.Type = "s"; - track.ID = i + 1; - MediaTracks.Add(track); - } - - void Add(MediaTrack track, string val) - { - if (!string.IsNullOrEmpty(val) && !(track.Text != null && track.Text.Contains(val))) - track.Text += " " + val + ","; - } - } - } - })); - } - - class MediaTrack - { - public string Text { get; set; } - public string Type { get; set; } - public int ID { get; set; } - } - - private void Mp_Idle() - { - BeginInvoke(new Action(() => { Text = "mpv.net " + Application.ProductVersion; })); - } - - private void CM_Popup(object sender, EventArgs e) => CursorHelp.Show(); - - private void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { Msg.ShowException(e.Exception); } - private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Msg.ShowError(e.ExceptionObject.ToString()); } - private void mp_VideoSizeChanged() + void mp_VideoSizeChanged() { BeginInvoke(new Action(() => SetFormPositionAndSizeKeepHeight())); } - private void mp_Shutdown() + void mp_Shutdown() { BeginInvoke(new Action(() => Close())); } @@ -531,12 +433,9 @@ namespace mpvnet CursorHelp.Show(); } - bool IsMouseInOSC() - { - return PointToClient(Control.MousePosition).Y > ClientSize.Height * 0.9; - } + bool IsMouseInOSC() => PointToClient(Control.MousePosition).Y > ClientSize.Height * 0.9; - private void Timer_Tick(object sender, EventArgs e) + void Timer_Tick(object sender, EventArgs e) { if (CursorHelp.IsPosDifferent(LastCursorPosChanged)) { @@ -600,7 +499,7 @@ namespace mpvnet { base.OnFormClosed(e); mp.commandv("quit"); - mp.AutoResetEvent.WaitOne(3000); + mp.AutoResetEvent.WaitOne(3000); } protected override void OnLostFocus(EventArgs e) @@ -615,14 +514,14 @@ namespace mpvnet CheckYouTube(); } - private string LastURL; - void CheckYouTube() { string clipboard = Clipboard.GetText(); - if (clipboard.StartsWith("https://www.youtube.com/watch?") && LastURL != clipboard && Visible) + + if (clipboard.StartsWith("https://www.youtube.com/watch?") && RegistryHelp.GetValue("HKCU\\Software\\" + Application.ProductName, "LastYouTubeURL") != clipboard && Visible) { - LastURL = clipboard; + RegistryHelp.SetValue("HKCU\\Software\\" + Application.ProductName, "LastYouTubeURL", clipboard); + if (Msg.ShowQuestion("Play YouTube URL?") == MsgResult.OK) mp.LoadURL(clipboard); } diff --git a/mpv.net/MediaInfo.cs b/mpv.net/MediaInfo.cs index bc34f43..1852f92 100644 --- a/mpv.net/MediaInfo.cs +++ b/mpv.net/MediaInfo.cs @@ -3,8 +3,8 @@ using System.Runtime.InteropServices; public class MediaInfo : IDisposable { - private IntPtr Handle; - private static bool Loaded; + IntPtr Handle; + static bool Loaded; public MediaInfo(string sourcepath) { @@ -42,7 +42,7 @@ public class MediaInfo : IDisposable return Marshal.PtrToStringUni(MediaInfo_Get(Handle, MediaInfoStreamKind.Text, streamNumber, parameter, MediaInfoInfoKind.Text, MediaInfoInfoKind.Name)); } - private bool Disposed; + bool Disposed; public void Dispose() { @@ -57,32 +57,32 @@ public class MediaInfo : IDisposable ~MediaInfo() { Dispose(); } [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr LoadLibrary(string path); + static extern IntPtr LoadLibrary(string path); [DllImport("MediaInfo.dll")] - private static extern IntPtr MediaInfo_New(); + static extern IntPtr MediaInfo_New(); [DllImport("MediaInfo.dll")] - private static extern void MediaInfo_Delete(IntPtr handle); + static extern void MediaInfo_Delete(IntPtr handle); [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] - private static extern int MediaInfo_Open(IntPtr handle, string fileName); + static extern int MediaInfo_Open(IntPtr handle, string fileName); [DllImport("MediaInfo.dll")] - private static extern int MediaInfo_Close(IntPtr handle); + static extern int MediaInfo_Close(IntPtr handle); [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr MediaInfo_Get(IntPtr handle, - MediaInfoStreamKind streamKind, - int streamNumber, - string parameter, - MediaInfoInfoKind kindOfInfo, - MediaInfoInfoKind kindOfSearch); + static extern IntPtr MediaInfo_Get(IntPtr handle, + MediaInfoStreamKind streamKind, + int streamNumber, + string parameter, + MediaInfoInfoKind kindOfInfo, + MediaInfoInfoKind kindOfSearch); [DllImport("MediaInfo.dll", CharSet = CharSet.Unicode)] - private static extern int MediaInfo_Count_Get(IntPtr handle, - MediaInfoStreamKind streamKind, - int streamNumber); + static extern int MediaInfo_Count_Get(IntPtr handle, + MediaInfoStreamKind streamKind, + int streamNumber); } public enum MediaInfoStreamKind diff --git a/mpv.net/Menu.cs b/mpv.net/Menu.cs index dbd1cd0..b41439e 100644 --- a/mpv.net/Menu.cs +++ b/mpv.net/Menu.cs @@ -149,7 +149,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer public static Color ColorToolStrip3 { get; set; } public static Color ColorToolStrip4 { get; set; } - private int TextOffset; + int TextOffset; public ToolStripRendererEx() { @@ -321,28 +321,28 @@ public struct HSLColor Luminosity = l; } - private double hue; + double _Hue; public int Hue { - get => System.Convert.ToInt32(hue * 240); - set => hue = CheckRange(value / 240.0); + get => System.Convert.ToInt32(_Hue * 240); + set => _Hue = CheckRange(value / 240.0); } - private double saturation; + double _Saturation; public int Saturation { - get => System.Convert.ToInt32(saturation * 240); - set => saturation = CheckRange(value / 240.0); + get => System.Convert.ToInt32(_Saturation * 240); + set => _Saturation = CheckRange(value / 240.0); } - private double luminosity; + double _Luminosity; public int Luminosity { - get => System.Convert.ToInt32(luminosity * 240); - set => luminosity = CheckRange(value / 240.0); + get => System.Convert.ToInt32(_Luminosity * 240); + set => _Luminosity = CheckRange(value / 240.0); } - private double CheckRange(double value) + double CheckRange(double value) { if (value < 0) value = 0; @@ -367,21 +367,21 @@ public struct HSLColor { double r = 0, g = 0, b = 0; - if (luminosity != 0) + if (_Luminosity != 0) { - if (saturation == 0) + if (_Saturation == 0) { - b = luminosity; - g = luminosity; - r = luminosity; + b = _Luminosity; + g = _Luminosity; + r = _Luminosity; } else { double temp2 = GetTemp2(this); - double temp1 = 2.0 * luminosity - temp2; - r = GetColorComponent(temp1, temp2, hue + 1.0 / 3.0); - g = GetColorComponent(temp1, temp2, hue); - b = GetColorComponent(temp1, temp2, hue - 1.0 / 3.0); + double temp1 = 2.0 * _Luminosity - temp2; + r = GetColorComponent(temp1, temp2, _Hue + 1.0 / 3.0); + g = GetColorComponent(temp1, temp2, _Hue); + b = GetColorComponent(temp1, temp2, _Hue - 1.0 / 3.0); } } @@ -391,7 +391,7 @@ public struct HSLColor System.Convert.ToInt32(255 * b)); } - private static double GetColorComponent(double temp1, double temp2, double temp3) + static double GetColorComponent(double temp1, double temp2, double temp3) { temp3 = MoveIntoRange(temp3); @@ -405,7 +405,7 @@ public struct HSLColor return temp1; } - private static double MoveIntoRange(double temp3) + static double MoveIntoRange(double temp3) { if (temp3 < 0) temp3 += 1; @@ -414,14 +414,14 @@ public struct HSLColor return temp3; } - private static double GetTemp2(HSLColor hslColor) + static double GetTemp2(HSLColor hslColor) { double temp2; - if (hslColor.luminosity < 0.5) - temp2 = hslColor.luminosity * (1.0 + hslColor.saturation); + if (hslColor._Luminosity < 0.5) + temp2 = hslColor._Luminosity * (1.0 + hslColor._Saturation); else - temp2 = hslColor.luminosity + hslColor.saturation - (hslColor.luminosity * hslColor.saturation); + temp2 = hslColor._Luminosity + hslColor._Saturation - (hslColor._Luminosity * hslColor._Saturation); return temp2; } @@ -429,17 +429,17 @@ public struct HSLColor public static HSLColor Convert(Color c) { HSLColor r = new HSLColor(); - r.hue = c.GetHue() / 360.0; - r.luminosity = c.GetBrightness(); - r.saturation = c.GetSaturation(); + r._Hue = c.GetHue() / 360.0; + r._Luminosity = c.GetBrightness(); + r._Saturation = c.GetSaturation(); return r; } public void SetRGB(int red, int green, int blue) { HSLColor hc = HSLColor.Convert(Color.FromArgb(red, green, blue)); - hue = hc.hue; - saturation = hc.saturation; - luminosity = hc.luminosity; + _Hue = hc._Hue; + _Saturation = hc._Saturation; + _Luminosity = hc._Luminosity; } } \ No newline at end of file diff --git a/mpv.net/Misc.cs b/mpv.net/Misc.cs index 4ba3065..e97aa80 100644 --- a/mpv.net/Misc.cs +++ b/mpv.net/Misc.cs @@ -99,6 +99,15 @@ namespace mpvnet rk.SetValue(name, value); } + public static string GetValue(string path, string name) + { + using (RegistryKey rk = GetRootKey(path).OpenSubKey(path.Substring(5))) + if (rk != null) + return rk.GetValue(name, "").ToString(); + else + return ""; + } + public static void RemoveKey(string path) { GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); @@ -122,4 +131,11 @@ namespace mpvnet } } } + + public class MediaTrack + { + public string Text { get; set; } + public string Type { get; set; } + public int ID { get; set; } + } } \ No newline at end of file diff --git a/mpv.net/Resources/input.conf.txt b/mpv.net/Resources/input.conf.txt index befe422..99f163b 100644 --- a/mpv.net/Resources/input.conf.txt +++ b/mpv.net/Resources/input.conf.txt @@ -84,7 +84,7 @@ d cycle deinterlace #menu: Video > Toggle Deinterlace a cycle-values video-aspect "16:9" "4:3" "2.35:1" "-1" #menu: Video > Cycle Aspect Ratio - KP7 cycle audio #menu: Audio > Cycle/Next + KP7 script-message mpv.net cycle-audio #menu: Audio > Cycle/Next _ ignore #menu: Audio > - KP6 add audio-delay 0.100 #menu: Audio > Delay +0.1 KP9 add audio-delay -0.100 #menu: Audio > Delay -0.1 @@ -116,12 +116,12 @@ _ ignore #menu: Speed > - BS set speed 1 #menu: Speed > Reset - KP0 script-message rate-file 0 #menu: Addons > Rating > 0stars - KP1 script-message rate-file 1 #menu: Addons > Rating > 1stars - KP2 script-message rate-file 2 #menu: Addons > Rating > 2stars - KP3 script-message rate-file 3 #menu: Addons > Rating > 3stars - KP4 script-message rate-file 4 #menu: Addons > Rating > 4stars - KP5 script-message rate-file 5 #menu: Addons > Rating > 5stars + KP0 script-message rate-file 0 #menu: Extensions > Rating > 0stars + KP1 script-message rate-file 1 #menu: Extensions > Rating > 1stars + KP2 script-message rate-file 2 #menu: Extensions > Rating > 2stars + KP3 script-message rate-file 3 #menu: Extensions > Rating > 3stars + KP4 script-message rate-file 4 #menu: Extensions > Rating > 4stars + KP5 script-message rate-file 5 #menu: Extensions > Rating > 5stars Ctrl+t set ontop yes #menu: View > On Top > Enable Ctrl+T set ontop no #menu: View > On Top > Disable diff --git a/mpv.net/mp.cs b/mpv.net/mp.cs index 8e23e6a..878d67b 100644 --- a/mpv.net/mp.cs +++ b/mpv.net/mp.cs @@ -53,20 +53,21 @@ namespace mpvnet public static event Action QueueOverflow; // MPV_EVENT_QUEUE_OVERFLOW public static event Action Hook; // MPV_EVENT_HOOK - public static IntPtr MpvHandle; - public static IntPtr MpvWindowHandle; - public static Addon Addon; - public static List>> BoolPropChangeActions = new List>>(); - public static List>> StringPropChangeActions = new List>>(); - public static Size VideoSize = new Size(1920, 1080); - 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 mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf"; - public static string mpvNetConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpvnet.conf"; - public static List PythonScripts => new List(); - public static AutoResetEvent AutoResetEvent = new AutoResetEvent(false); + public static IntPtr MpvHandle { get; set; } + public static IntPtr MpvWindowHandle { get; set; } + public static Addon Addon { get; set; } + public static List>> BoolPropChangeActions { get; set; } = new List>>(); + public static List>> StringPropChangeActions { get; set; } = new List>>(); + public static Size VideoSize { get; set; } = new Size(1920, 1080); + public static string MpvConfFolderPath { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\"; + public static string InputConfPath { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf"; + public static string MpvConfPath { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf"; + public static string MpvNetConfPath { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpvnet.conf"; + public static List PythonScripts { get; set; } = new List(); + public static AutoResetEvent AutoResetEvent { get; set; } = new AutoResetEvent(false); + public static List MediaTracks { get; set; } = new List(); - private static Dictionary _mpvConf; + static Dictionary _mpvConf; public static Dictionary mpvConf { get { @@ -74,8 +75,8 @@ namespace mpvnet { _mpvConf = new Dictionary(); - if (File.Exists(mpvConfPath)) - foreach (var i in File.ReadAllLines(mpvConfPath)) + if (File.Exists(MpvConfPath)) + foreach (var i in File.ReadAllLines(MpvConfPath)) if (i.Contains("=") && ! i.StartsWith("#")) _mpvConf[i.Substring(0, i.IndexOf("=")).Trim()] = i.Substring(i.IndexOf("=") + 1).Trim(); } @@ -83,7 +84,7 @@ namespace mpvnet } } - private static Dictionary _mpvNetConf; + static Dictionary _mpvNetConf; public static Dictionary mpvNetConf { get { @@ -91,8 +92,8 @@ namespace mpvnet { _mpvNetConf = new Dictionary(); - if (File.Exists(mpvNetConfPath)) - foreach (string i in File.ReadAllLines(mpvNetConfPath)) + if (File.Exists(MpvNetConfPath)) + foreach (string i in File.ReadAllLines(MpvNetConfPath)) if (i.Contains("=") && !i.StartsWith("#")) _mpvNetConf[i.Substring(0, i.IndexOf("=")).Trim()] = i.Substring(i.IndexOf("=") + 1).Trim(); } @@ -102,11 +103,11 @@ namespace mpvnet public static void Init() { - if (!Directory.Exists(mp.mpvConfFolderPath)) - Directory.CreateDirectory(mp.mpvConfFolderPath); + 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.MpvConfPath)) + File.WriteAllText(mp.MpvConfPath, Properties.Resources.mpv_conf); if (!File.Exists(mp.InputConfPath)) File.WriteAllText(mp.InputConfPath, Properties.Resources.input_conf); @@ -143,7 +144,7 @@ namespace mpvnet if (Path.GetExtension(scriptPath) == ".ps1") PowerShellScript.Init(scriptPath); - foreach (var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "Scripts")) + 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") @@ -168,6 +169,7 @@ namespace mpvnet { case mpv_event_id.MPV_EVENT_SHUTDOWN: Shutdown?.Invoke(); + WriteHistory(null); AutoResetEvent.Set(); return; case mpv_event_id.MPV_EVENT_LOG_MESSAGE: @@ -275,7 +277,12 @@ namespace mpvnet { VideoSize = s; VideoSizeChanged?.Invoke(); - } + } + + Task.Run(new Action(() => { + WriteHistory(mp.get_property_string("path")); + SetMediaTracks(); + })); break; case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE: ChapterChange?.Invoke(); @@ -295,7 +302,7 @@ namespace mpvnet } } - private static List PythonEventObjects = new List(); + static List PythonEventObjects = new List(); public static void register_event(string name, PyRT.PythonFunction pyFunc) { @@ -533,9 +540,9 @@ namespace mpvnet mp.LoadFolder(); } - private static bool WasFolderLoaded; + static bool WasFolderLoaded; - public static void LoadFolder() + static void LoadFolder() { if (WasFolderLoaded) return; @@ -561,7 +568,7 @@ namespace mpvnet WasFolderLoaded = true; } - public static IntPtr AllocateUtf8IntPtrArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers) + static IntPtr AllocateUtf8IntPtrArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers) { int numberOfStrings = arr.Length + 1; // add extra element for extra null pointer last (sentinel) byteArrayPointers = new IntPtr[numberOfStrings]; @@ -579,7 +586,7 @@ namespace mpvnet return rootPointer; } - public static string[] NativeUtf8StrArray2ManagedStrArray(IntPtr pUnmanagedStringArray, int StringCount) + static string[] NativeUtf8StrArray2ManagedStrArray(IntPtr pUnmanagedStringArray, int StringCount) { IntPtr[] pIntPtrArray = new IntPtr[StringCount]; string[] ManagedStringArray = new string[StringCount]; @@ -591,7 +598,7 @@ namespace mpvnet return ManagedStringArray; } - public static string StringFromNativeUtf8(IntPtr nativeUtf8) + static string StringFromNativeUtf8(IntPtr nativeUtf8) { int len = 0; while (Marshal.ReadByte(nativeUtf8, len) != 0) ++len; @@ -600,7 +607,100 @@ namespace mpvnet return Encoding.UTF8.GetString(buffer); } - public static byte[] GetUtf8Bytes(string s) => Encoding.UTF8.GetBytes(s + "\0"); + static byte[] GetUtf8Bytes(string s) => Encoding.UTF8.GetBytes(s + "\0"); + + static string LastHistoryPath; + static DateTime LastHistoryStartDateTime; + + static void WriteHistory(string filePath) + { + int totalMinutes = Convert.ToInt32((DateTime.Now - LastHistoryStartDateTime).TotalMinutes); + + if (File.Exists(LastHistoryPath) && totalMinutes > 1) + { + string historyFilepath = mp.MpvConfFolderPath + "history.txt"; + + File.AppendAllText(historyFilepath, DateTime.Now.ToString().Substring(0, 16) + + " " + totalMinutes.ToString().PadLeft(3) + " " + + Path.GetFileNameWithoutExtension(LastHistoryPath) + "\r\n"); + } + + LastHistoryPath = filePath; + LastHistoryStartDateTime = DateTime.Now; + } + + static void SetMediaTracks() + { + lock (MediaTracks) + { + MediaTracks.Clear(); + + using (MediaInfo mi = new MediaInfo(mp.get_property_string("path"))) + { + int count = mi.GetCount(MediaInfoStreamKind.Video); + + for (int i = 0; i < count; i++) + { + MediaTrack track = new MediaTrack(); + Add(track, mi.GetVideo(i, "Format")); + Add(track, mi.GetVideo(i, "Format_Profile")); + Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height")); + Add(track, mi.GetVideo(i, "FrameRate") + " FPS"); + Add(track, mi.GetVideo(i, "Language/String")); + Add(track, mi.GetVideo(i, "Forced") == "Yes" ? "Forced" : ""); + Add(track, mi.GetVideo(i, "Default") == "Yes" ? "Default" : ""); + Add(track, mi.GetVideo(i, "Title")); + track.Text = "V: " + track.Text.Trim(" ,".ToCharArray()); + track.Type = "v"; + track.ID = i + 1; + MediaTracks.Add(track); + } + + count = mi.GetCount(MediaInfoStreamKind.Audio); + + for (int i = 0; i < count; i++) + { + MediaTrack track = new MediaTrack(); + Add(track, mi.GetAudio(i, "Language/String")); + Add(track, mi.GetAudio(i, "Format")); + Add(track, mi.GetAudio(i, "Format_Profile")); + Add(track, mi.GetAudio(i, "BitRate/String")); + Add(track, mi.GetAudio(i, "Channel(s)/String")); + Add(track, mi.GetAudio(i, "SamplingRate/String")); + Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : ""); + Add(track, mi.GetAudio(i, "Default") == "Yes" ? "Default" : ""); + Add(track, mi.GetAudio(i, "Title")); + track.Text = "A: " + track.Text.Trim(" ,".ToCharArray()); + track.Type = "a"; + track.ID = i + 1; + MediaTracks.Add(track); + } + + count = mi.GetCount(MediaInfoStreamKind.Text); + + for (int i = 0; i < count; i++) + { + MediaTrack track = new MediaTrack(); + Add(track, mi.GetText(i, "Language/String")); + Add(track, mi.GetText(i, "Format")); + Add(track, mi.GetText(i, "Format_Profile")); + Add(track, mi.GetText(i, "Forced") == "Yes" ? "Forced" : ""); + Add(track, mi.GetText(i, "Default") == "Yes" ? "Default" : ""); + Add(track, mi.GetText(i, "Title")); + track.Text = "S: " + track.Text.Trim(" ,".ToCharArray()); + track.Type = "s"; + track.ID = i + 1; + MediaTracks.Add(track); + } + + void Add(MediaTrack track, string val) + { + if (!string.IsNullOrEmpty(val) && !(track.Text != null && track.Text.Contains(val))) + track.Text += " " + val + ","; + } + } + } + } } public enum EndFileEventMode