misc / sr_wrapper-- only consider an album returned from tidal to be a duplicate if both the name AND release date match.
This commit is contained in:
1
base.py
1
base.py
@@ -36,6 +36,7 @@ origins = [
|
|||||||
"https://status.boatson.boats",
|
"https://status.boatson.boats",
|
||||||
"https://_new.codey.lol",
|
"https://_new.codey.lol",
|
||||||
"http://localhost:4321",
|
"http://localhost:4321",
|
||||||
|
"https://local.codey.lol:4321",
|
||||||
]
|
]
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
|
|||||||
@@ -196,12 +196,23 @@ class SRUtil:
|
|||||||
title_match = self.is_fuzzy_match(expected_title, found_title, threshold)
|
title_match = self.is_fuzzy_match(expected_title, found_title, threshold)
|
||||||
return artist_match and album_match and title_match
|
return artist_match and album_match and title_match
|
||||||
|
|
||||||
def dedupe_by_key(self, key: str, entries: list[dict]) -> list[dict]:
|
def dedupe_by_key(
|
||||||
deduped = {}
|
self, key: str | list[str], entries: list[dict]
|
||||||
|
) -> list[dict]:
|
||||||
|
"""Return entries de-duplicated by one or more keys."""
|
||||||
|
|
||||||
|
keys = [key] if isinstance(key, str) else list(key)
|
||||||
|
if not keys:
|
||||||
|
return entries
|
||||||
|
|
||||||
|
def normalize(value: Any) -> str:
|
||||||
|
return str(value or "").strip().lower()
|
||||||
|
|
||||||
|
deduped: dict[tuple[str, ...], dict] = {}
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
norm = entry[key].strip().lower()
|
composite_key = tuple(normalize(entry.get(k)) for k in keys)
|
||||||
if norm not in deduped:
|
if composite_key not in deduped:
|
||||||
deduped[norm] = entry
|
deduped[composite_key] = entry
|
||||||
return list(deduped.values())
|
return list(deduped.values())
|
||||||
|
|
||||||
def group_artists_by_name(
|
def group_artists_by_name(
|
||||||
@@ -450,7 +461,7 @@ class SRUtil:
|
|||||||
return None
|
return None
|
||||||
if not metadata:
|
if not metadata:
|
||||||
return None
|
return None
|
||||||
albums = self.dedupe_by_key("title", metadata.get("albums", []))
|
albums = self.dedupe_by_key(["title", "releaseDate"], metadata.get("albums", []))
|
||||||
albums_out = [
|
albums_out = [
|
||||||
{
|
{
|
||||||
"artist": ", ".join(artist["name"] for artist in album["artists"]),
|
"artist": ", ".join(artist["name"] for artist in album["artists"]),
|
||||||
|
|||||||
Reference in New Issue
Block a user