Skip to content

Commit

Permalink
Clean up code based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
sontek committed Sep 24, 2019
1 parent 43d6b93 commit 4bf3fe2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/webvtt_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_parse_captions_with_bom(self):
vtt = webvtt.read(self._get_file('captions_with_bom.vtt'))
self.assertEqual(len(vtt.captions), 4)

def test_can_parse_empty_lines_from_netflix_subtitles(self):
def test_empty_lines_are_not_included_in_result(self):
vtt = webvtt.read(self._get_file('netflix_chicas_del_cable.vtt'))
self.assertEqual(vtt.captions[0].text, "[Alba] En 1928,")
self.assertEqual(
Expand Down
10 changes: 5 additions & 5 deletions webvtt/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,16 @@ def _compute_blocks(self, lines):
blocks = []

for index, line in enumerate(lines, start=1):
# clean up exstraneous whitespace
final_line = line.strip()

# Remove empty lines
if line and line.strip():
if final_line:
if not blocks:
blocks.append(Block(index))
if not blocks[-1].lines:
blocks[-1].line_number = index
blocks[-1].lines.append(line)
blocks[-1].lines.append(final_line)
else:
blocks.append(Block(index))

Expand Down Expand Up @@ -194,9 +197,6 @@ def _parse(self, lines):
self._compute_blocks(lines)

for block in self.blocks:
# skip empty blocks
if self._is_empty(block):
continue
if self._is_cue_block(block):
caption = self._parse_cue_block(block)
self.captions.append(caption)
Expand Down

0 comments on commit 4bf3fe2

Please sign in to comment.