From 3a7c25f20f877402e1ccdaa983e71bca78c2a31f Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sun, 12 Apr 2026 17:41:55 -0700 Subject: [PATCH] Fix allow_duplicates not working for singles in watchlist scanner Singles like "idol" weren't added when the same song existed on a different album because check_track_exists used album-aware matching that found the track via album name. Now skips the album hint when allow_duplicates is on so matching is title+artist only, then compares album names ourselves with a strict 0.85 threshold. Only affects users with allow_duplicates enabled. --- core/watchlist_scanner.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/watchlist_scanner.py b/core/watchlist_scanner.py index 312e9320..dedc93f2 100644 --- a/core/watchlist_scanner.py +++ b/core/watchlist_scanner.py @@ -1530,16 +1530,23 @@ class WatchlistScanner: for artist_name in artists_to_search: for query_title in unique_title_variations: - db_track, confidence = self.database.check_track_exists(query_title, artist_name, confidence_threshold=0.7, server_source=active_server, album=album_name) + # When allow_duplicates is on, skip album hint so we get title+artist matches only + search_album = None if allow_duplicates else album_name + db_track, confidence = self.database.check_track_exists(query_title, artist_name, confidence_threshold=0.7, server_source=active_server, album=search_album) if db_track and confidence >= 0.7: - # When allow_duplicates is on, only skip if the same album matches - if allow_duplicates and album_name and db_track.album_title: - from difflib import SequenceMatcher - album_sim = SequenceMatcher(None, album_name.lower(), db_track.album_title.lower()).ratio() - if album_sim < 0.8: - logger.debug(f"Track found but different album (allow_duplicates=True): '{original_title}' — library: '{db_track.album_title}', wanted: '{album_name}'") - continue # Different album — allow it + # When allow_duplicates is on, only skip if the exact same album + if allow_duplicates and album_name: + lib_album = getattr(db_track, 'album_title', '') or '' + if lib_album: + from difflib import SequenceMatcher + album_sim = SequenceMatcher(None, album_name.lower(), lib_album.lower()).ratio() + if album_sim < 0.85: + logger.debug(f"Track found but different album (allow_duplicates=True): '{original_title}' — library: '{lib_album}', wanted: '{album_name}'") + continue # Different album — allow it + else: + # No album info in library — can't compare, allow it + continue logger.debug(f"Track found in library: '{original_title}' by '{artist_name}' (confidence: {confidence:.2f})") return False # Track exists in library