stoof
This commit is contained in:
parent
31c8f0ac04
commit
1c7a64bc58
@ -112,7 +112,8 @@ class LyricSearch(FastAPI):
|
|||||||
"IRC-KALI",
|
"IRC-KALI",
|
||||||
"DISC-ACES",
|
"DISC-ACES",
|
||||||
"DISC-HAVOC",
|
"DISC-HAVOC",
|
||||||
"IRC-SHARED"
|
"IRC-SHARED",
|
||||||
|
"LIMNORIA-SHARED",
|
||||||
]
|
]
|
||||||
|
|
||||||
self.lrc_regex = regex.compile(r'\[([0-9]{2}:[0-9]{2})\.[0-9]{1,3}\](\s(.*)){0,}')
|
self.lrc_regex = regex.compile(r'\[([0-9]{2}:[0-9]{2})\.[0-9]{1,3}\](\s(.*)){0,}')
|
||||||
@ -143,8 +144,8 @@ class LyricSearch(FastAPI):
|
|||||||
|
|
||||||
async def song_typeahead_handler(self, data: ValidTypeAheadRequest):
|
async def song_typeahead_handler(self, data: ValidTypeAheadRequest):
|
||||||
"""Song Type Ahead Handler"""
|
"""Song Type Ahead Handler"""
|
||||||
if not isinstance(data.pre_query, str) or len(data.pre_query) < 2\
|
if not isinstance(data.pre_query, str)\
|
||||||
or not isinstance(data.query, str) or len(data.query) < 2:
|
or not isinstance(data.query, str|None):
|
||||||
return {
|
return {
|
||||||
'err': True,
|
'err': True,
|
||||||
'errorText': 'Invalid request',
|
'errorText': 'Invalid request',
|
||||||
@ -183,7 +184,10 @@ class LyricSearch(FastAPI):
|
|||||||
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:
|
if data.src.upper() not in self.acceptable_request_sources:
|
||||||
raise HTTPException(detail="Invalid request", status_code=500)
|
return {
|
||||||
|
'err': True,
|
||||||
|
'errorText': f'Unknown request source: {data.src.upper()}',
|
||||||
|
}
|
||||||
|
|
||||||
search_artist: Optional[str] = data.a
|
search_artist: Optional[str] = data.a
|
||||||
search_song: Optional[str] = data.s
|
search_song: Optional[str] = data.s
|
||||||
|
@ -43,6 +43,8 @@ class Aggregate:
|
|||||||
sources: list = [cache_search,
|
sources: list = [cache_search,
|
||||||
lrclib_search,
|
lrclib_search,
|
||||||
genius_search]
|
genius_search]
|
||||||
|
if not plain:
|
||||||
|
sources = [lrclib_search] # Only LRCLib supported for synced lyrics
|
||||||
search_result: Optional[LyricsResult] = None
|
search_result: Optional[LyricsResult] = None
|
||||||
for source in sources:
|
for source in sources:
|
||||||
if source.label.lower() in self.exclude_methods:
|
if source.label.lower() in self.exclude_methods:
|
||||||
@ -53,6 +55,7 @@ class Aggregate:
|
|||||||
if plain:
|
if plain:
|
||||||
logging.info("Skipping source: %s, excluded.", source.label)
|
logging.info("Skipping source: %s, excluded.", source.label)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
search_result = await source.search(artist=artist, song=song,
|
search_result = await source.search(artist=artist, song=song,
|
||||||
plain=plain)
|
plain=plain)
|
||||||
if search_result:
|
if search_result:
|
||||||
|
@ -8,6 +8,7 @@ import traceback
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import regex
|
||||||
sys.path.insert(1,'..')
|
sys.path.insert(1,'..')
|
||||||
from lyric_search_new import notifier
|
from lyric_search_new import notifier
|
||||||
from lyric_search_new.constructors import LyricsResult
|
from lyric_search_new.constructors import LyricsResult
|
||||||
@ -21,6 +22,7 @@ from . import private
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
log_level = logging.getLevelName(logger.level)
|
log_level = logging.getLevelName(logger.level)
|
||||||
|
|
||||||
@ -38,6 +40,10 @@ class RedisCache:
|
|||||||
self.redis_client = redis.Redis(password=private.REDIS_PW)
|
self.redis_client = redis.Redis(password=private.REDIS_PW)
|
||||||
self.notifier = notifier.DiscordNotifier()
|
self.notifier = notifier.DiscordNotifier()
|
||||||
self.notify_warnings = True
|
self.notify_warnings = True
|
||||||
|
self.regexes = [
|
||||||
|
regex.compile(r'\-'),
|
||||||
|
regex.compile(r'[^a-zA-Z0-9\s]'),
|
||||||
|
]
|
||||||
|
|
||||||
async def create_index(self) -> None:
|
async def create_index(self) -> None:
|
||||||
"""Create Index"""
|
"""Create Index"""
|
||||||
@ -54,6 +60,24 @@ class RedisCache:
|
|||||||
raise RedisException(f"Redis: Failed to create index: {result}")
|
raise RedisException(f"Redis: Failed to create index: {result}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await self.notifier.send(f"ERROR @ {__file__}", f"Failed to create idx: {str(e)}")
|
await self.notifier.send(f"ERROR @ {__file__}", f"Failed to create idx: {str(e)}")
|
||||||
|
|
||||||
|
def sanitize_input(self, artist: str, song: str) -> tuple[str, str]:
|
||||||
|
"""
|
||||||
|
Sanitize artist/song input (convert to redis matchable fuzzy query)
|
||||||
|
Args:
|
||||||
|
artist: Input artist
|
||||||
|
song: Input song
|
||||||
|
Returns:
|
||||||
|
tuple[str, str]: Tuple containing the 2 output strings (artist, song)
|
||||||
|
"""
|
||||||
|
artist = self.regexes[0].sub(" ", artist)
|
||||||
|
artist = self.regexes[1].sub("", artist).strip()
|
||||||
|
song = self.regexes[0].sub(" ", song)
|
||||||
|
song = self.regexes[1].sub("", song).strip()
|
||||||
|
artist = " ".join([f"(%{artist_word}%)" for artist_word in artist.split(" ")])
|
||||||
|
song = "".join([f"(%{song_word}%)" for song_word in song.split(" ")])
|
||||||
|
return (artist, song)
|
||||||
|
|
||||||
|
|
||||||
async def search(self, **kwargs) -> list[tuple]:
|
async def search(self, **kwargs) -> list[tuple]:
|
||||||
"""
|
"""
|
||||||
@ -77,11 +101,15 @@ class RedisCache:
|
|||||||
raise RedisException("Lyric search not yet implemented")
|
raise RedisException("Lyric search not yet implemented")
|
||||||
|
|
||||||
if not is_random_search:
|
if not is_random_search:
|
||||||
artist = artist.replace("-", " ")
|
(artist, song) = self.sanitize_input(artist=artist,
|
||||||
song = song.replace("-", " ")
|
song=song)
|
||||||
search_res = await self.redis_client.ft().search(
|
search_res = await self.redis_client.ft().search(Query(
|
||||||
Query(f"@artist:{artist} @song:{song}"
|
f"@artist:{artist} @song:{song}"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
search_res_out = [(result['id'].split(":",
|
search_res_out = [(result['id'].split(":",
|
||||||
maxsplit=1)[1], dict(json.loads(result['json'])))
|
maxsplit=1)[1], dict(json.loads(result['json'])))
|
||||||
for result in search_res.docs]
|
for result in search_res.docs]
|
||||||
|
@ -140,7 +140,7 @@ class DataUtils:
|
|||||||
if not reg_helper[1].strip():
|
if not reg_helper[1].strip():
|
||||||
_words = "♪"
|
_words = "♪"
|
||||||
else:
|
else:
|
||||||
_words = reg_helper[1]
|
_words = reg_helper[1].strip()
|
||||||
lrc_out.append({
|
lrc_out.append({
|
||||||
"timeTag": _timetag,
|
"timeTag": _timetag,
|
||||||
"words": _words,
|
"words": _words,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user