mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-10 07:58:39 -05:00
Add debug logging for Spotify playlist ChildCount updates
- Log when checking items for Spotify playlists - Log cache lookups and file cache fallbacks - Log successful ChildCount updates - Log when no Spotify playlists found - Helps diagnose why playlist counts might not be updating correctly
This commit is contained in:
@@ -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<Dictionary<string, object>>();
|
||||
|
||||
_logger.LogInformation("Checking {Count} items for Spotify playlists", itemsArray.Count);
|
||||
|
||||
foreach (var item in itemsArray)
|
||||
{
|
||||
var itemDict = JsonSerializer.Deserialize<Dictionary<string, object>>(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<List<allstarr.Models.Spotify.MissingTrack>>(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<Dictionary<string, object>>(response.RootElement.GetRawText());
|
||||
if (responseDict != null)
|
||||
|
||||
Reference in New Issue
Block a user