From b73d2e710723e0bbd2a8eb58f038e31925353beb Mon Sep 17 00:00:00 2001 From: stax76 Date: Sun, 7 Aug 2022 13:50:29 +0200 Subject: [PATCH] new history-filter option added --- docs/Changelog.md | 1 + docs/Manual.md | 4 ++ src/Misc/App.cs | 8 +++- src/Misc/Commands.cs | 4 +- src/Misc/Player.cs | 90 +++++++++++++---------------------- src/Resources/editor_conf.txt | 7 +++ src/WinForms/MainForm.cs | 2 +- 7 files changed, 55 insertions(+), 61 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index bf90ee6..2cf2a13 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -3,6 +3,7 @@ - Support multiple folders input (regression fix). - Relative file input paths are converted to absolute paths. +- New history-filter option added to define paths to be excluded from the history log feature. # 6.0.3.1 (2022-07-30) diff --git a/docs/Manual.md b/docs/Manual.md index d301af6..9615137 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -505,6 +505,10 @@ Amount of recent files to be remembered. Default: 15 Usage of the media info library instead of mpv to access media information. Default: yes (mpv.net specific option) +#### --history-filter + +Semicolon separated list of paths to be excluded from the history log feature. + #### --video-file-extensions=\ Video file extensions used to create file associations and used by the auto-load-folder feature. diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 6600b2e..8e6b07f 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -14,6 +14,8 @@ namespace mpvnet { public static List TempFiles { get; } = new List(); + public static string[] HistoryFilter { get; set; } + public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; } public static string ProcessInstance { get; set; } = "single"; public static string DarkMode { get; set; } = "always"; @@ -244,16 +246,17 @@ namespace mpvnet case "audio-file-extensions": CorePlayer.AudioTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; case "auto-play": AutoPlay = value == "yes"; return true; - case "autofit-image": AutofitImage = value.Trim('%').ToInt() / 100f; return true; case "autofit-audio": AutofitAudio = value.Trim('%').ToInt() / 100f; return true; + case "autofit-image": AutofitImage = value.Trim('%').ToInt() / 100f; return true; case "dark-mode": DarkMode = value; return true; case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "debug-mode": DebugMode = value == "yes"; return true; + case "history-filter": HistoryFilter = value.Split(';'); return true; case "image-file-extensions": CorePlayer.ImageTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true; case "media-info": MediaInfo = value == "yes"; return true; - case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true; case "minimum-aspect-ratio-audio": MinimumAspectRatioAudio = value.ToFloat(); return true; + case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true; case "process-instance": ProcessInstance = value; return true; case "queue": Queue = value == "yes"; return true; case "recent-count": RecentCount = value.ToInt(); return true; @@ -264,6 +267,7 @@ namespace mpvnet case "start-size": StartSize = value; return true; case "start-threshold": StartThreshold = value.ToInt(); return true; case "video-file-extensions": CorePlayer.VideoTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; + default: if (writeError) Terminal.WriteError($"unknown mpvnet.conf property: {name}"); diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 9d64b41..0cf0809 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -157,8 +157,8 @@ namespace mpvnet ProcessHelp.ShellExecute(Core.ConfigFolder + "history.txt"); else { - if (Msg.ShowQuestion("Create history.txt file in config folder?" + BR2 + - "mpv.net will write the date, time and filename of opened files to it.") == MessageBoxResult.OK) + if (Msg.ShowQuestion("Create a 'history.txt' file in the config folder?" + BR2 + + "mpv.net will write the date, time, play length and path of watched files to it.") == MessageBoxResult.OK) File.WriteAllText(Core.ConfigFolder + "history.txt", ""); } diff --git a/src/Misc/Player.cs b/src/Misc/Player.cs index 449891c..da559c2 100644 --- a/src/Misc/Player.cs +++ b/src/Misc/Player.cs @@ -72,6 +72,7 @@ namespace mpvnet public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); + public DateTime HistoryTime; public IntPtr Handle { get; set; } public IntPtr NamedHandle { get; set; } public List MediaTracks { get; set; } = new List(); @@ -176,7 +177,15 @@ namespace mpvnet SetPropertyString("idle", "yes"); ObservePropertyDouble("window-scale", value => WindowScaleMpv(value)); - ObservePropertyString("path", value => Path = value); + + ObservePropertyString("path", value => { + if (HistoryTime == DateTime.MinValue) + { + HistoryTime = DateTime.Now; + HistoryPath = value; + } + Path = value; + }); ObservePropertyBool("pause", value => { Paused = value; @@ -499,7 +508,7 @@ namespace mpvnet case mpv_event_id.MPV_EVENT_SHUTDOWN: IsQuitNeeded = false; Shutdown?.Invoke(); - WriteHistory(null); + WriteHistory(); ShutdownAutoResetEvent.Set(); return; case mpv_event_id.MPV_EVENT_LOG_MESSAGE: @@ -580,13 +589,7 @@ namespace mpvnet } App.RunTask(new Action(() => UpdateTracks())); - - App.RunTask(new Action(() => { - if (path.Contains("://")) - path = GetPropertyString("media-title"); - - WriteHistory(path); - })); + App.RunTask(new Action(() => WriteHistory())); InvokeEvent(FileLoaded, FileLoadedAsync); } @@ -942,29 +945,6 @@ namespace mpvnet return ""; } - public string GetScriptOption(string name, string defaultValue = "") - { - string value = GetPropertyString("script-opts"); - - if (string.IsNullOrEmpty(value)) - return defaultValue; - - string[] values = value.Split(','); - - foreach (string item in values) - { - if (item.Contains("=")) - { - string optionName = item.Substring(0, item.IndexOf("=")); - - if (optionName == name) - return item.Substring(item.IndexOf("=") + 1); - } - } - - return defaultValue; - } - public void ObservePropertyInt(string name, Action action) { lock (IntPropChangeActions) @@ -1369,38 +1349,36 @@ namespace mpvnet } } - string LastHistoryPath; - DateTime LastHistoryStartDateTime; + string HistoryPath; - void WriteHistory(string path) + void WriteHistory() { - if (!File.Exists(ConfigFolder + "history.txt")) - return; + double totalMinutes = (DateTime.Now - HistoryTime).TotalMinutes; - double totalMinutes = (DateTime.Now - LastHistoryStartDateTime).TotalMinutes; + if (!string.IsNullOrEmpty(HistoryPath) && totalMinutes > 1 && + !HistoryDiscard() && File.Exists(ConfigFolder + "history.txt")) + { + string path = HistoryPath; - if (LastHistoryPath != null && totalMinutes > 1 && !HistoryDiscard()) - File.AppendAllText(ConfigFolder + "history.txt", DateTime.Now.ToString().Substring(0, 16) + - " " + Convert.ToInt32(totalMinutes).ToString().PadLeft(3) + " " + LastHistoryPath + "\r\n"); + if (path.Contains("://")) + path = GetPropertyString("media-title"); - LastHistoryPath = path; - LastHistoryStartDateTime = DateTime.Now; + string txt = DateTime.Now.ToString().Substring(0, 16) + " " + + Convert.ToInt32(totalMinutes).ToString().PadLeft(3) + " " + path + "\r\n"; + + File.AppendAllText(ConfigFolder + "history.txt", txt); + } + + HistoryPath = Path; + HistoryTime = DateTime.Now; } - string HistoryDiscardOption; - - bool HistoryDiscard() + public bool HistoryDiscard() { - if (HistoryDiscardOption == null) - HistoryDiscardOption = GetScriptOption("history-discard"); - - if (string.IsNullOrEmpty(HistoryDiscardOption)) - return false; - - foreach (string i in HistoryDiscardOption.Split(';')) - if (LastHistoryPath.Contains(i)) - return true; - + if (App.HistoryFilter != null) + foreach (string filter in App.HistoryFilter) + if (HistoryPath.Contains(filter.Trim())) + return true; return false; } diff --git a/src/Resources/editor_conf.txt b/src/Resources/editor_conf.txt index a2fbed0..af52575 100644 --- a/src/Resources/editor_conf.txt +++ b/src/Resources/editor_conf.txt @@ -26,6 +26,13 @@ help = Usage of the media info library instead of mpv to access media informatio option = yes option = no +[setting] +name = history-filter +file = mpvnet +filter = General +width = 500 +help = Semicolon separated list of paths to be excluded from the history log feature. + [setting] name = video-file-extensions file = mpvnet diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index d9292f3..2a39b8d 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -779,7 +779,7 @@ namespace mpvnet string text = Core.Expand(title); - if (text == "(unavailable)") + if (text == "(unavailable)" || Core.PlaylistPos == -1) text = "mpv.net"; Text = text;