Fix artist detail parsing to handle missing artist property

- Add TryGetProperty check for artist field in albums response
- Log response keys when artist data not found for debugging
- Improves error handling when API returns albums without artist field
This commit is contained in:
2026-02-06 01:39:43 -05:00
parent 5f22fb0a3b
commit a2e9021100

View File

@@ -360,21 +360,25 @@ public class SquidWTFMetadataService : IMusicMetadataService
JsonElement? artistSource = null;
int albumCount = 0;
// Think this can maybe switch to something using ParseTidalAlbum
// Try to get artist from albums.items[0].artist
if (result.RootElement.TryGetProperty("albums", out var albums) &&
albums.TryGetProperty("items", out var albumItems) &&
albumItems.GetArrayLength() > 0)
{
albumCount = albumItems.GetArrayLength();
artistSource = albumItems[0].GetProperty("artist");
_logger.LogInformation("Found artist from albums, albumCount={AlbumCount}", albumCount);
if (albumItems[0].TryGetProperty("artist", out var artistEl))
{
artistSource = artistEl;
_logger.LogInformation("Found artist from albums, albumCount={AlbumCount}", albumCount);
}
}
// Think this can maybe switch to something using ParseTidalTrack
else if (result.RootElement.TryGetProperty("tracks", out var tracks) &&
tracks.GetArrayLength() > 0 &&
tracks[0].TryGetProperty("artists", out var artists) &&
artists.GetArrayLength() > 0)
// Fallback: try to get artist from tracks[0].artists[0]
if (artistSource == null &&
result.RootElement.TryGetProperty("tracks", out var tracks) &&
tracks.GetArrayLength() > 0 &&
tracks[0].TryGetProperty("artists", out var artists) &&
artists.GetArrayLength() > 0)
{
artistSource = artists[0];
_logger.LogInformation("Found artist from tracks");
@@ -382,7 +386,8 @@ public class SquidWTFMetadataService : IMusicMetadataService
if (artistSource == null)
{
_logger.LogWarning("Could not find artist data in response");
_logger.LogWarning("Could not find artist data in response. Response keys: {Keys}",
string.Join(", ", result.RootElement.EnumerateObject().Select(p => p.Name)));
return null;
}