Files
unshackle/tests/core/test_music_lyrics.py
T

73 lines
2.0 KiB
Python

"""The shared lyric helpers; each expected value is recorded from the service copies that they replace."""
import pytest
from unshackle.core.music import cues_to_lrc, cues_to_srt, lrc_stamp, lrc_to_cues
LRC = (
"[00:05.00]third line\r\n"
"[00:01.00] first line \n"
"[00:02.50]\n"
"not a lyric line\n"
"[00:01.80]second line\n"
" [00:03.00]indented \n"
"[00:04.001]inexact\n"
"[00:20]no fraction, gap\n"
"[00:30.00]same start\n"
"[00:30.00]same start again\n"
"[120:00.125]over ninety-nine minutes\n"
)
CUES = [
(1000, 1800, "first line"),
(1800, 2500, "second line"),
(3000, 4001, "indented"),
(4001, 5000, "inexact"),
(5000, 8500, "third line"),
(20000, 23500, "no fraction, gap"),
(30000, 33000, "same start"),
(30000, 33500, "same start again"),
(7200125, 7203125, "over ninety-nine minutes"),
]
@pytest.mark.parametrize(
("ms", "stamp"),
[
(0, "00:00.00"),
(-1, "00:00.00"),
(-5000, "00:00.00"),
(5, "00:00.00"),
(15, "00:00.02"),
(25, "00:00.02"),
(995, "00:01.00"),
(59994, "00:59.99"),
(59995, "01:00.00"),
(59996, "01:00.00"),
(60000, "01:00.00"),
(3599990, "59:59.99"),
(5999994, "99:59.99"),
(5999996, "100:00.00"),
(123456789, "2057:36.79"),
],
)
def test_lrc_stamp(ms: int, stamp: str) -> None:
assert lrc_stamp(ms) == stamp
def test_cues_to_lrc() -> None:
cues = [(-20, 0, "before zero"), (0, 3000, "first"), (59996, 62000, "one minute"), (6000000, 6003000, "hundred")]
assert cues_to_lrc(cues) == "[00:00.00]before zero\n[00:00.00]first\n[01:00.00]one minute\n[100:00.00]hundred"
assert cues_to_lrc([]) == ""
def test_lrc_to_cues() -> None:
assert lrc_to_cues(LRC) == CUES
assert lrc_to_cues("") == []
def test_cues_to_srt() -> None:
assert cues_to_srt(CUES[:2]) == (
"1\n00:00:01,000 --> 00:00:01,800\nfirst line\n\n2\n00:00:01,800 --> 00:00:02,500\nsecond line\n\n"
)
assert cues_to_srt([]) == ""