Skip to content

Commit 59a5567

Browse files
committed
support for autocreate-playlist, video-exts, audio-exts, image-exts
1 parent cca474a commit 59a5567

File tree

7 files changed

+85
-44
lines changed

7 files changed

+85
-44
lines changed

docs/changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
# v7.1.1.3 Beta (????-??-??)
3+
4+
- Support for autocreate-playlist, video-exts, audio-exts, image-exts.
5+
Windows 7 support should still work, but needs auto-load-folder to be enabled.
6+
27
# v7.1.1.2 Beta (2024-10-10)
38

49
- Polish translation fixed. German, Turkish and Japanese translation updated.

docs/manual.md

-12
Original file line numberDiff line numberDiff line change
@@ -448,18 +448,6 @@ Amount of recent files to be remembered. Default: 15
448448

449449
Usage of the media info library instead of mpv to access media information. Default: yes (mpv.net specific option)
450450

451-
#### --video-file-extensions=\<string\>
452-
453-
Video file extensions used to create file associations and used by the auto-load-folder feature.
454-
455-
#### --audio-file-extensions=\<string\>
456-
457-
Audio file extensions used to create file associations and used by the auto-load-folder feature.
458-
459-
#### --image-file-extensions=\<string\>
460-
461-
Image file extensions used to create file associations and used by the auto-load-folder feature.
462-
463451
#### --debug-mode=\<yes|no\>
464452

465453
Enable this only when a developer asks for it. Default: no

src/MpvNet.Windows/GuiCommand.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ void RegisterFileAssociations(IList<string> args)
236236

237237
switch (perceivedType)
238238
{
239-
case "video": extensions = FileTypes.Video; break;
240-
case "audio": extensions = FileTypes.Audio; break;
241-
case "image": extensions = FileTypes.Image; break;
239+
case "video": extensions = FileTypes.GetVideoExts(); break;
240+
case "audio": extensions = FileTypes.GetAudioExts(); break;
241+
case "image": extensions = FileTypes.GetImgExts(); break;
242242
}
243243

244244
try
@@ -284,13 +284,13 @@ void ShowMediaInfo(IList<string> args)
284284

285285
if (File.Exists(path) && osd)
286286
{
287-
if (FileTypes.Audio.Contains(path.Ext()))
287+
if (FileTypes.IsAudio(path.Ext()))
288288
{
289289
text = Player.GetPropertyOsdString("filtered-metadata");
290290
Player.CommandV("show-text", text, "5000");
291291
return;
292292
}
293-
else if (FileTypes.Image.Contains(path.Ext()))
293+
else if (FileTypes.IsImage(path.Ext()))
294294
{
295295
fileSize = new FileInfo(path).Length;
296296

src/MpvNet.Windows/Resources/editor_conf.txt

+25-16
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,11 @@ default = yes
2121
option = yes
2222
option = no
2323

24-
name = video-file-extensions
25-
file = mpvnet
26-
directory = General
27-
width = 500
28-
help = Video file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option)
29-
30-
name = audio-file-extensions
31-
file = mpvnet
32-
directory = General
33-
width = 500
34-
help = Audio file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option)
35-
36-
name = image-file-extensions
37-
file = mpvnet
24+
name = image-exts
25+
file = mpv
3826
directory = General
3927
width = 500
40-
help = Image file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net option)
28+
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.
4129

4230
name = menu-syntax
4331
file = mpvnet
@@ -790,6 +778,12 @@ file = mpv
790778
directory = Video/Screenshot
791779
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.
792780

781+
name = video-exts
782+
file = mpv
783+
directory = Video
784+
width = 500
785+
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.
786+
793787
name = volume
794788
file = mpv
795789
directory = Audio
@@ -833,6 +827,12 @@ default = yes
833827
option = yes
834828
option = no
835829

830+
name = audio-exts
831+
file = mpv
832+
directory = Audio
833+
width = 500
834+
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.
835+
836836
name = slang
837837
file = mpv
838838
directory = Subtitle
@@ -1097,10 +1097,19 @@ file = mpv
10971097
directory = Playback
10981098
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.
10991099

1100+
name = autocreate-playlist
1101+
file = mpv
1102+
directory = Playback
1103+
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.
1104+
default = filter
1105+
option = no
1106+
option = filter
1107+
option = same
1108+
11001109
name = auto-load-folder
11011110
file = mpvnet
11021111
directory = Playback
1103-
help = For single files automatically load the entire directory into the playlist. (mpv.net option)
1112+
help = For single files automatically load the entire directory into the playlist. (deprecated mpv.net option, autocreate-playlist can be used instead)
11041113
default = yes
11051114
option = yes
11061115
option = no

src/MpvNet/App.cs

-3
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ public bool ProcessProperty(string name, string value, bool writeError = false)
131131
{
132132
switch (name)
133133
{
134-
case "audio-file-extensions": FileTypes.Audio = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
135134
case "auto-load-folder": AutoLoadFolder = value == "yes"; return true;
136135
case "autofit-audio": AutofitAudio = value.Trim('%').ToInt(70) / 100f; return true;
137136
case "autofit-image": AutofitImage = value.Trim('%').ToInt(80) / 100f; return true;
138137
case "dark-mode": DarkMode = value; return true;
139138
case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true;
140139
case "debug-mode": DebugMode = value == "yes"; return true;
141-
case "image-file-extensions": FileTypes.Image = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
142140
case "language": Language = value; return true;
143141
case "light-theme": LightTheme = value.Trim('\'', '"'); return true;
144142
case "media-info": MediaInfo = value == "yes"; return true;
@@ -152,7 +150,6 @@ public bool ProcessProperty(string name, string value, bool writeError = false)
152150
case "remember-volume": RememberVolume = value == "yes"; return true;
153151
case "remember-window-position": RememberWindowPosition = value == "yes"; return true;
154152
case "start-size": StartSize = value; return true;
155-
case "video-file-extensions": FileTypes.Video = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
156153

157154
default:
158155
if (writeError)

src/MpvNet/FileTypes.cs

+41-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,49 @@ namespace MpvNet;
55

66
public static class FileTypes
77
{
8-
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(' ');
9-
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(' ');
10-
public static string[] Image { get; set; } = { "jpg", "bmp", "png", "gif", "webp" };
118
public static string[] Subtitle { get; } = { "srt", "ass", "idx", "sub", "sup", "ttxt", "txt", "ssa", "smi", "mks" };
129

13-
public static bool IsImage(string extension) => Image.Contains(extension);
14-
public static bool IsAudio(string extension) => Audio.Contains(extension);
10+
public static bool IsVideo(string[] exts, string ext) => exts?.Contains(ext) ?? false;
11+
public static bool IsAudio(string[] exts, string ext) => exts?.Contains(ext) ?? false;
12+
public static bool IsImage(string[] exts, string ext) => exts?.Contains(ext) ?? false;
1513

16-
public static bool IsMedia(string extension) =>
17-
Video.Contains(extension) || Audio.Contains(extension) || Image.Contains(extension);
14+
public static bool IsVideo(string ext) => GetVideoExts().Contains(ext);
15+
public static bool IsAudio(string ext) => GetAudioExts().Contains(ext);
16+
public static bool IsImage(string ext) => GetImgExts().Contains(ext);
1817

19-
public static IEnumerable<string> GetMediaFiles(IEnumerable<string> files) => files.Where(i => IsMedia(i.Ext()));
18+
public static string[] GetVideoExts()
19+
{
20+
string exts = Player.GetPropertyString("video-exts");
21+
22+
if (string.IsNullOrEmpty(exts))
23+
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(' ');
24+
25+
return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
26+
}
27+
28+
public static string[] GetAudioExts()
29+
{
30+
string exts = Player.GetPropertyString("audio-exts");
31+
32+
if (string.IsNullOrEmpty(exts))
33+
return "mp3 flac m4a mka mp2 ogg opus aac ac3 dts dtshd dtshr dtsma eac3 mpa mpc thd w64 wav".Split(' ');
34+
35+
return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
36+
}
37+
38+
public static string[] GetImgExts()
39+
{
40+
string exts = Player.GetPropertyString("image-exts");
41+
42+
if (string.IsNullOrEmpty(exts))
43+
return new string[]{ "jpg", "bmp", "png", "gif", "webp" };
44+
45+
return exts.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
46+
}
47+
48+
public static bool IsMedia(string[] exts, string ext) =>
49+
IsVideo(exts, ext) || IsAudio(exts, ext) || IsImage(exts, ext);
50+
51+
public static IEnumerable<string> GetMediaFiles(string[] files) =>
52+
files.Where(i => IsMedia(files, i.Ext()));
2053
}

src/MpvNet/MpvClient.cs

+9
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ public void SetPropertyDouble(string name, double value)
346346

347347
public string GetPropertyString(string name)
348348
{
349+
if (Handle == IntPtr.Zero)
350+
return "";
351+
349352
mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name),
350353
mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
351354

@@ -364,6 +367,12 @@ public string GetPropertyString(string name)
364367

365368
public void SetPropertyString(string name, string value)
366369
{
370+
if (Handle == IntPtr.Zero)
371+
{
372+
Terminal.WriteError($"error setting property: {name} = {value}");
373+
return;
374+
}
375+
367376
byte[] bytes = GetUtf8Bytes(value);
368377
mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
369378

0 commit comments

Comments
 (0)