lrc tweaks

This commit is contained in:
2025-01-17 07:48:29 -05:00
parent 76182e3df1
commit 7899fc2d71
5 changed files with 66 additions and 13 deletions

View File

@ -191,14 +191,17 @@ class LyricSearch(FastAPI):
aggregate_search = aggregate.Aggregate(exclude_methods=excluded_sources)
plain_lyrics = not data.lrc
result = await aggregate_search.search(data.a, data.s, plain_lyrics)
if not result:
return {
'err': True,
'errorText': 'Sources exhausted, lyrics not located.',
}
result = result.dict()
lyric_lines = result['lyrics'].strip().split(" / ")
if data.sub:
result = result.todict()
if data.sub and not data.lrc:
lyric_lines = result['lyrics'].strip().split(" / ")
for i, line in enumerate(lyric_lines):
line = regex.sub(r'\u2064', '', line.strip())
if data.sub.strip().lower() in line.strip().lower():
@ -213,9 +216,18 @@ class LyricSearch(FastAPI):
}
result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:])
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
result['confidence'] = int(result.get('confidence', 0))
result['time'] = f'{float(result['time']):.4f}'
if plain_lyrics:
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
else:
# Swap lyrics key for 'lrc'
logging.info("lyrics: %s, type: %s",
result['lyrics'], type(result['lyrics']))
result['lrc'] = result['lyrics']
result.pop('lyrics')
if "cached" in result['src']:
result['from_cache'] = True