From bc2432d9f6cc40cb843c342235035e1d5267b322 Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Thu, 4 Jun 2026 21:16:41 -0700 Subject: [PATCH] Fix #785 (cont.): also search canonical title in discovery worker The scoring best-of only helps if the right candidates were returned. File/CSV titles ('Artist - Title') made the search query carry the artist prefix; add canonical-title search queries so the correct tracks are actually found, then the scorer best-of matches them. Additive (extra queries only when the title canonicalizes differently). --- core/discovery/playlist.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/discovery/playlist.py b/core/discovery/playlist.py index db841d72..1d6fce88 100644 --- a/core/discovery/playlist.py +++ b/core/discovery/playlist.py @@ -247,6 +247,20 @@ def run_playlist_discovery_worker(playlists, automation_id=None, deps: PlaylistD except Exception: search_queries = [f"{artist_name} {track_name}", track_name] + # #785: file/CSV playlists keep raw "Artist - Title" titles, so the + # queries above search for the artist prefix too. Also search the + # canonicalized title so the right candidates are actually returned + # (the scorer best-of then matches them). + try: + from core.text.source_title import canonical_source_track + _cq_title, _cq_artist = canonical_source_track(track_name, artist_name) + if (_cq_title, _cq_artist) != (track_name, artist_name): + for _q in (f"{_cq_artist} {_cq_title}", _cq_title): + if _q not in search_queries: + search_queries.append(_q) + except Exception: + pass + # Step 3: Search and score best_match = None best_confidence = 0.0