summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-11-27 19:45:13 +0100
committerwm4 <wm4@nowhere>2017-11-27 19:45:13 +0100
commitd5dae869c6522a8d95a1bc762a4133e675d08c63 (patch)
tree194680f97f4081a06e960d037d251d92ac886ee9
parente7c12bead4e1a0b47e9a8e0f84fb2831a2ff87a5 (diff)
downloadmpv-d5dae869c6522a8d95a1bc762a4133e675d08c63.tar.bz2
mpv-d5dae869c6522a8d95a1bc762a4133e675d08c63.tar.xz
player: match subtitles with language tags with --sub-auto=exact
Apparently a relatively widespread convention, and almost as strict as the old "exact" semantics. (So it's not going to auto load radically unrelated files.)
-rw-r--r--player/external_files.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/player/external_files.c b/player/external_files.c
index f55e52b637..bc82e94e4f 100644
--- a/player/external_files.c
+++ b/player/external_files.c
@@ -123,10 +123,6 @@ static void append_dir_subtitles(struct mpv_global *global,
if (f_fbname.start != f_fname.start)
talloc_steal(tmpmem, f_fname.start);
- // 0 = nothing
- // 1 = any subtitle file
- // 2 = any sub file containing movie name
- // 3 = sub file containing movie name and the lang extension
char *path0 = bstrdup0(tmpmem, path);
if (mp_is_url(bstr0(path0)))
@@ -170,24 +166,25 @@ static void append_dir_subtitles(struct mpv_global *global,
goto next_sub;
// we have a (likely) subtitle file
+ // 0 = nothing
+ // 1 = any subtitle file
+ // 2 = any sub file containing movie name
+ // 3 = sub file containing movie name and the lang extension
int prio = 0;
- char *found_lang = NULL;
- if (langs) {
- if (bstr_startswith(tmp_fname_trim, f_fname_trim)) {
- struct bstr lang = guess_lang_from_filename(tmp_fname_trim);
- if (lang.len) {
- for (int n = 0; langs[n]; n++) {
- if (bstr_startswith0(lang, langs[n])) {
- prio = 4; // matches the movie name + lang extension
- found_lang = langs[n];
- break;
- }
- }
- }
+
+ bstr lang = {0};
+ if (bstr_startswith(tmp_fname_trim, f_fname_trim))
+ lang = guess_lang_from_filename(tmp_fname_trim);
+ for (int n = 0; langs && langs[n]; n++) {
+ if (lang.len && bstr_startswith0(lang, langs[n])) {
+ prio = 4; // matches the movie name + lang extension
+ break;
}
}
if (!prio && bstrcmp(tmp_fname_trim, f_fname_trim) == 0)
prio = 3; // matches the movie name
+ if (!prio && lang.len)
+ prio = 3; // matches the movie name + a language was matched
if (!prio && bstr_find(tmp_fname_trim, f_fname_trim) >= 0 && fuzz >= 1)
prio = 2; // contains the movie name
if (!prio) {
@@ -215,7 +212,7 @@ static void append_dir_subtitles(struct mpv_global *global,
sub->type = type;
sub->priority = prio;
sub->fname = subpath;
- sub->lang = found_lang;
+ sub->lang = lang.len ? bstrdup0(*slist, lang) : NULL;
} else
talloc_free(subpath);
}