forked from kenzuya/unshackle
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""The shared lyric helpers; each expected value is recorded from the service copies that they replace."""
|
|
|
|
from unshackle.core.music import cues_to_lrc, cues_to_srt, 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"),
|
|
]
|
|
|
|
|
|
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([]) == ""
|