mirror of
https://github.com/mpv-player/mpv
synced 2025-01-05 14:40:43 +00:00
sub: fix --sub-codepage UTF-8 with fallback
Fixes e.g --sub-codepage=utf8:gb18030 if the subtitle us UTF-8.
This was broken in commit e5d31808
.
Also log the detected charset in verbose mode.
This commit is contained in:
parent
e6fd6d6e49
commit
d60270ed3d
@ -239,6 +239,9 @@ const char *mp_charset_guess(void *talloc_ctx, struct mp_log *log, bstr buf,
|
|||||||
if (bstrcasecmp0(type, "utf8") == 0 || bstrcasecmp0(type, "utf-8") == 0) {
|
if (bstrcasecmp0(type, "utf8") == 0 || bstrcasecmp0(type, "utf-8") == 0) {
|
||||||
if (!fallback)
|
if (!fallback)
|
||||||
fallback = params[1].start; // must be already 0-terminated
|
fallback = params[1].start; // must be already 0-terminated
|
||||||
|
int r = bstr_validate_utf8(buf);
|
||||||
|
if (r >= 0 || (r > -8 && (flags & MP_ICONV_ALLOW_CUTOFF)))
|
||||||
|
res = "utf-8";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
@ -252,6 +255,7 @@ const char *mp_charset_guess(void *talloc_ctx, struct mp_log *log, bstr buf,
|
|||||||
if (!res && !(flags & MP_STRICT_UTF8))
|
if (!res && !(flags & MP_STRICT_UTF8))
|
||||||
res = "UTF-8-BROKEN";
|
res = "UTF-8-BROKEN";
|
||||||
|
|
||||||
|
mp_verbose(log, "Using charset '%s'.\n", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user