This commit is contained in:
codey 2025-01-14 07:45:34 -05:00
parent ff04602954
commit 7a63b6525d
7 changed files with 22 additions and 9 deletions

View File

@ -123,7 +123,9 @@ class LyricSearch(FastAPI):
aggregate_search = aggregate.Aggregate()
result = await aggregate_search.search(data.a, data.s)
return result.dict()
result = result.dict()
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
return result

View File

@ -0,0 +1,2 @@
"""
"""

View File

@ -8,6 +8,7 @@ sys.path.insert(1,'..')
sys.path.insert(1,'..')
from . import cache
from . import genius
class Aggregate:
"""Aggregate all source methods"""

View File

@ -1,12 +1,12 @@
#!/usr/bin/env python3.12
# pylint: disable=wrong-import-position
import os
import sys
sys.path.insert(1,'..')
import aiosqlite as sqlite3
sys.path.insert(1,'.')
from typing import Optional
from . import private
from . import common
import aiosqlite as sqlite3
from lyric_search_new import utils
from lyric_search_new.constructors import LyricsResult
@ -21,6 +21,7 @@ class Cache:
self.sqlite_exts = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
def get_matched(self, sqlite_rows, matched_candidate, confidence) -> Optional[LyricsResult]:
"""Get Matched Result"""
matched_id = matched_candidate[0]
for row in sqlite_rows:
if row[0] == matched_id:
@ -40,6 +41,8 @@ class Cache:
Returns:
- LyricsResult corresponding to nearest match found (if found), **None** otherwise
"""
artist = artist.strip().lower()
song = song.strip().lower()
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
await db_conn.enable_load_extension(True)
for ext in self.sqlite_exts:
@ -47,7 +50,9 @@ class Cache:
async with await db_conn.executescript(self.cache_pre_query) as _db_cursor:
search_query = 'SELECT id, artist, song, lyrics, src, confidence FROM lyrics WHERE editdist3((artist || " " || song), (? || " " || ?))\
<= 410 ORDER BY editdist3((artist || " " || song), ?) ASC LIMIT 10'
async with await _db_cursor.execute(search_query, (artist.strip(), song.strip(), f"{artist.strip()} {song.strip()}")) as db_cursor:
search_params = (artist.strip(), song.strip(),
f"{artist.strip()} {song.strip()}")
async with await _db_cursor.execute(search_query, search_params) as db_cursor:
results = await db_cursor.fetchall()
result_tracks = []
for track in results:

View File

@ -33,6 +33,8 @@ class Genius:
@song: the song to search
"""
try:
artist = artist.strip().lower()
song = song.strip().lower()
search_term = f'{artist}%20{song}'
returned_lyrics = ''
async with ClientSession() as client:

View File

@ -3,8 +3,8 @@
import asyncio
import sys
sys.path.insert(1, '.')
import sources.cache, sources.genius, sources.aggregate
import utils
test_artist = "hopsin"
test_song = "ill mind of hopsin 5"
@ -39,6 +39,6 @@ async def test_aggregate(artist=None, song=None):
loop = asyncio.new_event_loop()
loop.run_until_complete(test_genius())
# loop.run_until_complete(test_genius())
loop.run_until_complete(test_cache(artist=test_artist, song=test_song))
loop.run_until_complete(test_aggregate())
# loop.run_until_complete(test_aggregate())

View File

@ -63,7 +63,8 @@ class TrackMatcher:
extra spaces, and converting to lowercase.
"""
# Remove special characters and convert to lowercase
text = regex.sub(r'[^\w\s-]', '', text.lower())
text = regex.sub(r'[^\w\s-]', '', text).lower()
print(f"Text: {text}")
# Normalize spaces
text = ' '.join(text.split())
return text