fix: fix generating pdf with empty subtitles #10
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Problem:
When we have a video like https://www.youtube.com/watch?v=KN6OSdUfgyA with subtitles like
subtitles_8-old.txt, we get an exception thrown:
Cause:
This is because the subtitle file contains subtitle parts that has no content in it. For instance,
This causes the check of
self.parts[right_part_index].text[right_part_char_index]
to fail sinceright_part_index
is a valid index inself.parts
but since the text is empty and we first setright_part_char_index
to 0, it will causeself.parts[right_part_index].text[right_part_char_index]
to fail.Solution:
Each subtitle part needs to have some text. A subtitle part with no text is redundant. Hence, when we parse the subtitles, we need to remove the subtitle parts that have no text.
Manual Test:
python3 src/main.py tests/videos/input_8.mp4 -s tests/subtitles/subtitles_8.1.vrt -o output.pdf
. It did not crash, and it returned this PDF:output.pdf
tests/subtitles/subtitles_8.srt
is a better replacement for that video's subtitle. Running python3 src/main.py tests/videos/input_8.mp4 -s tests/subtitles/subtitles_8.srt -o output.pdf` produced this subtitle:output.pdf