From 10e58eced9ac83e0d1a63c24df78dbd7b486e5e3 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Wed, 4 Feb 2026 18:23:11 -0500 Subject: [PATCH] fix: add authentication to playlist cache pre-building - PreBuildPlaylistItemsCacheAsync was failing with HTTP 401 - Background services don't have client headers for authentication - Now manually creates X-Emby-Authorization header with API key - Fixes 'Failed to fetch Jellyfin playlist items: HTTP 401' warning - Playlist items cache now builds successfully after track matching All 225 tests pass. --- .../Services/Spotify/SpotifyTrackMatchingService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs index d44c992..542d239 100644 --- a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs +++ b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs @@ -3,6 +3,7 @@ using allstarr.Models.Settings; using allstarr.Models.Spotify; using allstarr.Services.Common; using allstarr.Services.Jellyfin; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using System.Text.Json; @@ -701,8 +702,15 @@ public class SpotifyTrackMatchingService : BackgroundService return; } + // Create authentication headers for background service call + var headers = new HeaderDictionary(); + if (!string.IsNullOrEmpty(jellyfinSettings.ApiKey)) + { + headers["X-Emby-Authorization"] = $"MediaBrowser Token=\"{jellyfinSettings.ApiKey}\""; + } + var playlistItemsUrl = $"Playlists/{jellyfinPlaylistId}/Items?UserId={userId}&Fields=MediaSources"; - var (existingTracksResponse, statusCode) = await proxyService.GetJsonAsync(playlistItemsUrl, null, null); + var (existingTracksResponse, statusCode) = await proxyService.GetJsonAsync(playlistItemsUrl, null, headers); if (statusCode != 200 || existingTracksResponse == null) {