diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index 3179cc1..731b5d2 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -1864,6 +1864,7 @@ public class JellyfinController : ControllerBase // Modify response if it contains Spotify playlists to update ChildCount if (_spotifySettings.Enabled && result.RootElement.TryGetProperty("Items", out var items)) { + _logger.LogInformation("Response has Items property, checking for Spotify playlists to update counts"); result = await UpdateSpotifyPlaylistCounts(result); } @@ -1896,6 +1897,8 @@ public class JellyfinController : ControllerBase var modified = false; var updatedItems = new List>(); + _logger.LogInformation("Checking {Count} items for Spotify playlists", itemsArray.Count); + foreach (var item in itemsArray) { var itemDict = JsonSerializer.Deserialize>(item.GetRawText()); @@ -1908,9 +1911,13 @@ public class JellyfinController : ControllerBase if (item.TryGetProperty("Id", out var idProp)) { var playlistId = idProp.GetString(); + _logger.LogDebug("Checking item with ID: {Id}", playlistId); + if (!string.IsNullOrEmpty(playlistId) && _spotifySettings.PlaylistIds.Any(id => id.Equals(playlistId, StringComparison.OrdinalIgnoreCase))) { + _logger.LogInformation("Found Spotify playlist: {Id}", playlistId); + // This is a Spotify playlist - get the actual track count var playlistIndex = _spotifySettings.PlaylistIds.FindIndex(id => id.Equals(playlistId, StringComparison.OrdinalIgnoreCase)); @@ -1921,10 +1928,15 @@ public class JellyfinController : ControllerBase var missingTracksKey = $"spotify:missing:{playlistName}"; var missingTracks = await _cache.GetAsync>(missingTracksKey); + _logger.LogInformation("Cache lookup for {Key}: {Count} tracks", + missingTracksKey, missingTracks?.Count ?? 0); + // Fallback to file cache if (missingTracks == null || missingTracks.Count == 0) { + _logger.LogInformation("Trying file cache for {Name}", playlistName); missingTracks = await LoadMissingTracksFromFile(playlistName); + _logger.LogInformation("File cache result: {Count} tracks", missingTracks?.Count ?? 0); } if (missingTracks != null && missingTracks.Count > 0) @@ -1932,9 +1944,13 @@ public class JellyfinController : ControllerBase // Update ChildCount to show the number of tracks we'll provide itemDict["ChildCount"] = missingTracks.Count; modified = true; - _logger.LogDebug("Updated ChildCount for Spotify playlist {Name} to {Count}", + _logger.LogInformation("✓ Updated ChildCount for Spotify playlist {Name} to {Count}", playlistName, missingTracks.Count); } + else + { + _logger.LogWarning("No missing tracks found for {Name}", playlistName); + } } } } @@ -1944,9 +1960,13 @@ public class JellyfinController : ControllerBase if (!modified) { + _logger.LogInformation("No Spotify playlists found to update"); return response; } + _logger.LogInformation("Modified {Count} Spotify playlists, rebuilding response", + updatedItems.Count(i => i.ContainsKey("ChildCount"))); + // Rebuild the response with updated items var responseDict = JsonSerializer.Deserialize>(response.RootElement.GetRawText()); if (responseDict != null)