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:
@@ -196,12 +196,23 @@ class SRUtil:
|
||||
title_match = self.is_fuzzy_match(expected_title, found_title, threshold)
|
||||
return artist_match and album_match and title_match
|
||||
|
||||
def dedupe_by_key(self, key: str, entries: list[dict]) -> list[dict]:
|
||||
deduped = {}
|
||||
def dedupe_by_key(
|
||||
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:
|
||||
norm = entry[key].strip().lower()
|
||||
if norm not in deduped:
|
||||
deduped[norm] = entry
|
||||
composite_key = tuple(normalize(entry.get(k)) for k in keys)
|
||||
if composite_key not in deduped:
|
||||
deduped[composite_key] = entry
|
||||
return list(deduped.values())
|
||||
|
||||
def group_artists_by_name(
|
||||
@@ -450,7 +461,7 @@ class SRUtil:
|
||||
return None
|
||||
if not metadata:
|
||||
return None
|
||||
albums = self.dedupe_by_key("title", metadata.get("albums", []))
|
||||
albums = self.dedupe_by_key(["title", "releaseDate"], metadata.get("albums", []))
|
||||
albums_out = [
|
||||
{
|
||||
"artist": ", ".join(artist["name"] for artist in album["artists"]),
|
||||
|
||||
Reference in New Issue
Block a user