track count fix
Some checks failed
CI / build-and-test (push) Has been cancelled

This commit is contained in:
2026-02-03 01:49:58 -05:00
parent 0356f3c54d
commit bbb0d9bb73

View File

@@ -2525,17 +2525,48 @@ public class JellyfinController : ControllerBase
_logger.LogInformation("File cache result: {Count} tracks", missingTracks?.Count ?? 0);
}
// Get local tracks count from Jellyfin
var localTracksCount = 0;
try
{
var (localTracksResponse, _) = await _proxyService.GetJsonAsync(
$"Playlists/{playlistId}/Items",
null,
Request.Headers);
if (localTracksResponse != null &&
localTracksResponse.RootElement.TryGetProperty("Items", out var localItems))
{
localTracksCount = localItems.GetArrayLength();
_logger.LogInformation("Found {Count} local tracks in Jellyfin playlist {Name}",
localTracksCount, playlistName);
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to get local tracks count for {Name}", playlistName);
}
if (missingTracks != null && missingTracks.Count > 0)
{
// Update ChildCount to show the number of tracks we'll provide
itemDict["ChildCount"] = missingTracks.Count;
// Update ChildCount to show total tracks (local + external)
var totalCount = localTracksCount + missingTracks.Count;
itemDict["ChildCount"] = totalCount;
modified = true;
_logger.LogInformation("✓ Updated ChildCount for Spotify playlist {Name} to {Count}",
playlistName, missingTracks.Count);
_logger.LogInformation("✓ Updated ChildCount for Spotify playlist {Name} to {Total} ({Local} local + {External} external)",
playlistName, totalCount, localTracksCount, missingTracks.Count);
}
else if (localTracksCount > 0)
{
// No external tracks, but we have local tracks
itemDict["ChildCount"] = localTracksCount;
modified = true;
_logger.LogInformation("✓ Updated ChildCount for Spotify playlist {Name} to {Count} (local only, no external tracks)",
playlistName, localTracksCount);
}
else
{
_logger.LogWarning("No missing tracks found for {Name}", playlistName);
_logger.LogWarning("No tracks found for {Name} (neither local nor external)", playlistName);
}
}
}