summaryrefslogtreecommitdiffstats
path: root/player/external_files.c
diff options
context:
space:
mode:
Diffstat (limited to 'player/external_files.c')
-rw-r--r--player/external_files.c98
1 files changed, 69 insertions, 29 deletions
diff --git a/player/external_files.c b/player/external_files.c
index 69610642d2..2e0091261d 100644
--- a/player/external_files.c
+++ b/player/external_files.c
@@ -32,37 +32,64 @@
#include "options/path.h"
#include "external_files.h"
-static const char *const sub_exts[] = {"utf", "utf8", "utf-8", "idx", "sub",
- "srt", "rt", "ssa", "ass", "mks", "vtt",
- "sup", "scc", "smi", "lrc", "pgs",
- NULL};
-
-static const char *const audio_exts[] = {"mp3", "aac", "mka", "dts", "flac",
- "ogg", "m4a", "ac3", "opus", "wav",
- "wv",
- NULL};
-
-static bool test_ext_list(bstr ext, const char *const *list)
+// Stolen from: vlc/-/blob/master/modules/meta_engine/folder.c#L40
+// sorted by priority (descending)
+static const char *const cover_files[] = {
+ "AlbumArt",
+ "Album",
+ "cover",
+ "front",
+ "AlbumArtSmall",
+ "Folder",
+ ".folder",
+ "thumb",
+ NULL
+};
+
+// Needed for mp_might_be_subtitle_file
+char **sub_exts;
+
+static bool test_ext_list(bstr ext, char **list)
{
+ if (!list)
+ goto done;
for (int n = 0; list[n]; n++) {
if (bstrcasecmp(bstr0(list[n]), ext) == 0)
return true;
}
+done:
return false;
}
-static int test_ext(bstr ext)
+static int test_ext(MPOpts *opts, bstr ext)
{
- if (test_ext_list(ext, sub_exts))
+ if (test_ext_list(ext, opts->sub_auto_exts))
return STREAM_SUB;
- if (test_ext_list(ext, audio_exts))
+ if (test_ext_list(ext, opts->audiofile_auto_exts))
return STREAM_AUDIO;
+ if (test_ext_list(ext, opts->coverart_auto_exts))
+ return STREAM_VIDEO;
return -1;
}
+static int test_cover_filename(bstr fname)
+{
+ for (int n = 0; cover_files[n]; n++) {
+ if (bstrcasecmp(bstr0(cover_files[n]), fname) == 0) {
+ return MP_ARRAY_SIZE(cover_files) - n;
+ }
+ }
+ return 0;
+}
+
bool mp_might_be_subtitle_file(const char *filename)
{
- return test_ext(bstr_get_ext(bstr0(filename))) == STREAM_SUB;
+ return test_ext_list(bstr_get_ext(bstr0(filename)), sub_exts);
+}
+
+void mp_update_subtitle_exts(struct MPOpts *opts)
+{
+ sub_exts = opts->sub_auto_exts;
}
static int compare_sub_filename(const void *a, const void *b)
@@ -115,6 +142,14 @@ static struct bstr guess_lang_from_filename(struct bstr name, int *fn_start)
return (struct bstr){name.start + i + 1, n};
}
+char *mp_guess_lang_from_filename(void* ctx, const char *filename)
+{
+ bstr filename_no_ext = bstr_strip_ext(bstr0(filename));
+ int start = 0; // only used in append_dir_subtitles()
+ char *lang = bstrto0(ctx, guess_lang_from_filename(filename_no_ext, &start));
+ return lang;
+}
+
static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
struct subfn **slist, int *nsub,
struct bstr path, const char *fname,
@@ -158,7 +193,7 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
talloc_steal(tmpmem2, dename.start);
// check what it is (most likely)
- int type = test_ext(tmp_fname_ext);
+ int type = test_ext(opts, tmp_fname_ext);
char **langs = NULL;
int fuzz = -1;
switch (type) {
@@ -170,6 +205,9 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
langs = opts->stream_lang[type];
fuzz = opts->audiofile_auto;
break;
+ case STREAM_VIDEO:
+ fuzz = opts->coverart_auto;
+ break;
}
if (fuzz < 0 || (limit_type >= 0 && limit_type != type))
@@ -183,34 +221,36 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
prio |= 32; // exact movie name match
bstr lang = {0};
+ int start = 0;
+ lang = guess_lang_from_filename(tmp_fname_trim, &start);
if (bstr_startswith(tmp_fname_trim, f_fname_trim)) {
- int start = 0;
- lang = guess_lang_from_filename(tmp_fname_trim, &start);
-
if (lang.len && start == f_fname_trim.len)
prio |= 16; // exact movie name + followed by lang
- }
- for (int n = 0; langs && langs[n]; n++) {
- if (lang.len && bstr_case_startswith(lang, bstr0(langs[n]))) {
- if (fuzz >= 1)
- prio |= 8; // known language -> boost priority
- break;
+ if (lang.len && fuzz >= 1)
+ prio |= 4; // matches the movie name + a language was matched
+
+ for (int n = 0; langs && langs[n]; n++) {
+ if (lang.len && bstr_case_startswith(lang, bstr0(langs[n]))) {
+ if (fuzz >= 1)
+ prio |= 8; // known language -> boost priority
+ break;
+ }
}
}
- if (lang.len && fuzz >= 1)
- prio |= 4; // matches the movie name + a language was matched
-
if (bstr_find(tmp_fname_trim, f_fname_trim) >= 0 && fuzz >= 1)
prio |= 2; // contains the movie name
+ if (type == STREAM_VIDEO && opts->coverart_whitelist && prio == 0)
+ prio = test_cover_filename(tmp_fname_trim);
+
// doesn't contain the movie name
// don't try in the mplayer subtitle directory
if (!limit_fuzziness && fuzz >= 2)
prio |= 1;
- mp_dbg(log, "Potential external file: \"%s\" Priority: %d\n",
+ mp_trace(log, "Potential external file: \"%s\" Priority: %d\n",
de->d_name, prio);
if (prio) {