Increase rate limit for lighting state requests and enhance error handling for Cync device operations. Improve lyric search processing by splitting lyrics based on line breaks and cleaning special characters (bugfix for subsearch/seek).
This commit is contained in:
@@ -210,20 +210,20 @@ class LyricSearch(FastAPI):
|
||||
|
||||
if data.sub and not data.lrc:
|
||||
seeked_found_line: Optional[int] = None
|
||||
lyric_lines: list[str] = result["lyrics"].strip().split(" / ")
|
||||
# Split lyrics into lines based on <br> or newline characters
|
||||
lyrics_text = result["lyrics"].strip()
|
||||
if "<br>" in lyrics_text:
|
||||
lyric_lines = lyrics_text.split("<br>")
|
||||
else:
|
||||
lyric_lines = lyrics_text.split("\n")
|
||||
for i, line in enumerate(lyric_lines):
|
||||
line = regex.sub(r"\u2064", "", line.strip())
|
||||
if data.sub.strip().lower() in line.strip().lower():
|
||||
# Remove any special characters and extra spaces
|
||||
cleaned_line = regex.sub(r"\u2064", "", line.strip())
|
||||
if data.sub.strip().lower() in cleaned_line.lower():
|
||||
seeked_found_line = i
|
||||
logging.debug(
|
||||
"Found %s at %s, match for %s!",
|
||||
line,
|
||||
seeked_found_line,
|
||||
data.sub,
|
||||
) # REMOVEME: DEBUG
|
||||
break
|
||||
|
||||
if not seeked_found_line:
|
||||
if seeked_found_line is None:
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={
|
||||
@@ -232,7 +232,10 @@ class LyricSearch(FastAPI):
|
||||
"failed_seek": True,
|
||||
},
|
||||
)
|
||||
result["lyrics"] = " / ".join(lyric_lines[seeked_found_line:])
|
||||
# Only include lines strictly starting from the matched line
|
||||
# Use the same separator that was used to split
|
||||
separator = "<br>" if "<br>" in result["lyrics"] else "\n"
|
||||
result["lyrics"] = separator.join(lyric_lines[seeked_found_line:])
|
||||
|
||||
result["confidence"] = int(result["confidence"])
|
||||
result["time"] = f"{float(result['time']):.4f}"
|
||||
|
Reference in New Issue
Block a user