summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-08-10 17:36:22 -0500
committerDudemanguy <random342@airmail.cc>2023-08-26 00:33:00 +0000
commit32be72623b1d43027f2d97c15fcf604d8c328e00 (patch)
tree7d58216175bb08fc77ae746d19902194bdbfa43f /options
parentafdd2fa5656140c55a0b685e498a89a2249a623a (diff)
downloadmpv-32be72623b1d43027f2d97c15fcf604d8c328e00.tar.bz2
mpv-32be72623b1d43027f2d97c15fcf604d8c328e00.tar.xz
player: make all autoload extensions configurable
--audio-file-auto, --cover-art-auto, and --sub-auto all work by using an internally hardcoded list that determine what file extensions get recognized. This is fine and people periodically update it, but we can actually expose this as a stringlist option instead. This way users can add or remove any file extension for any type. For the most part, this is pretty pretty easy and involves making sub_exts, etc. the defaults for the new options (--audio-file-auto-exts, --cover-art-auto-exts, and --sub-auto-exts). There's actually one slight complication however. The input code uses mp_might_be_subtitle_file which guesses if the file drag and dropped file is a subtitle. The input ctx has no access to mpctx so we have to be clever here. For this, the trick is to recognize that we can leverage the m_option_change_callback. We add a new flag, UPDATE_SUB_EXTS, which fires when the player starts up. Then in the callback, we can set the value of sub_exts in external_files to opts->sub_auto_exts. Whenever the option updates, the callback is fired again and sub_exts updates. That way mp_might_be_subtitle_file can just operate off of this global variable instead of trying to mess with the core mpv state directly. Fixes #12000.
Diffstat (limited to 'options')
-rw-r--r--options/m_option.h3
-rw-r--r--options/options.c55
-rw-r--r--options/options.h3
3 files changed, 60 insertions, 1 deletions
diff --git a/options/m_option.h b/options/m_option.h
index 1adac938e4..c868487b3e 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -433,7 +433,8 @@ char *format_file_size(int64_t size);
#define UPDATE_HWDEC (1 << 20) // --hwdec
#define UPDATE_DVB_PROG (1 << 21) // some --dvbin-...
#define UPDATE_SUB_HARD (1 << 22) // subtitle opts. that need full reinit
-#define UPDATE_OPT_LAST (1 << 22)
+#define UPDATE_SUB_EXTS (1 << 23) // update internal list of sub exts
+#define UPDATE_OPT_LAST (1 << 23)
// All bits between _FIRST and _LAST (inclusive)
#define UPDATE_OPTS_MASK \
diff --git a/options/options.c b/options/options.c
index 7d00537b28..7b9156a823 100644
--- a/options/options.c
+++ b/options/options.c
@@ -615,10 +615,13 @@ static const m_option_t mp_opts[] = {
{"sub-auto", OPT_CHOICE(sub_auto,
{"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})},
+ {"sub-auto-exts", OPT_STRINGLIST(sub_auto_exts), .flags = UPDATE_SUB_EXTS},
{"audio-file-auto", OPT_CHOICE(audiofile_auto,
{"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})},
+ {"audio-file-auto-exts", OPT_STRINGLIST(audiofile_auto_exts)},
{"cover-art-auto", OPT_CHOICE(coverart_auto,
{"no", -1}, {"exact", 0}, {"fuzzy", 1}, {"all", 2})},
+ {"cover-art-auto-exts", OPT_STRINGLIST(coverart_auto_exts)},
{"cover-art-whitelist", OPT_BOOL(coverart_whitelist)},
{"", OPT_SUBSTRUCT(subs_rend, mp_subtitle_sub_opts)},
@@ -1056,6 +1059,58 @@ static const struct MPOpts mp_default_opts = {
.screenshot_template = "mpv-shot%n",
.play_dir = 1,
+ .audiofile_auto_exts = (char *[]){
+ "aac",
+ "ac3",
+ "dts",
+ "eac3",
+ "flac",
+ "m4a",
+ "mka",
+ "mp3",
+ "ogg",
+ "opus",
+ "thd",
+ "wav",
+ "wv",
+ NULL
+ },
+
+ .coverart_auto_exts = (char *[]){
+ "avif",
+ "bmp",
+ "gif",
+ "jpeg",
+ "jpg",
+ "jxl",
+ "png",
+ "tif",
+ "tiff",
+ "webp",
+ NULL
+ },
+
+ .sub_auto_exts = (char *[]){
+ "ass",
+ "idx",
+ "lrc",
+ "mks",
+ "pgs",
+ "rt",
+ "sbv",
+ "scc",
+ "smi",
+ "srt",
+ "ssa",
+ "sub",
+ "sup",
+ "utf",
+ "utf-8",
+ "utf8",
+ "vtt",
+ NULL
+ },
+
.audio_output_channels = {
.set = 1,
.auto_safe = 1,
diff --git a/options/options.h b/options/options.h
index fac88dd939..6f8c8a5998 100644
--- a/options/options.h
+++ b/options/options.h
@@ -309,8 +309,11 @@ typedef struct MPOpts {
char **external_files;
bool autoload_files;
int sub_auto;
+ char **sub_auto_exts;
int audiofile_auto;
+ char **audiofile_auto_exts;
int coverart_auto;
+ char **coverart_auto_exts;
bool coverart_whitelist;
bool osd_bar_visible;