mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Fix LRCLib and SquidWTF error handling
Some checks failed
CI / build-and-test (push) Has been cancelled
Some checks failed
CI / build-and-test (push) Has been cancelled
- Handle nullable duration in LRCLib API responses - Validate input parameters before making LRCLib requests - Change SquidWTF artist warning to debug level (expected behavior) - Prevent JSON deserialization errors when duration is null - Prevent 400 Bad Request errors from empty track names
This commit is contained in:
@@ -30,6 +30,14 @@ public class LrclibService
|
|||||||
|
|
||||||
public async Task<LyricsInfo?> GetLyricsAsync(string trackName, string[] artistNames, string albumName, int durationSeconds)
|
public async Task<LyricsInfo?> GetLyricsAsync(string trackName, string[] artistNames, string albumName, int durationSeconds)
|
||||||
{
|
{
|
||||||
|
// Validate input parameters
|
||||||
|
if (string.IsNullOrWhiteSpace(trackName) || artistNames == null || artistNames.Length == 0)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Invalid parameters for lyrics search: trackName={TrackName}, artistCount={ArtistCount}",
|
||||||
|
trackName, artistNames?.Length ?? 0);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var artistName = string.Join(", ", artistNames);
|
var artistName = string.Join(", ", artistNames);
|
||||||
var cacheKey = $"lyrics:{artistName}:{trackName}:{albumName}:{durationSeconds}";
|
var cacheKey = $"lyrics:{artistName}:{trackName}:{albumName}:{durationSeconds}";
|
||||||
|
|
||||||
@@ -112,7 +120,7 @@ public class LrclibService
|
|||||||
var artistCountBonus = resultArtistCount == expectedArtistCount ? 50.0 : 0.0;
|
var artistCountBonus = resultArtistCount == expectedArtistCount ? 50.0 : 0.0;
|
||||||
|
|
||||||
// Duration match (within 5 seconds is good)
|
// Duration match (within 5 seconds is good)
|
||||||
var durationDiff = Math.Abs(result.Duration - durationSeconds);
|
var durationDiff = result.Duration.HasValue ? Math.Abs(result.Duration.Value - durationSeconds) : 999;
|
||||||
var durationScore = durationDiff <= 5 ? 100.0 : Math.Max(0, 100 - (durationDiff * 2));
|
var durationScore = durationDiff <= 5 ? 100.0 : Math.Max(0, 100 - (durationDiff * 2));
|
||||||
|
|
||||||
// Bonus for having synced lyrics (prefer synced over plain)
|
// Bonus for having synced lyrics (prefer synced over plain)
|
||||||
@@ -143,7 +151,7 @@ public class LrclibService
|
|||||||
TrackName = bestMatch.TrackName ?? trackName,
|
TrackName = bestMatch.TrackName ?? trackName,
|
||||||
ArtistName = bestMatch.ArtistName ?? artistName,
|
ArtistName = bestMatch.ArtistName ?? artistName,
|
||||||
AlbumName = bestMatch.AlbumName ?? albumName,
|
AlbumName = bestMatch.AlbumName ?? albumName,
|
||||||
Duration = (int)Math.Round(bestMatch.Duration),
|
Duration = bestMatch.Duration.HasValue ? (int)Math.Round(bestMatch.Duration.Value) : durationSeconds,
|
||||||
Instrumental = bestMatch.Instrumental,
|
Instrumental = bestMatch.Instrumental,
|
||||||
PlainLyrics = bestMatch.PlainLyrics,
|
PlainLyrics = bestMatch.PlainLyrics,
|
||||||
SyncedLyrics = bestMatch.SyncedLyrics
|
SyncedLyrics = bestMatch.SyncedLyrics
|
||||||
@@ -192,7 +200,7 @@ public class LrclibService
|
|||||||
TrackName = lyrics.TrackName ?? trackName,
|
TrackName = lyrics.TrackName ?? trackName,
|
||||||
ArtistName = lyrics.ArtistName ?? artistName,
|
ArtistName = lyrics.ArtistName ?? artistName,
|
||||||
AlbumName = lyrics.AlbumName ?? albumName,
|
AlbumName = lyrics.AlbumName ?? albumName,
|
||||||
Duration = (int)Math.Round(lyrics.Duration),
|
Duration = lyrics.Duration.HasValue ? (int)Math.Round(lyrics.Duration.Value) : durationSeconds,
|
||||||
Instrumental = lyrics.Instrumental,
|
Instrumental = lyrics.Instrumental,
|
||||||
PlainLyrics = lyrics.PlainLyrics,
|
PlainLyrics = lyrics.PlainLyrics,
|
||||||
SyncedLyrics = lyrics.SyncedLyrics
|
SyncedLyrics = lyrics.SyncedLyrics
|
||||||
@@ -334,7 +342,7 @@ public class LrclibService
|
|||||||
TrackName = lyrics.TrackName ?? trackName,
|
TrackName = lyrics.TrackName ?? trackName,
|
||||||
ArtistName = lyrics.ArtistName ?? artistName,
|
ArtistName = lyrics.ArtistName ?? artistName,
|
||||||
AlbumName = lyrics.AlbumName ?? albumName,
|
AlbumName = lyrics.AlbumName ?? albumName,
|
||||||
Duration = (int)Math.Round(lyrics.Duration),
|
Duration = lyrics.Duration.HasValue ? (int)Math.Round(lyrics.Duration.Value) : durationSeconds,
|
||||||
Instrumental = lyrics.Instrumental,
|
Instrumental = lyrics.Instrumental,
|
||||||
PlainLyrics = lyrics.PlainLyrics,
|
PlainLyrics = lyrics.PlainLyrics,
|
||||||
SyncedLyrics = lyrics.SyncedLyrics
|
SyncedLyrics = lyrics.SyncedLyrics
|
||||||
@@ -390,7 +398,7 @@ public class LrclibService
|
|||||||
TrackName = lyrics.TrackName ?? string.Empty,
|
TrackName = lyrics.TrackName ?? string.Empty,
|
||||||
ArtistName = lyrics.ArtistName ?? string.Empty,
|
ArtistName = lyrics.ArtistName ?? string.Empty,
|
||||||
AlbumName = lyrics.AlbumName ?? string.Empty,
|
AlbumName = lyrics.AlbumName ?? string.Empty,
|
||||||
Duration = (int)Math.Round(lyrics.Duration),
|
Duration = lyrics.Duration.HasValue ? (int)Math.Round(lyrics.Duration.Value) : 0,
|
||||||
Instrumental = lyrics.Instrumental,
|
Instrumental = lyrics.Instrumental,
|
||||||
PlainLyrics = lyrics.PlainLyrics,
|
PlainLyrics = lyrics.PlainLyrics,
|
||||||
SyncedLyrics = lyrics.SyncedLyrics
|
SyncedLyrics = lyrics.SyncedLyrics
|
||||||
@@ -419,7 +427,7 @@ public class LrclibService
|
|||||||
public string? TrackName { get; set; }
|
public string? TrackName { get; set; }
|
||||||
public string? ArtistName { get; set; }
|
public string? ArtistName { get; set; }
|
||||||
public string? AlbumName { get; set; }
|
public string? AlbumName { get; set; }
|
||||||
public double Duration { get; set; }
|
public double? Duration { get; set; }
|
||||||
public bool Instrumental { get; set; }
|
public bool Instrumental { get; set; }
|
||||||
public string? PlainLyrics { get; set; }
|
public string? PlainLyrics { get; set; }
|
||||||
public string? SyncedLyrics { get; set; }
|
public string? SyncedLyrics { get; set; }
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
|||||||
|
|
||||||
if (artistSource == null)
|
if (artistSource == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Could not find artist data in response. Response keys: {Keys}",
|
_logger.LogDebug("Could not find artist data in response. Response keys: {Keys}",
|
||||||
string.Join(", ", result.RootElement.EnumerateObject().Select(p => p.Name)));
|
string.Join(", ", result.RootElement.EnumerateObject().Select(p => p.Name)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user