Commit d17b5206 d17b52065a8dec1c261851b43e21639162d3cbf0 by 沈秋雨

feat(etl): 实现 LRC 时间戳去除

1 parent 22f7456f
import re
_TIMESTAMP_RE = re.compile(r'\[\d{2}:\d{2}\.\d{2,3}\]')
_META_TAG_RE = re.compile(r'\[[a-zA-Z]+:[^\]]*\]')
def strip_timestamps(text: str | None) -> str:
if not text:
return ''
text = _META_TAG_RE.sub('', text)
text = _TIMESTAMP_RE.sub('', text)
lines = [line.strip() for line in text.splitlines() if line.strip()]
return '\n'.join(lines)
File mode changed
from etl_to_crawler.lyric import strip_timestamps
def test_strips_standard_timestamps():
lrc = "[00:12.34]第一行歌词\n[01:23.45]第二行歌词"
assert strip_timestamps(lrc) == "第一行歌词\n第二行歌词"
def test_strips_millisecond_timestamps():
lrc = "[00:12.345]带三位毫秒"
assert strip_timestamps(lrc) == "带三位毫秒"
def test_strips_meta_tags():
lrc = "[ti:歌曲名]\n[ar:歌手]\n[00:01.00]歌词"
result = strip_timestamps(lrc)
assert "歌词" in result
assert "[ti:" not in result
def test_empty_and_none():
assert strip_timestamps(None) == ''
assert strip_timestamps('') == ''
def test_plain_text_unchanged():
assert strip_timestamps("没有时间戳的歌词") == "没有时间戳的歌词"