new history-filter option added

This commit is contained in:
stax76
2022-08-07 13:50:29 +02:00
parent a7fa76d63a
commit b73d2e7107
7 changed files with 55 additions and 61 deletions

View File

@@ -3,6 +3,7 @@
- Support multiple folders input (regression fix). - Support multiple folders input (regression fix).
- Relative file input paths are converted to absolute paths. - 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) # 6.0.3.1 (2022-07-30)

View File

@@ -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) 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=\<string\> #### --video-file-extensions=\<string\>
Video file extensions used to create file associations and used by the auto-load-folder feature. Video file extensions used to create file associations and used by the auto-load-folder feature.

View File

@@ -14,6 +14,8 @@ namespace mpvnet
{ {
public static List<string> TempFiles { get; } = new List<string>(); public static List<string> TempFiles { get; } = new List<string>();
public static string[] HistoryFilter { get; set; }
public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; } public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; }
public static string ProcessInstance { get; set; } = "single"; public static string ProcessInstance { get; set; } = "single";
public static string DarkMode { get; set; } = "always"; 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 "audio-file-extensions": CorePlayer.AudioTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; case "auto-load-folder": AutoLoadFolder = value == "yes"; return true;
case "auto-play": AutoPlay = 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-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-mode": DarkMode = value; return true;
case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true;
case "debug-mode": DebugMode = value == "yes"; 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 "image-file-extensions": CorePlayer.ImageTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
case "light-theme": LightTheme = value.Trim('\'', '"'); return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true;
case "media-info": MediaInfo = value == "yes"; 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-audio": MinimumAspectRatioAudio = value.ToFloat(); return true;
case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true;
case "process-instance": ProcessInstance = value; return true; case "process-instance": ProcessInstance = value; return true;
case "queue": Queue = value == "yes"; return true; case "queue": Queue = value == "yes"; return true;
case "recent-count": RecentCount = value.ToInt(); 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-size": StartSize = value; return true;
case "start-threshold": StartThreshold = value.ToInt(); return true; case "start-threshold": StartThreshold = value.ToInt(); return true;
case "video-file-extensions": CorePlayer.VideoTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "video-file-extensions": CorePlayer.VideoTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
default: default:
if (writeError) if (writeError)
Terminal.WriteError($"unknown mpvnet.conf property: {name}"); Terminal.WriteError($"unknown mpvnet.conf property: {name}");

View File

@@ -157,8 +157,8 @@ namespace mpvnet
ProcessHelp.ShellExecute(Core.ConfigFolder + "history.txt"); ProcessHelp.ShellExecute(Core.ConfigFolder + "history.txt");
else else
{ {
if (Msg.ShowQuestion("Create history.txt file in config folder?" + BR2 + if (Msg.ShowQuestion("Create a 'history.txt' file in the config folder?" + BR2 +
"mpv.net will write the date, time and filename of opened files to it.") == MessageBoxResult.OK) "mpv.net will write the date, time, play length and path of watched files to it.") == MessageBoxResult.OK)
File.WriteAllText(Core.ConfigFolder + "history.txt", ""); File.WriteAllText(Core.ConfigFolder + "history.txt", "");
} }

View File

@@ -72,6 +72,7 @@ namespace mpvnet
public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent ShutdownAutoResetEvent { get; } = new AutoResetEvent(false);
public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false); public AutoResetEvent VideoSizeAutoResetEvent { get; } = new AutoResetEvent(false);
public DateTime HistoryTime;
public IntPtr Handle { get; set; } public IntPtr Handle { get; set; }
public IntPtr NamedHandle { get; set; } public IntPtr NamedHandle { get; set; }
public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>(); public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
@@ -176,7 +177,15 @@ namespace mpvnet
SetPropertyString("idle", "yes"); SetPropertyString("idle", "yes");
ObservePropertyDouble("window-scale", value => WindowScaleMpv(value)); 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 => { ObservePropertyBool("pause", value => {
Paused = value; Paused = value;
@@ -499,7 +508,7 @@ namespace mpvnet
case mpv_event_id.MPV_EVENT_SHUTDOWN: case mpv_event_id.MPV_EVENT_SHUTDOWN:
IsQuitNeeded = false; IsQuitNeeded = false;
Shutdown?.Invoke(); Shutdown?.Invoke();
WriteHistory(null); WriteHistory();
ShutdownAutoResetEvent.Set(); ShutdownAutoResetEvent.Set();
return; return;
case mpv_event_id.MPV_EVENT_LOG_MESSAGE: case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
@@ -580,13 +589,7 @@ namespace mpvnet
} }
App.RunTask(new Action(() => UpdateTracks())); App.RunTask(new Action(() => UpdateTracks()));
App.RunTask(new Action(() => WriteHistory()));
App.RunTask(new Action(() => {
if (path.Contains("://"))
path = GetPropertyString("media-title");
WriteHistory(path);
}));
InvokeEvent(FileLoaded, FileLoadedAsync); InvokeEvent(FileLoaded, FileLoadedAsync);
} }
@@ -942,29 +945,6 @@ namespace mpvnet
return ""; 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<int> action) public void ObservePropertyInt(string name, Action<int> action)
{ {
lock (IntPropChangeActions) lock (IntPropChangeActions)
@@ -1369,38 +1349,36 @@ namespace mpvnet
} }
} }
string LastHistoryPath; string HistoryPath;
DateTime LastHistoryStartDateTime;
void WriteHistory(string path) void WriteHistory()
{ {
if (!File.Exists(ConfigFolder + "history.txt")) double totalMinutes = (DateTime.Now - HistoryTime).TotalMinutes;
return;
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()) if (path.Contains("://"))
File.AppendAllText(ConfigFolder + "history.txt", DateTime.Now.ToString().Substring(0, 16) + path = GetPropertyString("media-title");
" " + Convert.ToInt32(totalMinutes).ToString().PadLeft(3) + " " + LastHistoryPath + "\r\n");
LastHistoryPath = path; string txt = DateTime.Now.ToString().Substring(0, 16) + " " +
LastHistoryStartDateTime = DateTime.Now; Convert.ToInt32(totalMinutes).ToString().PadLeft(3) + " " + path + "\r\n";
File.AppendAllText(ConfigFolder + "history.txt", txt);
}
HistoryPath = Path;
HistoryTime = DateTime.Now;
} }
string HistoryDiscardOption; public bool HistoryDiscard()
bool HistoryDiscard()
{ {
if (HistoryDiscardOption == null) if (App.HistoryFilter != null)
HistoryDiscardOption = GetScriptOption("history-discard"); foreach (string filter in App.HistoryFilter)
if (HistoryPath.Contains(filter.Trim()))
if (string.IsNullOrEmpty(HistoryDiscardOption)) return true;
return false;
foreach (string i in HistoryDiscardOption.Split(';'))
if (LastHistoryPath.Contains(i))
return true;
return false; return false;
} }

View File

@@ -26,6 +26,13 @@ help = Usage of the media info library instead of mpv to access media informatio
option = yes option = yes
option = no 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] [setting]
name = video-file-extensions name = video-file-extensions
file = mpvnet file = mpvnet

View File

@@ -779,7 +779,7 @@ namespace mpvnet
string text = Core.Expand(title); string text = Core.Expand(title);
if (text == "(unavailable)") if (text == "(unavailable)" || Core.PlaylistPos == -1)
text = "mpv.net"; text = "mpv.net";
Text = text; Text = text;