From d5dae869c6522a8d95a1bc762a4133e675d08c63 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 27 Nov 2017 19:45:13 +0100 Subject: 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.) --- player/external_files.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'player') 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); } -- cgit v1.2.3