formatting / minor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Database models for LRCLib lyrics cache.
|
||||
"""
|
||||
|
||||
import os
|
||||
import urllib.parse
|
||||
from typing import Type, AsyncGenerator
|
||||
@@ -24,6 +25,7 @@ Base: Type[DeclarativeMeta] = declarative_base()
|
||||
|
||||
class Tracks(Base): # type: ignore
|
||||
"""Tracks table - stores track metadata."""
|
||||
|
||||
__tablename__ = "tracks"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
@@ -60,6 +62,7 @@ class Tracks(Base): # type: ignore
|
||||
|
||||
class Lyrics(Base): # type: ignore
|
||||
"""Lyrics table - stores lyrics content."""
|
||||
|
||||
__tablename__ = "lyrics"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
@@ -95,11 +98,7 @@ encoded_password = urllib.parse.quote_plus(POSTGRES_PASSWORD)
|
||||
|
||||
DATABASE_URL: str = f"postgresql+asyncpg://{POSTGRES_USER}:{encoded_password}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}"
|
||||
async_engine: AsyncEngine = create_async_engine(
|
||||
DATABASE_URL,
|
||||
pool_size=20,
|
||||
max_overflow=10,
|
||||
pool_pre_ping=True,
|
||||
echo=False
|
||||
DATABASE_URL, pool_size=20, max_overflow=10, pool_pre_ping=True, echo=False
|
||||
)
|
||||
AsyncSessionLocal = async_sessionmaker(bind=async_engine, expire_on_commit=False)
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class Genius:
|
||||
)
|
||||
if not best_match:
|
||||
raise InvalidGeniusResponseException("No matching result")
|
||||
|
||||
|
||||
logging.info("To scrape: %s", to_scrape)
|
||||
((scrape_stub, track), confidence) = best_match
|
||||
scrape_url: str = f"{self.genius_url}{scrape_stub[1:]}"
|
||||
|
||||
@@ -46,7 +46,7 @@ class LRCLib:
|
||||
|
||||
async with AsyncSessionLocal() as db:
|
||||
best_match = None
|
||||
|
||||
|
||||
# Try exact match first (fastest)
|
||||
result = await db.execute(
|
||||
select(
|
||||
@@ -63,7 +63,7 @@ class LRCLib:
|
||||
.limit(1)
|
||||
)
|
||||
best_match = result.first()
|
||||
|
||||
|
||||
# If no exact match, try prefix match (faster than full ILIKE)
|
||||
if not best_match:
|
||||
result = await db.execute(
|
||||
@@ -81,7 +81,7 @@ class LRCLib:
|
||||
.limit(1)
|
||||
)
|
||||
best_match = result.first()
|
||||
|
||||
|
||||
# If still no match, try full ILIKE (slowest)
|
||||
if not best_match:
|
||||
result = await db.execute(
|
||||
@@ -106,7 +106,7 @@ class LRCLib:
|
||||
|
||||
returned_artist = best_match.artist_name
|
||||
returned_song = best_match.name
|
||||
|
||||
|
||||
if plain:
|
||||
if not best_match.plain_lyrics:
|
||||
logging.info("No plain lyrics available on %s", self.label)
|
||||
@@ -125,19 +125,18 @@ class LRCLib:
|
||||
input_track = f"{artist} - {song}"
|
||||
returned_track = f"{returned_artist} - {returned_song}"
|
||||
match_result = self.matcher.find_best_match(
|
||||
input_track=input_track,
|
||||
candidate_tracks=[(0, returned_track)]
|
||||
input_track=input_track, candidate_tracks=[(0, returned_track)]
|
||||
)
|
||||
|
||||
|
||||
if not match_result:
|
||||
return None
|
||||
|
||||
|
||||
_matched, confidence = match_result
|
||||
|
||||
|
||||
logging.info("Result found on %s", self.label)
|
||||
time_end = time.time()
|
||||
time_diff = time_end - time_start
|
||||
|
||||
|
||||
matched = LyricsResult(
|
||||
artist=returned_artist,
|
||||
song=returned_song,
|
||||
@@ -146,10 +145,10 @@ class LRCLib:
|
||||
confidence=confidence,
|
||||
time=time_diff,
|
||||
)
|
||||
|
||||
|
||||
await self.redis_cache.increment_found_count(self.label)
|
||||
return matched
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Exception in %s: %s", self.label, str(e))
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user