loadfile: use mp_match_lang_single

This adds basic support for IETF language tags,
as well as matching 2-letter language codes against 3-letter ones (and vice versa).
This commit is contained in:
rcombs 2021-05-26 17:57:41 -05:00 committed by sfan5
parent eb14dbff3e
commit 76009bf7a6
2 changed files with 12 additions and 10 deletions

View File

@ -5,10 +5,11 @@ Track Selection
--------------- ---------------
``--alang=<languagecode[,languagecode,...]>`` ``--alang=<languagecode[,languagecode,...]>``
Specify a priority list of audio languages to use. Different container Specify a priority list of audio languages to use, as IETF language tags.
formats employ different language codes. DVDs use ISO 639-1 two-letter Equivalent ISO 639-1 two-letter and ISO 639-2 three-letter codes are treated the same.
language codes, Matroska, MPEG-TS and NUT use ISO 639-2 three-letter The first tag in the list whose language matches a track in the file will be used.
language codes, while OGM uses a free-form identifier. See also ``--aid``. A track that matches more subtags will be preferred over one that matches fewer,
with preference given to earlier subtags over later ones. See also ``--aid``.
This is a string list option. See `List Options`_ for details. This is a string list option. See `List Options`_ for details.
@ -20,10 +21,7 @@ Track Selection
audio. audio.
``--slang=<languagecode[,languagecode,...]>`` ``--slang=<languagecode[,languagecode,...]>``
Specify a priority list of subtitle languages to use. Different container Equivalent to ``--alang``, for subtitle tracks.
formats employ different language codes. DVDs use ISO 639-1 two letter
language codes, Matroska uses ISO 639-2 three letter language codes while
OGM uses a free-form identifier. See also ``--sid``.
This is a string list option. See `List Options`_ for details. This is a string list option. See `List Options`_ for details.
@ -33,6 +31,8 @@ Track Selection
a DVD and falls back on English if Hungarian is not available. a DVD and falls back on English if Hungarian is not available.
- ``mpv --slang=jpn example.mkv`` plays a Matroska file with Japanese - ``mpv --slang=jpn example.mkv`` plays a Matroska file with Japanese
subtitles. subtitles.
- ``mpv --slang=pt-BR example.mkv`` plays a Matroska file with Brazilian
Portuguese subtitles if available, and otherwise any Portuguese subtitles.
``--vlang=<...>`` ``--vlang=<...>``
Equivalent to ``--alang`` and ``--slang``, for video tracks. Equivalent to ``--alang`` and ``--slang``, for video tracks.

View File

@ -47,6 +47,7 @@
#include "common/recorder.h" #include "common/recorder.h"
#include "common/stats.h" #include "common/stats.h"
#include "input/input.h" #include "input/input.h"
#include "misc/language.h"
#include "audio/out/ao.h" #include "audio/out/ao.h"
#include "filters/f_decoder_wrapper.h" #include "filters/f_decoder_wrapper.h"
@ -447,8 +448,9 @@ static int match_lang(char **langs, const char *lang)
if (!lang) if (!lang)
return 0; return 0;
for (int idx = 0; langs && langs[idx]; idx++) { for (int idx = 0; langs && langs[idx]; idx++) {
if (lang && strcasecmp(langs[idx], lang) == 0) int score = mp_match_lang_single(langs[idx], lang);
return INT_MAX - idx; if (score > 0)
return INT_MAX - (idx + 1) * LANGUAGE_SCORE_MAX + score - 1;
} }
return 0; return 0;
} }