Skip to content

Commit

Permalink
Add checking in case lyrics has translation along
Browse files Browse the repository at this point in the history
  • Loading branch information
moehmeni committed May 24, 2024
1 parent 3cf97f5 commit ccd45fb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions syncedlyrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ccd45fb

Please sign in to comment.