mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: improve fuzzy matching for tracks with special formatting
- Lower matching threshold from 60 to 50 for more lenient matching - Add fallback to trust provider's top result when artist matches well (>=70) - Helps match tracks with parentheses, brackets, and stylized titles like 'PiLlOwT4lK' - Provider search already does fuzzy matching, so trust it when artist is correct
This commit is contained in:
@@ -539,7 +539,8 @@ public class SpotifyTrackMatchingService : BackgroundService
|
|||||||
|
|
||||||
if (results.Count == 0) return null;
|
if (results.Count == 0) return null;
|
||||||
|
|
||||||
var bestMatch = results
|
// Score all results
|
||||||
|
var scoredResults = results
|
||||||
.Select(song => new
|
.Select(song => new
|
||||||
{
|
{
|
||||||
Song = song,
|
Song = song,
|
||||||
@@ -554,13 +555,27 @@ public class SpotifyTrackMatchingService : BackgroundService
|
|||||||
TotalScore = (x.TitleScore * 0.6) + (x.ArtistScore * 0.4)
|
TotalScore = (x.TitleScore * 0.6) + (x.ArtistScore * 0.4)
|
||||||
})
|
})
|
||||||
.OrderByDescending(x => x.TotalScore)
|
.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;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
Reference in New Issue
Block a user