From 59a556794fd77848e7cd441946ecbe2b52ab5c48 Mon Sep 17 00:00:00 2001 From: stax76 Date: Sat, 12 Oct 2024 21:50:46 +0200 Subject: [PATCH] support for autocreate-playlist, video-exts, audio-exts, image-exts --- docs/changelog.md | 5 ++ docs/manual.md | 12 ----- src/MpvNet.Windows/GuiCommand.cs | 10 ++-- src/MpvNet.Windows/Resources/editor_conf.txt | 41 +++++++++------- src/MpvNet/App.cs | 3 -- src/MpvNet/FileTypes.cs | 49 ++++++++++++++++---- src/MpvNet/MpvClient.cs | 9 ++++ 7 files changed, 85 insertions(+), 44 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index dd66b0e4..d264cf89 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,4 +1,9 @@ +# v7.1.1.3 Beta (????-??-??) + +- Support for autocreate-playlist, video-exts, audio-exts, image-exts. + Windows 7 support should still work, but needs auto-load-folder to be enabled. + # v7.1.1.2 Beta (2024-10-10) - Polish translation fixed. German, Turkish and Japanese translation updated. diff --git a/docs/manual.md b/docs/manual.md index fbbd6e30..c5a921b6 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -448,18 +448,6 @@ 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) -#### --video-file-extensions=\ - -Video file extensions used to create file associations and used by the auto-load-folder feature. - -#### --audio-file-extensions=\ - -Audio file extensions used to create file associations and used by the auto-load-folder feature. - -#### --image-file-extensions=\ - -Image file extensions used to create file associations and used by the auto-load-folder feature. - #### --debug-mode=\ Enable this only when a developer asks for it. Default: no diff --git a/src/MpvNet.Windows/GuiCommand.cs b/src/MpvNet.Windows/GuiCommand.cs index 7cbfb390..83b8956f 100644 --- a/src/MpvNet.Windows/GuiCommand.cs +++ b/src/MpvNet.Windows/GuiCommand.cs @@ -236,9 +236,9 @@ void RegisterFileAssociations(IList args) switch (perceivedType) { - case "video": extensions = FileTypes.Video; break; - case "audio": extensions = FileTypes.Audio; break; - case "image": extensions = FileTypes.Image; break; + case "video": extensions = FileTypes.GetVideoExts(); break; + case "audio": extensions = FileTypes.GetAudioExts(); break; + case "image": extensions = FileTypes.GetImgExts(); break; } try @@ -284,13 +284,13 @@ void ShowMediaInfo(IList args) if (File.Exists(path) && osd) { - if (FileTypes.Audio.Contains(path.Ext())) + if (FileTypes.IsAudio(path.Ext())) { text = Player.GetPropertyOsdString("filtered-metadata"); Player.CommandV("show-text", text, "5000"); return; } - else if (FileTypes.Image.Contains(path.Ext())) + else if (FileTypes.IsImage(path.Ext())) { fileSize = new FileInfo(path).Length; diff --git a/src/MpvNet.Windows/Resources/editor_conf.txt b/src/MpvNet.Windows/Resources/editor_conf.txt index 9032c572..f41485b4 100644 --- a/src/MpvNet.Windows/Resources/editor_conf.txt +++ b/src/MpvNet.Windows/Resources/editor_conf.txt @@ -21,23 +21,11 @@ default = yes option = yes option = no -name = video-file-extensions -file = mpvnet -directory = General -width = 500 -help = Video file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) - -name = audio-file-extensions -file = mpvnet -directory = General -width = 500 -help = Audio file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) - -name = image-file-extensions -file = mpvnet +name = image-exts +file = mpv directory = General width = 500 -help = Image file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option) +help = Image file extentions to try to match when using --cover-art-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. name = menu-syntax file = mpvnet @@ -790,6 +778,12 @@ file = mpv directory = Video/Screenshot help = <0-5> Set the filter applied prior to PNG compression. 0 is none, 1 is 'sub', 2 is 'up', 3 is 'average', 4 is 'Paeth', and 5 is 'mixed'. This affects the level of compression that can be achieved. For most images, 'mixed' achieves the best compression ratio, hence it is the default. +name = video-exts +file = mpv +directory = Video +width = 500 +help = Video file extentions to try to match when using --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. + name = volume file = mpv directory = Audio @@ -833,6 +827,12 @@ default = yes option = yes option = no +name = audio-exts +file = mpv +directory = Audio +width = 500 +help = Audio file extentions to try to match when using --audio-file-auto, --autocreate-playlist or --directory-filter-types. By mpv.net used to create file associations and used by the auto-load-folder feature. + name = slang file = mpv directory = Subtitle @@ -1097,10 +1097,19 @@ file = mpv directory = Playback help = Loops playback N times. A value of 1 plays it one time (default), 2 two times, etc. inf means forever. no is the same as 1 and disables looping. If several files are specified on command line, the entire playlist is looped. The force mode is like inf, but does not skip playlist entries which have been marked as failing. This means the player might waste CPU time trying to loop a file that doesn't exist. But it might be useful for playing webradios under very bad network conditions. +name = autocreate-playlist +file = mpv +directory = Playback +help = When opening a local file, act as if the parent directory is opened and create a playlist automatically.\n\nno: Load a single file (mpv default).\n\nFilter: Create a playlist from the parent directory with files matching --directory-filter-types. (mpv.net default)\n\nsame: Create a playlist from the parent directory with files matching the same category as the currently loaded file. One of the *-exts is selected based on the input file and only files with matching extensions are added to the playlist. If the input file itself is not matched to any extension list, the playlist is not autogenerated. +default = filter +option = no +option = filter +option = same + name = auto-load-folder file = mpvnet directory = Playback -help = For single files automatically load the entire directory into the playlist. (mpv.net option) +help = For single files automatically load the entire directory into the playlist. (deprecated mpv.net option, autocreate-playlist can be used instead) default = yes option = yes option = no diff --git a/src/MpvNet/App.cs b/src/MpvNet/App.cs index 86b3894e..eb627614 100644 --- a/src/MpvNet/App.cs +++ b/src/MpvNet/App.cs @@ -131,14 +131,12 @@ public bool ProcessProperty(string name, string value, bool writeError = false) { switch (name) { - case "audio-file-extensions": FileTypes.Audio = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; case "autofit-audio": AutofitAudio = value.Trim('%').ToInt(70) / 100f; return true; case "autofit-image": AutofitImage = value.Trim('%').ToInt(80) / 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 "image-file-extensions": FileTypes.Image = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; case "language": Language = value; return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true; case "media-info": MediaInfo = value == "yes"; return true; @@ -152,7 +150,6 @@ public bool ProcessProperty(string name, string value, bool writeError = false) case "remember-volume": RememberVolume = value == "yes"; return true; case "remember-window-position": RememberWindowPosition = value == "yes"; return true; case "start-size": StartSize = value; return true; - case "video-file-extensions": FileTypes.Video = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true; default: if (writeError) diff --git a/src/MpvNet/FileTypes.cs b/src/MpvNet/FileTypes.cs index 542ec873..0ee136b9 100644 --- a/src/MpvNet/FileTypes.cs +++ b/src/MpvNet/FileTypes.cs @@ -5,16 +5,49 @@ namespace MpvNet; public static class FileTypes { - public static string[] Video { get; set; } = "mkv mp4 avi mov flv mpg webm wmv ts vob 264 265 asf avc avs dav h264 h265 hevc m2t m2ts m2v m4v mpeg mpv mts vpy y4m".Split(' '); - public static string[] Audio { get; set; } = "mp3 flac m4a mka mp2 ogg opus aac ac3 dts dtshd dtshr dtsma eac3 mpa mpc thd w64 wav".Split(' '); - public static string[] Image { get; set; } = { "jpg", "bmp", "png", "gif", "webp" }; public static string[] Subtitle { get; } = { "srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks" }; - public static bool IsImage(string extension) => Image.Contains(extension); - public static bool IsAudio(string extension) => Audio.Contains(extension); + public static bool IsVideo(string[] exts, string ext) => exts?.Contains(ext) ?? false; + public static bool IsAudio(string[] exts, string ext) => exts?.Contains(ext) ?? false; + public static bool IsImage(string[] exts, string ext) => exts?.Contains(ext) ?? false; - public static bool IsMedia(string extension) => - Video.Contains(extension) || Audio.Contains(extension) || Image.Contains(extension); + public static bool IsVideo(string ext) => GetVideoExts().Contains(ext); + public static bool IsAudio(string ext) => GetAudioExts().Contains(ext); + public static bool IsImage(string ext) => GetImgExts().Contains(ext); - public static IEnumerable GetMediaFiles(IEnumerable files) => files.Where(i => IsMedia(i.Ext())); + public static string[] GetVideoExts() + { + string exts = Player.GetPropertyString("video-exts"); + + if (string.IsNullOrEmpty(exts)) + return "mkv mp4 avi mov flv mpg webm wmv ts vob 264 265 asf avc avs dav h264 h265 hevc m2t m2ts m2v m4v mpeg mpv mts vpy y4m".Split(' '); + + return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + } + + public static string[] GetAudioExts() + { + string exts = Player.GetPropertyString("audio-exts"); + + if (string.IsNullOrEmpty(exts)) + return "mp3 flac m4a mka mp2 ogg opus aac ac3 dts dtshd dtshr dtsma eac3 mpa mpc thd w64 wav".Split(' '); + + return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + } + + public static string[] GetImgExts() + { + string exts = Player.GetPropertyString("image-exts"); + + if (string.IsNullOrEmpty(exts)) + return new string[]{ "jpg", "bmp", "png", "gif", "webp" }; + + return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + } + + public static bool IsMedia(string[] exts, string ext) => + IsVideo(exts, ext) || IsAudio(exts, ext) || IsImage(exts, ext); + + public static IEnumerable GetMediaFiles(string[] files) => + files.Where(i => IsMedia(files, i.Ext())); } diff --git a/src/MpvNet/MpvClient.cs b/src/MpvNet/MpvClient.cs index 28b4c2fe..6b2dd6b3 100644 --- a/src/MpvNet/MpvClient.cs +++ b/src/MpvNet/MpvClient.cs @@ -346,6 +346,9 @@ public void SetPropertyDouble(string name, double value) public string GetPropertyString(string name) { + if (Handle == IntPtr.Zero) + return ""; + mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer); @@ -364,6 +367,12 @@ public string GetPropertyString(string name) public void SetPropertyString(string name, string value) { + if (Handle == IntPtr.Zero) + { + Terminal.WriteError($"error setting property: {name} = {value}"); + return; + } + byte[] bytes = GetUtf8Bytes(value); mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);