From 93699249682931a43f0329db26863684dc6a6339 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 18 Apr 2026 08:53:46 -0700 Subject: [PATCH] Fix discography dedup dropping studio albums for compilations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dedup key (normalized_title, year) caused different albums from the same year to collide when title normalization stripped too much. The "prefer more tracks" logic then kept compilations over studio albums. Two fixes: - Title similarity check: if normalized titles are <85% similar, they're different albums, not variants — keep both - Compilation deprioritization: studio albums win over compilations and "best of" collections when they do collide --- web_server.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web_server.py b/web_server.py index 7b47b66a..92a6b444 100644 --- a/web_server.py +++ b/web_server.py @@ -50837,9 +50837,23 @@ def get_spotify_artist_discography(artist_name): groups[key] = r else: existing = groups[key] - # Prefer: more tracks > explicit > longer title (deluxe) - if (r.get('track_count', 0) > existing.get('track_count', 0) or - '(explicit' in r['title'].lower()): + # Only dedup if titles are genuinely similar (not just same year) + from difflib import SequenceMatcher + title_sim = SequenceMatcher(None, norm, _VARIANT_RE.sub('', existing['title']).strip().lower()).ratio() + if title_sim < 0.85: + # Titles are too different — not variants, keep both + # Use full title as key to avoid collision + groups[(r['title'].lower(), r.get('year'))] = r + continue + # Prefer: studio over compilation, explicit over clean, more tracks as tiebreaker + r_is_compilation = r.get('album_type', '').lower() == 'compilation' or 'best of' in r['title'].lower() or 'greatest hits' in r['title'].lower() + e_is_compilation = existing.get('album_type', '').lower() == 'compilation' or 'best of' in existing['title'].lower() or 'greatest hits' in existing['title'].lower() + if e_is_compilation and not r_is_compilation: + groups[key] = r # Studio album wins over compilation + elif r_is_compilation and not e_is_compilation: + pass # Keep existing studio album + elif (r.get('track_count', 0) > existing.get('track_count', 0) or + '(explicit' in r['title'].lower()): groups[key] = r return list(groups.values())