From 40309412fb534b2c962540d8e35b9c56b7dfa39c Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Sun, 2 Jan 2022 14:26:41 +0100 Subject: [PATCH] fix: trim leading & trailing whitespace from output (#110) --- pyproject.toml | 2 +- subclean/core/section/__init__.py | 2 +- subclean/processors/processor.py | 4 ++-- tests/subs/American.Horror.Stories.S01E01.ref.srt | 10 +++++----- tests/subs/Yellowjackets.S01E08.ref.srt | 2 +- tests/test_sdhprocessor.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 084cb5e..b5190d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "subclean" -version = "0.3.5" +version = "0.3.6" description = "Simple CLI tool to instantly enhance your movie & TV show subtitles." authors = ["disrupted "] license = "GPL-3.0" diff --git a/subclean/core/section/__init__.py b/subclean/core/section/__init__.py index c3c3994..98b5055 100644 --- a/subclean/core/section/__init__.py +++ b/subclean/core/section/__init__.py @@ -44,4 +44,4 @@ def __init__(self, timing: SrtSectionTiming, lines: list[Line] | None = None): super().__init__(timing, lines) def __str__(self) -> str: - return f"{self.timing}\n{self.content()}\n" + return f"{self.timing}\n{self.content().strip()}\n" diff --git a/subclean/processors/processor.py b/subclean/processors/processor.py index fc2a631..ec36a53 100644 --- a/subclean/processors/processor.py +++ b/subclean/processors/processor.py @@ -110,7 +110,7 @@ def is_music(line: Line) -> bool: def contains_hi(line: Line) -> bool: return bool( re.search( - r"^([-‐\s]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)()?([\s])*|\s?[(\[*].*?[)\]*:]+\s?", + r"^([-‐\s]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<\/?i>)?([\s])*|\s?[(\[*].*?[)\]*:]+\s?", line, ) ) @@ -119,7 +119,7 @@ def contains_hi(line: Line) -> bool: def clean_hi(cls, line: Line) -> Line: """Clean hearing impaired.""" line = line.sub( - r"^([-‐\s]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)()?([\s])*", + r"^([-‐\s]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<\/?i>)?([\s])*", r"\1\5", ) line = cls.clean_parentheses(line) diff --git a/tests/subs/American.Horror.Stories.S01E01.ref.srt b/tests/subs/American.Horror.Stories.S01E01.ref.srt index 57c24b6..9ac2565 100644 --- a/tests/subs/American.Horror.Stories.S01E01.ref.srt +++ b/tests/subs/American.Horror.Stories.S01E01.ref.srt @@ -702,7 +702,7 @@ I got his other hand here. 166 00:15:47,470 --> 00:15:48,740 - Hey. +Hey. 167 00:15:48,773 --> 00:15:51,245 @@ -1260,7 +1260,7 @@ I will not be talking to you for weeks. 297 00:23:18,840 --> 00:23:20,009 - Just let me... +Just let me... 298 00:23:39,147 --> 00:23:42,053 @@ -1736,11 +1736,11 @@ Hello? 410 00:28:49,835 --> 00:28:51,839 - You are going to die in there. +You are going to die in there. 411 00:29:22,801 --> 00:29:24,003 - The fuck? +The fuck? 412 00:29:40,570 --> 00:29:43,375 @@ -1831,7 +1831,7 @@ good sense and determination. 433 00:31:13,354 --> 00:31:15,425 - Dad. +Dad. 434 00:31:15,459 --> 00:31:17,296 diff --git a/tests/subs/Yellowjackets.S01E08.ref.srt b/tests/subs/Yellowjackets.S01E08.ref.srt index 2a443e5..95c249d 100644 --- a/tests/subs/Yellowjackets.S01E08.ref.srt +++ b/tests/subs/Yellowjackets.S01E08.ref.srt @@ -20,7 +20,7 @@ 6 00:00:13,555 --> 00:00:14,931 - I know I don't have to come with you. +I know I don't have to come with you. 7 00:00:14,973 --> 00:00:16,182 diff --git a/tests/test_sdhprocessor.py b/tests/test_sdhprocessor.py index 221ac3b..42428fa 100644 --- a/tests/test_sdhprocessor.py +++ b/tests/test_sdhprocessor.py @@ -55,7 +55,7 @@ def test_clean_hi(self, fake_processor: SDHProcessor): assert fake_processor.clean_hi(Line("[Laura] sentence")) == "sentence" assert ( fake_processor.clean_hi(Line("[Laura] sentence")) - == " sentence" + == "sentence" ) assert ( fake_processor.clean_hi(Line("- CHRISTOPHER: Hello?"))