summaryrefslogtreecommitdiffhomepage
path: root/libs/subzero
diff options
context:
space:
mode:
authorjosdion <[email protected]>2020-07-29 20:31:30 +0300
committerjosdion <[email protected]>2020-07-29 20:31:30 +0300
commit859922b9c71d53867112fd7208a771adaacb930b (patch)
tree73d436c649fcc6ad0a5fdbc113de1f1e770c3afd /libs/subzero
parent1432f83bf4bd35d3022a1117e0eefc466f9d3ebb (diff)
downloadbazarr-859922b9c71d53867112fd7208a771adaacb930b.tar.gz
bazarr-859922b9c71d53867112fd7208a771adaacb930b.zip
merge from Sub-Zero.bundle
merge some fixes from panal/Sub-Zero.bundle
Diffstat (limited to 'libs/subzero')
-rw-r--r--libs/subzero/modification/exc.py7
-rw-r--r--libs/subzero/modification/main.py15
-rw-r--r--libs/subzero/modification/mods/__init__.py6
-rw-r--r--libs/subzero/modification/mods/hearing_impaired.py5
-rw-r--r--libs/subzero/modification/processors/re_processor.py18
5 files changed, 31 insertions, 20 deletions
diff --git a/libs/subzero/modification/exc.py b/libs/subzero/modification/exc.py
new file mode 100644
index 000000000..b9828dd3f
--- /dev/null
+++ b/libs/subzero/modification/exc.py
@@ -0,0 +1,7 @@
+# coding=utf-8
+class EmptyEntryError(Exception):
+ pass
+
+
+class EmptyLineError(Exception):
+ pass
diff --git a/libs/subzero/modification/main.py b/libs/subzero/modification/main.py
index e67042755..69822b093 100644
--- a/libs/subzero/modification/main.py
+++ b/libs/subzero/modification/main.py
@@ -7,7 +7,8 @@ import pysubs2
import logging
import time
-from .mods import EMPTY_TAG_PROCESSOR, EmptyEntryError
+from .mods import EMPTY_TAG_PROCESSOR
+from .exc import EmptyEntryError
from .registry import registry
from subzero.language import Language
import six
@@ -15,8 +16,6 @@ import six
logger = logging.getLogger(__name__)
-lowercase_re = re.compile(r'(?sux)[a-zà-ž]')
-
class SubtitleModifications(object):
debug = False
@@ -189,7 +188,7 @@ class SubtitleModifications(object):
sub = processor.process(sub)
if sub.strip():
- if lowercase_re.search(sub):
+ if not sub.isupper():
return False
entry_used = True
@@ -302,11 +301,11 @@ class SubtitleModifications(object):
mod = self.initialized_mods[identifier]
try:
- line = mod.modify(line.strip(), entry=entry.text, debug=self.debug, parent=self, index=index,
+ line = mod.modify(line.strip(), entry=t, debug=self.debug, parent=self, index=index,
**args)
except EmptyEntryError:
if self.debug:
- logger.debug(u"%d: %s: %r -> ''", index, identifier, entry.text)
+ logger.debug(u"%d: %s: %r -> ''", index, identifier, t)
skip_entry = True
break
@@ -331,11 +330,11 @@ class SubtitleModifications(object):
mod = self.initialized_mods[identifier]
try:
- line = mod.modify(line.strip(), entry=entry.text, debug=self.debug, parent=self, index=index,
+ line = mod.modify(line.strip(), entry=t, debug=self.debug, parent=self, index=index,
procs=["last_process"], **args)
except EmptyEntryError:
if self.debug:
- logger.debug(u"%d: %s: %r -> ''", index, identifier, entry.text)
+ logger.debug(u"%d: %s: %r -> ''", index, identifier, t)
skip_entry = True
break
diff --git a/libs/subzero/modification/mods/__init__.py b/libs/subzero/modification/mods/__init__.py
index e38e899c9..b1a828ad4 100644
--- a/libs/subzero/modification/mods/__init__.py
+++ b/libs/subzero/modification/mods/__init__.py
@@ -109,9 +109,3 @@ empty_line_post_processors = [
]
-class EmptyEntryError(Exception):
- pass
-
-
-class EmptyLineError(Exception):
- pass
diff --git a/libs/subzero/modification/mods/hearing_impaired.py b/libs/subzero/modification/mods/hearing_impaired.py
index 87088508b..34458e2df 100644
--- a/libs/subzero/modification/mods/hearing_impaired.py
+++ b/libs/subzero/modification/mods/hearing_impaired.py
@@ -3,7 +3,8 @@ from __future__ import absolute_import
from __future__ import unicode_literals
import re
-from subzero.modification.mods import SubtitleTextModification, empty_line_post_processors, EmptyEntryError, TAG
+from subzero.modification.mods import SubtitleTextModification, empty_line_post_processors, TAG
+from subzero.modification.exc import EmptyEntryError
from subzero.modification.processors.re_processor import NReProcessor
from subzero.modification import registry
@@ -93,7 +94,7 @@ class HearingImpaired(SubtitleTextModification):
# remove music entries
NReProcessor(re.compile(r'(?ums)(^[-\s>~]*[*#¶♫♪]+\s*.+|.+\s*[*#¶♫♪]+\s*$)'),
- "", name="HI_music"),
+ "", name="HI_music", entry=True),
]
diff --git a/libs/subzero/modification/processors/re_processor.py b/libs/subzero/modification/processors/re_processor.py
index ad07240d2..9bc71110f 100644
--- a/libs/subzero/modification/processors/re_processor.py
+++ b/libs/subzero/modification/processors/re_processor.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import
import re
import logging
+from subzero.modification.exc import EmptyEntryError
from subzero.modification.processors import Processor
logger = logging.getLogger(__name__)
@@ -15,13 +16,22 @@ class ReProcessor(Processor):
pattern = None
replace_with = None
- def __init__(self, pattern, replace_with, name=None, supported=None):
+ def __init__(self, pattern, replace_with, name=None, supported=None, entry=False, **kwargs):
super(ReProcessor, self).__init__(name=name, supported=supported)
self.pattern = pattern
self.replace_with = replace_with
+ self.use_entry = entry
- def process(self, content, debug=False, **kwargs):
- return self.pattern.sub(self.replace_with, content)
+ def process(self, content, debug=False, entry=None, **kwargs):
+ if not self.use_entry:
+ return self.pattern.sub(self.replace_with, content)
+
+ ret = self.pattern.sub(self.replace_with, entry)
+ if not ret:
+ raise EmptyEntryError()
+ elif ret != entry:
+ return ret
+ return content
class NReProcessor(ReProcessor):
@@ -37,7 +47,7 @@ class MultipleWordReProcessor(ReProcessor):
}
replaces found key in pattern with the corresponding value in data
"""
- def __init__(self, snr_dict, name=None, parent=None, supported=None):
+ def __init__(self, snr_dict, name=None, parent=None, supported=None, **kwargs):
super(ReProcessor, self).__init__(name=name, supported=supported)
self.snr_dict = snr_dict