support for autocreate-playlist, video-exts, audio-exts, image-exts

This commit is contained in:
stax76
2024-10-12 21:50:46 +02:00
parent cca474a5a5
commit 59a556794f
7 changed files with 85 additions and 44 deletions

View File

@@ -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.

View File

@@ -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=\<string\>
Video file extensions used to create file associations and used by the auto-load-folder feature.
#### --audio-file-extensions=\<string\>
Audio file extensions used to create file associations and used by the auto-load-folder feature.
#### --image-file-extensions=\<string\>
Image file extensions used to create file associations and used by the auto-load-folder feature.
#### --debug-mode=\<yes|no\>
Enable this only when a developer asks for it. Default: no

View File

@@ -236,9 +236,9 @@ public class GuiCommand
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 @@ public class GuiCommand
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;

View File

@@ -21,23 +21,11 @@ default = yes
option = yes
option = no
name = video-file-extensions
file = mpvnet
name = image-exts
file = mpv
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
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 = <N|inf|force|no> 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

View File

@@ -131,14 +131,12 @@ public class AppClass
{
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 class AppClass
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)

View File

@@ -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<string> GetMediaFiles(IEnumerable<string> 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<string> GetMediaFiles(string[] files) =>
files.Where(i => IsMedia(files, i.Ext()));
}

View File

@@ -346,6 +346,9 @@ public class MpvClient
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 class MpvClient
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);