summaryrefslogtreecommitdiffhomepage
path: root/libs/subzero
diff options
context:
space:
mode:
authorLouis Vézina <[email protected]>2019-10-05 22:57:42 -0400
committerLouis Vézina <[email protected]>2019-10-05 22:57:42 -0400
commitafd9cd6ddbbdab9e6a6d5d8844fbda1882054c8f (patch)
tree0ff406fb498cb773b0841567dcb4241c75623b30 /libs/subzero
parent4626d3f93c787121e081673f4cf9a5602766a95d (diff)
parentd65601d9cbc3f60276882583ea253520e51f7324 (diff)
downloadbazarr-afd9cd6ddbbdab9e6a6d5d8844fbda1882054c8f.tar.gz
bazarr-afd9cd6ddbbdab9e6a6d5d8844fbda1882054c8f.zip
Merge branch 'development' into python3
# Conflicts: # bazarr/get_movies.py # libs/subliminal_patch/core.py # libs/subliminal_patch/providers/subdivx.py # libs/subliminal_patch/providers/titlovi.py
Diffstat (limited to 'libs/subzero')
-rw-r--r--libs/subzero/language.py14
-rw-r--r--libs/subzero/lib/dict.py6
-rw-r--r--libs/subzero/video.py6
3 files changed, 24 insertions, 2 deletions
diff --git a/libs/subzero/language.py b/libs/subzero/language.py
index fb7290740..d212a02f4 100644
--- a/libs/subzero/language.py
+++ b/libs/subzero/language.py
@@ -1,6 +1,7 @@
# coding=utf-8
from __future__ import absolute_import
import types
+import re
from babelfish.exceptions import LanguageError
from babelfish import Language as Language_, basestr
@@ -139,3 +140,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 05516d4b8..e89071bcb 100644
--- a/libs/subzero/lib/dict.py
+++ b/libs/subzero/lib/dict.py
@@ -107,6 +107,12 @@ class Dicked(object):
for key, value in six.iteritems(entries):
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 6e263bca9..0a06240f6 100644
--- a/libs/subzero/video.py
+++ b/libs/subzero/video.py
@@ -19,7 +19,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()
@@ -29,7 +30,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: