From 52df29a1f51d3975a2580cfd97bff31164d32a14 Mon Sep 17 00:00:00 2001 From: Jakob Koschel Date: Mon, 20 Feb 2023 14:47:53 +0100 Subject: [PATCH] Fixed uppercase mod to be run after hearing impaired mod --- libs/subzero/modification/main.py | 39 ------------------------ libs/subzero/modification/mods/common.py | 25 +++++++++++++++ 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/libs/subzero/modification/main.py b/libs/subzero/modification/main.py index 13bf22483..884c90de6 100644 --- a/libs/subzero/modification/main.py +++ b/libs/subzero/modification/main.py @@ -22,7 +22,6 @@ class SubtitleModifications(object): language = None initialized_mods = {} mods_used = [] - only_uppercase = False f = None font_style_tag_start = u"{\\" @@ -111,11 +110,6 @@ class SubtitleModifications(object): identifier, self.language) continue - if mod_cls.only_uppercase and not self.only_uppercase: - if self.debug: - logger.debug("Skipping %s, because the subtitle isn't all uppercase", identifier) - continue - # merge args of duplicate mods if possible elif mod_cls.args_mergeable and identifier in mods_merged: mods_merged[identifier] = mod_cls.merge_args(mods_merged[identifier], args) @@ -180,42 +174,9 @@ class SubtitleModifications(object): return line_mods, non_line_mods, used_mods - def detect_uppercase(self): - entries_used = 0 - for entry in self.f: - entry_used = False - for sub in entry.text.strip().split(r"\N"): - # skip HI bracket entries, those might actually be lowercase - sub = sub.strip() - for processor in registry.mods["remove_HI"].processors[:4]: - sub = processor.process(sub) - - if sub.strip(): - # only consider alphabetic characters to determine if uppercase - alpha_sub = ''.join([i for i in sub if i.isalpha()]) - if alpha_sub and not alpha_sub.isupper(): - return False - - entry_used = True - else: - # skip full entry - break - - if entry_used: - entries_used += 1 - - if entries_used == 40: - break - - return True - def modify(self, *mods): new_entries = [] start = time.time() - self.only_uppercase = self.detect_uppercase() - - if self.only_uppercase and self.debug: - logger.debug("Full-uppercase subtitle found") line_mods, non_line_mods, mods_used = self.prepare_mods(*mods) self.mods_used = mods_used diff --git a/libs/subzero/modification/mods/common.py b/libs/subzero/modification/mods/common.py index 3d16541bc..9a715f0c7 100644 --- a/libs/subzero/modification/mods/common.py +++ b/libs/subzero/modification/mods/common.py @@ -175,10 +175,35 @@ class FixUppercase(SubtitleModification): long_description = "Some subtitles are in all-uppercase letters. This at least makes them readable." + def detect_uppercase(self, parent): + entries_used = 0 + for entry in parent.f: + entry_used = False + for sub in entry.text.strip().split(r"\N"): + if sub.strip(): + alpha_sub = ''.join([i for i in sub if i.isalpha()]) + if alpha_sub and not alpha_sub.isupper(): + return False + + entry_used = True + else: + # skip full entry + break + + if entry_used: + entries_used += 1 + + if entries_used == 40: + break + + return True + def capitalize(self, c): return u"".join([s.capitalize() for s in split_upper_re.split(c)]) def modify(self, content, debug=False, parent=None, **kwargs): + if not self.detect_uppercase(parent): + return for entry in parent.f: entry.plaintext = self.capitalize(entry.plaintext)