diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index 4b8c7f1..4b540c1 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -2812,14 +2812,24 @@ public class JellyfinController : ControllerBase } // Only fetch from Jellyfin if we didn't get count from file cache - if (!itemDict.ContainsKey("ChildCount") || (int)itemDict["ChildCount"]! == 0) + if (!itemDict.ContainsKey("ChildCount") || + (itemDict["ChildCount"] is JsonElement childCountElement && childCountElement.GetInt32() == 0) || + (itemDict["ChildCount"] is int childCountInt && childCountInt == 0)) { // Get local tracks count from Jellyfin var localTracksCount = 0; try { + // Include UserId parameter to avoid 401 Unauthorized + var userId = _settings.UserId; + var playlistItemsUrl = $"Playlists/{playlistId}/Items"; + if (!string.IsNullOrEmpty(userId)) + { + playlistItemsUrl += $"?UserId={userId}"; + } + var (localTracksResponse, _) = await _proxyService.GetJsonAsync( - $"Playlists/{playlistId}/Items", + playlistItemsUrl, null, Request.Headers);