Skip to content

Commit

Permalink
fix: trim leading & trailing whitespace from output (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Jan 2, 2022
1 parent 36e77af commit 4030941
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "GPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion subclean/core/section/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions subclean/processors/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def is_music(line: Line) -> bool:
def contains_hi(line: Line) -> bool:
return bool(
re.search(
r"^([-‐\s<i>]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<i>)?([\s])*|\s?[(\[*].*?[)\]*:]+\s?",
r"^([-‐\s<i>]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<\/?i>)?([\s])*|\s?[(\[*].*?[)\]*:]+\s?",
line,
)
)
Expand All @@ -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<i>]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<i>)?([\s])*",
r"^([-‐\s<i>]+)?((\b[-A-Za-z.']+\s?#?\d?){1,2}(?!\.)([\[(][\w\s]*[\])])?:(?!\w)|[\[]+.*[\]:]+)(<\/?i>)?([\s])*",
r"\1\5",
)
line = cls.clean_parentheses(line)
Expand Down
10 changes: 5 additions & 5 deletions tests/subs/American.Horror.Stories.S01E01.ref.srt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/subs/Yellowjackets.S01E08.ref.srt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

6
00:00:13,555 --> 00:00:14,931
<i>I know I don't have to come with you.</i>
<i>I know I don't have to come with you.</i>

7
00:00:14,973 --> 00:00:16,182
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sdhprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<i>[Laura]</i> <i>sentence</i>"))
== "<i></i> <i>sentence</i>"
== "<i></i><i>sentence</i>"
)
assert (
fake_processor.clean_hi(Line("- CHRISTOPHER:<i> Hello?</i>"))
Expand Down

0 comments on commit 4030941

Please sign in to comment.