diff options
author | Halali <[email protected]> | 2019-10-05 22:55:35 +0200 |
---|---|---|
committer | Halali <[email protected]> | 2019-10-05 22:55:35 +0200 |
commit | b3c6def6bc72e85d8ad016cec8347e445b9fad8b (patch) | |
tree | b6e9ae0d3745f02f38b03c19caeccd6239e9587d /libs/subzero | |
parent | 4e5e7d674410810f3e7a36e0500e440d79395d85 (diff) | |
download | bazarr-b3c6def6bc72e85d8ad016cec8347e445b9fad8b.tar.gz bazarr-b3c6def6bc72e85d8ad016cec8347e445b9fad8b.zip |
Updated subliminal_path and subzero to latest dev version
Diffstat (limited to 'libs/subzero')
-rw-r--r-- | libs/subzero/language.py | 14 | ||||
-rw-r--r-- | libs/subzero/lib/dict.py | 6 | ||||
-rw-r--r-- | libs/subzero/video.py | 6 |
3 files changed, 24 insertions, 2 deletions
diff --git a/libs/subzero/language.py b/libs/subzero/language.py index 0a3a5e775..a13bab160 100644 --- a/libs/subzero/language.py +++ b/libs/subzero/language.py @@ -1,5 +1,6 @@ # coding=utf-8 import types +import re from babelfish.exceptions import LanguageError from babelfish import Language as Language_, basestr @@ -134,3 +135,16 @@ class Language(Language_): return Language(*Language_.fromietf(s).__getstate__()) return Language(*Language_.fromalpha3b(s).__getstate__()) + + +IETF_MATCH = ".+\.([^-.]+)(?:-[A-Za-z]+)?$" +ENDSWITH_LANGUAGECODE_RE = re.compile("\.([^-.]{2,3})(?:-[A-Za-z]{2,})?$") + + +def match_ietf_language(s, ietf=False): + language_match = re.match(".+\.([^\.]+)$" if not ietf + else IETF_MATCH, s) + if language_match and len(language_match.groups()) == 1: + language = language_match.groups()[0] + return language + return s diff --git a/libs/subzero/lib/dict.py b/libs/subzero/lib/dict.py index 3f327dcf4..929a9a642 100644 --- a/libs/subzero/lib/dict.py +++ b/libs/subzero/lib/dict.py @@ -107,6 +107,12 @@ class Dicked(object): for key, value in entries.iteritems(): self.__dict__[key] = (Dicked(**value) if isinstance(value, dict) else value) + def has(self, key): + return self._entries is not None and key in self._entries + + def get(self, key, default=None): + return self._entries.get(key, default) if self._entries else default + def __repr__(self): return str(self) diff --git a/libs/subzero/video.py b/libs/subzero/video.py index 13db33ddf..160e1afec 100644 --- a/libs/subzero/video.py +++ b/libs/subzero/video.py @@ -17,7 +17,8 @@ def has_external_subtitle(part_id, stored_subs, language): def set_existing_languages(video, video_info, external_subtitles=False, embedded_subtitles=False, known_embedded=None, - stored_subs=None, languages=None, only_one=False, known_metadata_subs=None): + stored_subs=None, languages=None, only_one=False, known_metadata_subs=None, + match_strictness="strict"): logger.debug(u"Determining existing subtitles for %s", video.name) external_langs_found = set() @@ -27,7 +28,8 @@ def set_existing_languages(video, video_info, external_subtitles=False, embedded external_langs_found = known_metadata_subs external_langs_found.update(set(search_external_subtitles(video.name, languages=languages, - only_one=only_one).values())) + only_one=only_one, + match_strictness=match_strictness).values())) # found external subtitles should be considered? if external_subtitles: |