Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VTT issues #341

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented issue 6 from QA spreadsheet: system should fail if source content consists of only WEBVTT signature

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}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented issue 3 from QA spreadsheet: system should allow uploading (parsing) even if some subtitles are empty

)
# 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
Loading