summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorXavier Xiong <[email protected]>2021-02-12 20:15:19 +0100
committerGitHub <[email protected]>2021-02-12 14:15:19 -0500
commit1548263a6c960354ef61445a5206c2190eaa79e9 (patch)
tree560031e203014bd1d5cb0afea91b6e5ac527b308 /libs
parent06092c14a9bfa3d1e5a6284d1bb681f27b00c9cb (diff)
downloadbazarr-1548263a6c960354ef61445a5206c2190eaa79e9.tar.gz
bazarr-1548263a6c960354ef61445a5206c2190eaa79e9.zip
Adding simplified and traditional Chinese subtitles support (#1236)
Diffstat (limited to 'libs')
-rw-r--r--libs/subliminal_patch/converters/assrt.py10
-rw-r--r--libs/subliminal_patch/core.py25
2 files changed, 26 insertions, 9 deletions
diff --git a/libs/subliminal_patch/converters/assrt.py b/libs/subliminal_patch/converters/assrt.py
index 536d4b4ff..eb3ed29da 100644
--- a/libs/subliminal_patch/converters/assrt.py
+++ b/libs/subliminal_patch/converters/assrt.py
@@ -5,12 +5,12 @@ from subliminal.exceptions import ConfigurationError
class AssrtConverter(LanguageReverseConverter):
def __init__(self):
- self.from_assrt = { u'简体': ('zho', None, 'Hans'), u'繁体': ('zho', None, 'Hant'),
- u'簡體': ('zho', None, 'Hans'), u'繁體': ('zho', None, 'Hant'),
+ self.from_assrt = { u'简体': ('zho', 'CN', None), u'繁体': ('zho', 'TW', None),
+ u'簡體': ('zho', 'CN', None), u'繁體': ('zho', 'TW', None),
u'英文': ('eng',),
- u'chs': ('zho', None, 'Hans'), u'cht': ('zho', None, 'Hant'),
- u'chn': ('zho', None, 'Hans'), u'twn': ('zho', None, 'Hant')}
- self.to_assrt = { ('zho', None, 'Hans'): u'chs', ('zho', None, 'Hant'): u'cht',
+ u'chs': ('zho', 'CN', None), u'cht': ('zho', 'TW', None),
+ u'chn': ('zho', 'CN', None), u'twn': ('zho', 'TW', None)}
+ self.to_assrt = { ('zho', 'CN', None): u'chs', ('zho', 'TW', None): u'cht',
('eng', None, None) : u'eng', ('zho', None, None): u'chs'}
self.codes = set(self.from_assrt.keys())
diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py
index de3829188..76e11402a 100644
--- a/libs/subliminal_patch/core.py
+++ b/libs/subliminal_patch/core.py
@@ -636,6 +636,13 @@ def _search_external_subtitles(path, languages=None, only_one=False, scandir_gen
hi_tag = ["hi", "cc", "sdh"]
hi = any(i for i in hi_tag if i in adv_tag)
+ #add simplified/traditional chinese detection
+ simplified_chinese = ["chs", "sc", "zhs", "hans", "gb", u"简", u"双语"]
+ traditional_chinese = ["cht", "tc", "zht", "hant", "big5", u"繁", u"雙語"]
+ FULL_LANGUAGE_LIST.extend(simplified_chinese)
+ FULL_LANGUAGE_LIST.extend(traditional_chinese)
+ p_root = p_root.replace('zh-TW', 'zht')
+
# remove possible language code for matching
p_root_bare = ENDSWITH_LANGUAGECODE_RE.sub(
lambda m: "" if str(m.group(1)).lower() in FULL_LANGUAGE_LIST else m.group(0), p_root)
@@ -655,14 +662,24 @@ def _search_external_subtitles(path, languages=None, only_one=False, scandir_gen
try:
language_code = p_root.rsplit(".", 1)[1].replace('_', '-')
try:
- language = Language.fromietf(language_code)
+ language = Language.fromietf(language_code)
language.forced = forced
language.hi = hi
except (ValueError, LanguageReverseError):
- logger.error('Cannot parse language code %r', language_code)
- language_code = None
+ #add simplified/traditional chinese detection
+ if any(ext in str(language_code) for ext in simplified_chinese):
+ language = Language.fromietf('zh')
+ language.forced = forced
+ language.hi = hi
+ elif any(ext in str(language_code) for ext in traditional_chinese):
+ language = Language.fromietf('zh')
+ language.forced = forced
+ language.hi = hi
+ else:
+ logger.error('Cannot parse language code %r', language_code)
+ language_code = None
except IndexError:
- language_code = None
+ language_code = None
if not language and not language_code and only_one:
language = Language.rebuild(list(languages)[0], forced=forced, hi=hi)