mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
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:
@@ -360,18 +360,22 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
|||||||
JsonElement? artistSource = null;
|
JsonElement? artistSource = null;
|
||||||
int albumCount = 0;
|
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) &&
|
if (result.RootElement.TryGetProperty("albums", out var albums) &&
|
||||||
albums.TryGetProperty("items", out var albumItems) &&
|
albums.TryGetProperty("items", out var albumItems) &&
|
||||||
albumItems.GetArrayLength() > 0)
|
albumItems.GetArrayLength() > 0)
|
||||||
{
|
{
|
||||||
albumCount = albumItems.GetArrayLength();
|
albumCount = albumItems.GetArrayLength();
|
||||||
artistSource = albumItems[0].GetProperty("artist");
|
if (albumItems[0].TryGetProperty("artist", out var artistEl))
|
||||||
|
{
|
||||||
|
artistSource = artistEl;
|
||||||
_logger.LogInformation("Found artist from albums, albumCount={AlbumCount}", albumCount);
|
_logger.LogInformation("Found artist from albums, albumCount={AlbumCount}", albumCount);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Think this can maybe switch to something using ParseTidalTrack
|
// Fallback: try to get artist from tracks[0].artists[0]
|
||||||
else if (result.RootElement.TryGetProperty("tracks", out var tracks) &&
|
if (artistSource == null &&
|
||||||
|
result.RootElement.TryGetProperty("tracks", out var tracks) &&
|
||||||
tracks.GetArrayLength() > 0 &&
|
tracks.GetArrayLength() > 0 &&
|
||||||
tracks[0].TryGetProperty("artists", out var artists) &&
|
tracks[0].TryGetProperty("artists", out var artists) &&
|
||||||
artists.GetArrayLength() > 0)
|
artists.GetArrayLength() > 0)
|
||||||
@@ -382,7 +386,8 @@ public class SquidWTFMetadataService : IMusicMetadataService
|
|||||||
|
|
||||||
if (artistSource == null)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user