lyric.py 380 Bytes
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)