aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/knowit/rules
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2023-03-21 23:15:01 -0400
committermorpheus65535 <[email protected]>2023-03-21 23:15:01 -0400
commit7455496c4c42518df5f20646d50a93ca66c1a912 (patch)
treef7992557e15e6d8c8494edb2789772aa4b0dce44 /libs/knowit/rules
parent71363830985a34f5f45a32972477e0ac83dce519 (diff)
downloadbazarr-7455496c4c42518df5f20646d50a93ca66c1a912.tar.gz
bazarr-7455496c4c42518df5f20646d50a93ca66c1a912.zip
Trying to fix Segmentation fault caused by mediainfo in docker container. #2098v1.2.1-beta.9
Diffstat (limited to 'libs/knowit/rules')
-rw-r--r--libs/knowit/rules/general.py33
-rw-r--r--libs/knowit/rules/subtitle.py17
2 files changed, 27 insertions, 23 deletions
diff --git a/libs/knowit/rules/general.py b/libs/knowit/rules/general.py
index b492c03a5..ad2c7734f 100644
--- a/libs/knowit/rules/general.py
+++ b/libs/knowit/rules/general.py
@@ -1,8 +1,6 @@
-
-import re
from logging import NullHandler, getLogger
-import babelfish
+from trakit.api import trakit
from knowit.core import Rule
@@ -10,22 +8,27 @@ logger = getLogger(__name__)
logger.addHandler(NullHandler())
+class GuessTitleRule(Rule):
+ """Guess properties from track title."""
+
+ def execute(self, props, pv_props, context):
+ """Language detection using name."""
+ if 'name' in props:
+ language = props.get('language')
+ options = {'expected_language': language} if language else {}
+ guessed = trakit(props['name'], options)
+ if guessed:
+ return guessed
+
+
class LanguageRule(Rule):
"""Language rules."""
- name_re = re.compile(r'(?P<name>\w+)\b', re.IGNORECASE)
-
def execute(self, props, pv_props, context):
"""Language detection using name."""
- if 'language' in props:
+ if 'guessed' not in pv_props:
return
- if 'name' in props:
- name = props.get('name', '')
- match = self.name_re.match(name)
- if match:
- try:
- return babelfish.Language.fromname(match.group('name'))
- except babelfish.Error:
- pass
- logger.info('Invalid %s: %r', self.description, name)
+ guess = pv_props['guessed']
+ if 'language' in guess:
+ return guess['language']
diff --git a/libs/knowit/rules/subtitle.py b/libs/knowit/rules/subtitle.py
index fa16fdbc1..704109f99 100644
--- a/libs/knowit/rules/subtitle.py
+++ b/libs/knowit/rules/subtitle.py
@@ -10,18 +10,19 @@ class ClosedCaptionRule(Rule):
def execute(self, props, pv_props, context):
"""Execute closed caption rule."""
- for name in (pv_props.get('_closed_caption'), props.get('name')):
- if name and self.cc_re.search(name):
- return True
+ if '_closed_caption' in pv_props and self.cc_re.search(pv_props['_closed_caption']):
+ return True
+
+ if 'guessed' in pv_props:
+ guessed = pv_props['guessed']
+ return guessed.get('closed_caption')
class HearingImpairedRule(Rule):
"""Hearing Impaired rule."""
- hi_re = re.compile(r'(\bsdh\b)', re.IGNORECASE)
-
def execute(self, props, pv_props, context):
"""Hearing Impaired."""
- name = props.get('name')
- if name and self.hi_re.search(name):
- return True
+ if 'guessed' in pv_props:
+ guessed = pv_props['guessed']
+ return guessed.get('hearing_impaired')