add subsearch support to new lyric search endpoint
This commit is contained in:
parent
bb0432c5a0
commit
f173edb5f4
@ -99,7 +99,8 @@ class LyricSearch(FastAPI):
|
||||
self.endpoints = {
|
||||
"typeahead/artist": self.artist_typeahead_handler,
|
||||
"typeahead/song": self.song_typeahead_handler,
|
||||
"lyric_search": self.lyric_search_handler,
|
||||
# "lyric_search": self.lyric_search_handler,
|
||||
"lyric_search": self.new_test, #test
|
||||
"lyric_cache_list": self.lyric_cache_list_handler,
|
||||
"lyric_search_history": self.lyric_search_log_handler,
|
||||
"lyric_search_test": self.new_test,
|
||||
@ -174,13 +175,16 @@ class LyricSearch(FastAPI):
|
||||
- **s**: song
|
||||
- **t**: track (artist and song combined) [used only if a & s are not used] [unused]
|
||||
- **extra**: include extra details in response [optional, default: false] [unused]
|
||||
- **lrc**: Request LRCs? [unused]
|
||||
- **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional, default: none] [unused]
|
||||
- **src**: the script/utility which initiated the request [unused]
|
||||
- **lrc**: Request LRCs?
|
||||
- **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional, default: none]
|
||||
- **src**: the script/utility which initiated the request
|
||||
- **excluded_sources**: sources to exclude
|
||||
"""
|
||||
|
||||
if not data.a or not data.s:
|
||||
if not data.a or not data.s or not data.src:
|
||||
raise HTTPException(detail="Invalid request", status_code=500)
|
||||
|
||||
if data.src.upper() not in self.acceptable_request_sources:
|
||||
raise HTTPException(detail="Invalid request", status_code=500)
|
||||
|
||||
excluded_sources = data.excluded_sources
|
||||
@ -193,6 +197,22 @@ class LyricSearch(FastAPI):
|
||||
'errorText': 'Sources exhausted, lyrics not located.',
|
||||
}
|
||||
result = result.dict()
|
||||
lyric_lines = result['lyrics'].strip().split(" / ")
|
||||
if data.sub:
|
||||
for i, line in enumerate(lyric_lines):
|
||||
line = regex.sub(r'\u2064', '', line.strip())
|
||||
if data.sub.strip().lower() in line.strip().lower():
|
||||
seeked_found_line = i
|
||||
logging.debug("Found %s at %s, match for %s!",
|
||||
line, seeked_found_line, data.sub) # REMOVEME: DEBUG
|
||||
break
|
||||
|
||||
if seeked_found_line is None:
|
||||
return {
|
||||
'failed_seek': True,
|
||||
}
|
||||
result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:])
|
||||
|
||||
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
|
||||
result['confidence'] = f'{float(result.get('confidence', 0)):.2f}'
|
||||
result['time'] = f'{float(result['time']):.4f}'
|
||||
|
Loading…
x
Reference in New Issue
Block a user