Skip to content

Commit

Permalink
fix to author names filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lyon committed Nov 21, 2020
1 parent eee715a commit 0d291ae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ subs.filter(
rm_author=False,
)
```

### Issues

If you spot any issues with the filtered subtitles, or would like to request new features, please create an issue on GitHub.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os import path
from setuptools import setup

version = '1.3.0'
version = '1.3.1'
this_dir = path.abspath(path.dirname(__file__))
with open(path.join(this_dir, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
Expand Down
6 changes: 3 additions & 3 deletions subtitle_filter/libs/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def remove_sound_effects(self):
def replace_names(self):
'''Replace names in all caps with dashes'''
names = []
names.extend(re.findall(r'([A-Z]+ *: *|[A-Z]{1}[a-z]+: *)', self._contents))
names.extend(re.findall(r'([A-Z ]+ *: *|[A-Z]{1}[a-z]+: *)', self._contents))
if len(names) > 1:
# Replace names with '- '
self._contents = re.sub(r'([A-Z]+ *: *|[A-Z]{1}[a-z]+: *)', '- ', self._contents).lstrip()
self._contents = re.sub(r'([A-Z ]+ *: *|[A-Z]{1}[a-z]+: *)', '- ', self._contents).lstrip()
else:
# Replace name with empty string.
self._contents = re.sub(r'([A-Z]+ *:|[A-Z]{1}[a-z]+: *)', '', self._contents).lstrip()
self._contents = re.sub(r'([A-Z ]+ *:|[A-Z]{1}[a-z]+: *)', '', self._contents).lstrip()
self._filter_empty()

def remove_author(self):
Expand Down
6 changes: 5 additions & 1 deletion tests/data/subtitle_names_after.srt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ Gooby pls...

4
00:03:06,139 --> 00:03:07,639
Heres what you need: an egg.
Heres what you need: an egg.

5
00:00:05,377 --> 00:00:06,378
No.
10 changes: 7 additions & 3 deletions tests/data/subtitle_names_before.srt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2
1
00:01:40,723 --> 00:01:42,707
ELLIOT: It's almost as if...
JOE: Yes?
Expand All @@ -7,12 +7,16 @@ JOE: Yes?
00:01:40,723 --> 00:01:42,707
ELLIOT: Gooby pls...

16
17
00:03:06,139 --> 00:03:07,639
Bartender:
<i> You're gonna need</i>
<i> most of that</i>

16
60
00:03:06,139 --> 00:03:07,639
Heres what you need: an egg.

5
00:00:05,377 --> 00:00:06,378
THE FOOBAR: No.

0 comments on commit 0d291ae

Please sign in to comment.