From ccd45fb9af93e023e9ed71f423f7dfc8c784a831 Mon Sep 17 00:00:00 2001 From: Mohammad Momeni Date: Fri, 24 May 2024 13:36:41 +0200 Subject: [PATCH] Add checking in case lyrics has translation along --- syncedlyrics/utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/syncedlyrics/utils.py b/syncedlyrics/utils.py index 0e5b8b5..2116b02 100644 --- a/syncedlyrics/utils.py +++ b/syncedlyrics/utils.py @@ -9,14 +9,24 @@ R_FEAT = re.compile(r"\((feat.+)\)", re.IGNORECASE) -def is_lrc_valid(lrc: str, allow_plain_format: bool = False) -> bool: +def is_lrc_valid( + lrc: str, allow_plain_format: bool = False, check_translation: bool = False +) -> bool: """Checks whether a given LRC string is valid or not.""" if not lrc: return False + lines = lrc.split("\n")[5:10] if not allow_plain_format: - conds = ["[" in l for l in lrc.split("\n")[5:8]] - return all(conds) - + if not check_translation: + conds = ["[" in l for l in lrc.split("\n")[5:10]] + return all(conds) + else: + for i, line in enumerate(lines): + if "[" in line: + if i + 1 < len(lines): + next_line = lines[i + 1] + if "(" not in next_line: + return False return True