diff --git a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs index 37e77f1..45bf227 100644 --- a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs +++ b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs @@ -539,7 +539,8 @@ public class SpotifyTrackMatchingService : BackgroundService if (results.Count == 0) return null; - var bestMatch = results + // Score all results + var scoredResults = results .Select(song => new { Song = song, @@ -554,13 +555,27 @@ public class SpotifyTrackMatchingService : BackgroundService TotalScore = (x.TitleScore * 0.6) + (x.ArtistScore * 0.4) }) .OrderByDescending(x => x.TotalScore) - .FirstOrDefault(); + .ToList(); - if (bestMatch != null && bestMatch.TotalScore >= 60) + var bestMatch = scoredResults.FirstOrDefault(); + + // If we have a good match (50+), use it + if (bestMatch != null && bestMatch.TotalScore >= 50) { return bestMatch.Song; } + // Fallback: If the provider returned results and the top result has decent artist match, + // trust the provider's search algorithm (it already did fuzzy matching) + // This helps with tracks that have features/remixes in parentheses/brackets + // where the provider might format them differently + if (bestMatch != null && bestMatch.ArtistScore >= 70) + { + _logger.LogDebug("Using provider's top result despite low title score (Artist: {ArtistScore}, Title: {TitleScore}): {Title}", + bestMatch.ArtistScore, bestMatch.TitleScore, bestMatch.Song.Title); + return bestMatch.Song; + } + return null; } catch