Release 1.0.0.10: tag-based matching and metadata normalization

This commit is contained in:
1xDed committed 2026-12-01 02:28:18 +03:00
1 parent 106e8f09e0
commit 0dbf00a055
17 files changed
+513 -53

No files matched your search

@@ -81,6 +81,23 @@ public static partial class TextMatch
return best;
}
/// <summary>Splits a combined artist string on commas.</summary>
public static IEnumerable<string> SplitCommaSeparated(string? value)
{
if (string.IsNullOrWhiteSpace(value))
{
yield break;
}
foreach (var part in value.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
if (part.Length > 0)
{
yield return part;
}
}
}
/// <summary>Splits a combined artist string ("A, B &amp; C feat. D") into individual names.</summary>
public static IEnumerable<string> SplitArtists(string? value)
{
@@ -183,10 +200,15 @@ public static class MatchScoring
IReadOnlyList<string> artists,
long durationMs,
double threshold,
int toleranceSeconds)
int toleranceSeconds,
string? album = null)
{
(TrackDto Track, double Score)? best = null;
var hasArtists = artists.Any(a => !string.IsNullOrWhiteSpace(a));
var artistParts = artists
.SelectMany(TextMatch.SplitArtists)
.Where(a => !string.IsNullOrWhiteSpace(a))
.ToArray();
foreach (var track in tracks)
{
var titleScore = TextMatch.Similarity(title, track.Title);
@@ -194,6 +216,18 @@ public static class MatchScoring
? TextMatch.ArtistSimilarity(artists, track.Artists.Select(a => a.Name))
: 1;
var durationScore = DurationScore(durationMs, track.DurationMs, toleranceSeconds);
var albumScore = 0.5;
if (!string.IsNullOrWhiteSpace(album))
{
var candidateAlbum = track.Albums.FirstOrDefault()?.Title;
albumScore = string.IsNullOrWhiteSpace(candidateAlbum)
? 0
: TextMatch.Similarity(album, candidateAlbum);
}
var matchedArtistCount = hasArtists
? artistParts.Count(a => track.Artists.Any(c => TextMatch.Similarity(a, c.Name) >= 0.7))
: 0;
double score;
if (hasArtists)
@@ -204,22 +238,25 @@ public static class MatchScoring
}
score = durationScore is null
? (0.6 * titleScore) + (0.4 * artistScore)
: (0.5 * titleScore) + (0.3 * artistScore) + (0.2 * durationScore.Value);
? (0.5 * titleScore) + (0.3 * artistScore) + (0.2 * albumScore)
: (0.45 * titleScore) + (0.25 * artistScore) + (0.2 * durationScore.Value) + (0.1 * albumScore);
}
else
{
// No artist tags at all: rely on the title and, when available, the duration.
// No artist tags at all: rely on the title and, when available, the duration and album.
if (titleScore < 0.8)
{
continue;
}
score = durationScore is null
? titleScore
: (0.65 * titleScore) + (0.35 * durationScore.Value);
? (0.75 * titleScore) + (0.25 * albumScore)
: (0.55 * titleScore) + (0.3 * durationScore.Value) + (0.15 * albumScore);
}
// Prefer a result that matches more of the listed artists when the other signals are equal.
score += 0.001 * matchedArtistCount;
if (best is null || score > best.Value.Score)
{
best = (track, score);