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 = {
|
self.endpoints = {
|
||||||
"typeahead/artist": self.artist_typeahead_handler,
|
"typeahead/artist": self.artist_typeahead_handler,
|
||||||
"typeahead/song": self.song_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_cache_list": self.lyric_cache_list_handler,
|
||||||
"lyric_search_history": self.lyric_search_log_handler,
|
"lyric_search_history": self.lyric_search_log_handler,
|
||||||
"lyric_search_test": self.new_test,
|
"lyric_search_test": self.new_test,
|
||||||
@ -174,15 +175,18 @@ class LyricSearch(FastAPI):
|
|||||||
- **s**: song
|
- **s**: song
|
||||||
- **t**: track (artist and song combined) [used only if a & s are not used] [unused]
|
- **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]
|
- **extra**: include extra details in response [optional, default: false] [unused]
|
||||||
- **lrc**: Request LRCs? [unused]
|
- **lrc**: Request LRCs?
|
||||||
- **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional, default: none] [unused]
|
- **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 [unused]
|
- **src**: the script/utility which initiated the request
|
||||||
- **excluded_sources**: sources to exclude
|
- **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)
|
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
|
excluded_sources = data.excluded_sources
|
||||||
aggregate_search = aggregate.Aggregate(exclude_methods=excluded_sources)
|
aggregate_search = aggregate.Aggregate(exclude_methods=excluded_sources)
|
||||||
plain_lyrics = not data.lrc
|
plain_lyrics = not data.lrc
|
||||||
@ -193,6 +197,22 @@ class LyricSearch(FastAPI):
|
|||||||
'errorText': 'Sources exhausted, lyrics not located.',
|
'errorText': 'Sources exhausted, lyrics not located.',
|
||||||
}
|
}
|
||||||
result = result.dict()
|
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['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
|
||||||
result['confidence'] = f'{float(result.get('confidence', 0)):.2f}'
|
result['confidence'] = f'{float(result.get('confidence', 0)):.2f}'
|
||||||
result['time'] = f'{float(result['time']):.4f}'
|
result['time'] = f'{float(result['time']):.4f}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user