lyric.py 370 Bytes Raw Blame History Permalink 1 2 3 4 5 6 7 8 9 def ensure_newlines(text: str | None) -> str: """确保歌词每行之间有换行符,保留时间戳等原始内容""" if not text: return '' # 将字面量 \\n / \\r 转为真正换行符 text = text.replace('\\n', '\n').replace('\\r', '') lines = [line.strip() for line in text.splitlines() if line.strip()] return '\n'.join(lines)