From 7779049c934a5449c2551474f0366a6d94d3851c Mon Sep 17 00:00:00 2001 From: codey Date: Wed, 26 Nov 2025 15:09:43 -0500 Subject: [PATCH] misc / sr_wrapper-- only consider an album returned from tidal to be a duplicate if both the name AND release date match. --- base.py | 1 + utils/sr_wrapper.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/base.py b/base.py index d29b4d4..c86a41b 100644 --- a/base.py +++ b/base.py @@ -36,6 +36,7 @@ origins = [ "https://status.boatson.boats", "https://_new.codey.lol", "http://localhost:4321", + "https://local.codey.lol:4321", ] app.add_middleware( diff --git a/utils/sr_wrapper.py b/utils/sr_wrapper.py index a81682f..5d328f5 100644 --- a/utils/sr_wrapper.py +++ b/utils/sr_wrapper.py @@ -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"]),