Skip to content

Commit

Permalink
Test unicode subtitles (Zulko#1431)
Browse files Browse the repository at this point in the history
* Test unicode subtitles

* Edit path to subtitles file in test

* Fix errors in test
  • Loading branch information
mondeja authored Jan 15, 2021
1 parent df62fcd commit 737ac0c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions media/subtitles-unicode.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0
00:00:00,000 --> 00:00:05,000
ÁÉíöÙ

File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_PR.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def make_textclip(txt):
stroke_width=0.5,
)

SubtitlesClip(Path("media/subtitles1.srt"), make_textclip=make_textclip).close()
SubtitlesClip(Path("media/subtitles.srt"), make_textclip=make_textclip).close()


if __name__ == "__main__":
Expand Down
50 changes: 26 additions & 24 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
from tests.test_helper import FONT, TMP_DIR


MEDIA_SUBTITLES_DATA = [
([0.0, 4.0], "Red!"),
([5.0, 9.0], "More Red!"),
([10.0, 14.0], "Green!"),
([15.0, 19.0], "More Green!"),
([20.0, 24.0], "Blue"),
([25.0, 29.0], "More Blue!"),
]

MEDIA_SUBTITLES_UNICODE_DATA = [
([0, 5.0], "ÁÉíöÙ"),
]


def test_cuts1():
clip = VideoFileClip("media/big_buck_bunny_432_433.webm").resize(0.2)
cuts.find_video_period(clip) == pytest.approx(0.966666666667, 0.0001)
Expand All @@ -36,37 +50,25 @@ def test_subtitles():
color="white",
)

subtitles = SubtitlesClip("media/subtitles1.srt", generator)
subtitles = SubtitlesClip("media/subtitles.srt", generator)
final = CompositeVideoClip([myvideo, subtitles])
final.write_videofile(os.path.join(TMP_DIR, "subtitles1.mp4"), fps=30)

data = [
([0.0, 4.0], "Red!"),
([5.0, 9.0], "More Red!"),
([10.0, 14.0], "Green!"),
([15.0, 19.0], "More Green!"),
([20.0, 24.0], "Blue"),
([25.0, 29.0], "More Blue!"),
]
final.write_videofile(os.path.join(TMP_DIR, "subtitles.mp4"), fps=30)

assert subtitles.subtitles == data
assert subtitles.subtitles == MEDIA_SUBTITLES_DATA

subtitles = SubtitlesClip(data, generator)
assert subtitles.subtitles == data
subtitles = SubtitlesClip(MEDIA_SUBTITLES_DATA, generator)
assert subtitles.subtitles == MEDIA_SUBTITLES_DATA
close_all_clips(locals())


def test_file_to_subtitles():
data = [
([0.0, 4.0], "Red!"),
([5.0, 9.0], "More Red!"),
([10.0, 14.0], "Green!"),
([15.0, 19.0], "More Green!"),
([20.0, 24.0], "Blue"),
([25.0, 29.0], "More Blue!"),
]

assert data == file_to_subtitles("media/subtitles1.srt")
assert MEDIA_SUBTITLES_DATA == file_to_subtitles("media/subtitles.srt")


def test_file_to_subtitles_unicode():
assert MEDIA_SUBTITLES_UNICODE_DATA == file_to_subtitles(
"media/subtitles-unicode.srt", encoding="utf-8"
)


if __name__ == "__main__":
Expand Down

0 comments on commit 737ac0c

Please sign in to comment.