formatting
This commit is contained in:
@@ -19,28 +19,28 @@ def normalize_for_search(s: str) -> str:
|
||||
Removes common variations that cause exact match failures.
|
||||
"""
|
||||
s = s.lower().strip()
|
||||
|
||||
|
||||
# Remove parenthetical content: (Remastered), (feat. X), (2020 Remix), etc.
|
||||
s = re.sub(r'\s*\([^)]*\)\s*', ' ', s)
|
||||
|
||||
s = re.sub(r"\s*\([^)]*\)\s*", " ", s)
|
||||
|
||||
# Remove bracketed content: [Explicit], [Deluxe Edition], etc.
|
||||
s = re.sub(r'\s*\[[^\]]*\]\s*', ' ', s)
|
||||
|
||||
s = re.sub(r"\s*\[[^\]]*\]\s*", " ", s)
|
||||
|
||||
# Remove "feat.", "ft.", "featuring" and everything after
|
||||
s = re.sub(r'\s*(feat\.?|ft\.?|featuring)\s+.*$', '', s, flags=re.IGNORECASE)
|
||||
|
||||
s = re.sub(r"\s*(feat\.?|ft\.?|featuring)\s+.*$", "", s, flags=re.IGNORECASE)
|
||||
|
||||
# Remove "The " prefix from artist names
|
||||
s = re.sub(r'^the\s+', '', s)
|
||||
|
||||
s = re.sub(r"^the\s+", "", s)
|
||||
|
||||
# Normalize & to "and"
|
||||
s = re.sub(r'\s*&\s*', ' and ', s)
|
||||
|
||||
s = re.sub(r"\s*&\s*", " and ", s)
|
||||
|
||||
# Remove punctuation except spaces
|
||||
s = re.sub(r"[^\w\s]", '', s)
|
||||
|
||||
s = re.sub(r"[^\w\s]", "", s)
|
||||
|
||||
# Collapse multiple spaces
|
||||
s = re.sub(r'\s+', ' ', s).strip()
|
||||
|
||||
s = re.sub(r"\s+", " ", s).strip()
|
||||
|
||||
return s
|
||||
|
||||
|
||||
@@ -64,12 +64,12 @@ class LRCLib:
|
||||
) -> Optional[LyricsResult]:
|
||||
"""
|
||||
LRCLib Local Database Search with normalization and smart fallback.
|
||||
|
||||
|
||||
Search strategy:
|
||||
1. Exact match on lowercased input (fastest, ~0.1ms)
|
||||
2. Exact match on normalized input (fast, ~0.1ms)
|
||||
2. Exact match on normalized input (fast, ~0.1ms)
|
||||
3. Artist trigram + song exact within results (medium, ~50-200ms)
|
||||
|
||||
|
||||
Args:
|
||||
artist (str): the artist to search
|
||||
song (str): the song to search
|
||||
@@ -110,7 +110,7 @@ class LRCLib:
|
||||
if not best_match:
|
||||
artist_norm = normalize_for_search(artist)
|
||||
song_norm = normalize_for_search(song)
|
||||
|
||||
|
||||
if artist_norm != artist_lower or song_norm != song_lower:
|
||||
result = await db.execute(
|
||||
select(
|
||||
@@ -133,7 +133,7 @@ class LRCLib:
|
||||
if not best_match:
|
||||
artist_norm = normalize_for_search(artist)
|
||||
song_norm = normalize_for_search(song)
|
||||
|
||||
|
||||
result = await db.execute(
|
||||
select(
|
||||
Tracks.artist_name,
|
||||
|
||||
Reference in New Issue
Block a user