Skip to content

Commit

Permalink
Merge pull request #341 from dsavinov-actionengine/fixes_vtt
Browse files Browse the repository at this point in the history
Fix VTT issues
  • Loading branch information
kbairak authored Jul 12, 2024
2 parents 385d505 + efc48b2 commit 3c12d4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 5 additions & 4 deletions openformats/formats/vtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def parse(self, content, **kwargs):
self.transcriber.copy_until(len(source))

template = self.transcriber.get_destination()
if not template.startswith("WEBVTT"):
if len(stringset) == 0:
raise ParseError("There are no strings to translate")
elif not template.startswith("WEBVTT"):
raise ParseError("VTT file should start with 'WEBVTT'!")
return template, stringset

Expand Down Expand Up @@ -102,9 +104,8 @@ def _parse_section(self, offset, section):
# Content
string_to_translate = "\n".join(src_strings[timings_index + 1 :])
if string_to_translate == "":
raise ParseError(
f"Subtitle is empty on line {self.transcriber.line_number + 2}"
)
# Do not include an empty subtitle in the stringset
return None, None

string = OpenString(
timings,
Expand Down
7 changes: 2 additions & 5 deletions openformats/tests/formats/vtt/test_vtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ def test_vtt_occurrences(self):
_, stringset = self.handler.parse(source)
self.assertEqual(stringset[0].occurrences, '00:01:28.797,00:01:30.297')

def test_missing_string(self):
def test_empty_subtitle(self):
source = strip_leading_spaces("""WEBVTT
1
00:01:28.797 --> 00:01:30.297
""")
self._test_parse_error(
source,
"Subtitle is empty on line 5"
)
self._test_parse_error(source, "There are no strings to translate")

def test_full_and_short_timings(self):
source = strip_leading_spaces("""WEBVTT
Expand Down

0 comments on commit 3c12d4d

Please sign in to comment.