stoof
This commit is contained in:
parent
ff04602954
commit
7a63b6525d
@ -123,7 +123,9 @@ class LyricSearch(FastAPI):
|
|||||||
|
|
||||||
aggregate_search = aggregate.Aggregate()
|
aggregate_search = aggregate.Aggregate()
|
||||||
result = await aggregate_search.search(data.a, data.s)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
"""
|
||||||
|
"""
|
@ -8,6 +8,7 @@ sys.path.insert(1,'..')
|
|||||||
sys.path.insert(1,'..')
|
sys.path.insert(1,'..')
|
||||||
from . import cache
|
from . import cache
|
||||||
from . import genius
|
from . import genius
|
||||||
|
|
||||||
class Aggregate:
|
class Aggregate:
|
||||||
"""Aggregate all source methods"""
|
"""Aggregate all source methods"""
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env python3.12
|
#!/usr/bin/env python3.12
|
||||||
|
# pylint: disable=wrong-import-position
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(1,'..')
|
sys.path.insert(1,'..')
|
||||||
import aiosqlite as sqlite3
|
sys.path.insert(1,'.')
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from . import private
|
import aiosqlite as sqlite3
|
||||||
from . import common
|
|
||||||
from lyric_search_new import utils
|
from lyric_search_new import utils
|
||||||
from lyric_search_new.constructors import LyricsResult
|
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']
|
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]:
|
def get_matched(self, sqlite_rows, matched_candidate, confidence) -> Optional[LyricsResult]:
|
||||||
|
"""Get Matched Result"""
|
||||||
matched_id = matched_candidate[0]
|
matched_id = matched_candidate[0]
|
||||||
for row in sqlite_rows:
|
for row in sqlite_rows:
|
||||||
if row[0] == matched_id:
|
if row[0] == matched_id:
|
||||||
@ -40,6 +41,8 @@ class Cache:
|
|||||||
Returns:
|
Returns:
|
||||||
- LyricsResult corresponding to nearest match found (if found), **None** otherwise
|
- 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:
|
async with sqlite3.connect(self.cache_db, timeout=2) as db_conn:
|
||||||
await db_conn.enable_load_extension(True)
|
await db_conn.enable_load_extension(True)
|
||||||
for ext in self.sqlite_exts:
|
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:
|
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), (? || " " || ?))\
|
search_query = 'SELECT id, artist, song, lyrics, src, confidence FROM lyrics WHERE editdist3((artist || " " || song), (? || " " || ?))\
|
||||||
<= 410 ORDER BY editdist3((artist || " " || song), ?) ASC LIMIT 10'
|
<= 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()
|
results = await db_cursor.fetchall()
|
||||||
result_tracks = []
|
result_tracks = []
|
||||||
for track in results:
|
for track in results:
|
||||||
|
@ -33,6 +33,8 @@ class Genius:
|
|||||||
@song: the song to search
|
@song: the song to search
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
artist = artist.strip().lower()
|
||||||
|
song = song.strip().lower()
|
||||||
search_term = f'{artist}%20{song}'
|
search_term = f'{artist}%20{song}'
|
||||||
returned_lyrics = ''
|
returned_lyrics = ''
|
||||||
async with ClientSession() as client:
|
async with ClientSession() as client:
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
|
sys.path.insert(1, '.')
|
||||||
import sources.cache, sources.genius, sources.aggregate
|
import sources.cache, sources.genius, sources.aggregate
|
||||||
import utils
|
|
||||||
|
|
||||||
test_artist = "hopsin"
|
test_artist = "hopsin"
|
||||||
test_song = "ill mind of hopsin 5"
|
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 = 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_cache(artist=test_artist, song=test_song))
|
||||||
loop.run_until_complete(test_aggregate())
|
# loop.run_until_complete(test_aggregate())
|
||||||
|
@ -63,7 +63,8 @@ class TrackMatcher:
|
|||||||
extra spaces, and converting to lowercase.
|
extra spaces, and converting to lowercase.
|
||||||
"""
|
"""
|
||||||
# Remove special characters and convert 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
|
# Normalize spaces
|
||||||
text = ' '.join(text.split())
|
text = ' '.join(text.split())
|
||||||
return text
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user