fix background service to use configured playlist names

This commit is contained in:
2026-01-31 19:44:47 -05:00
parent fb3ea1b876
commit 8ef5ee7d8f

View File

@@ -111,27 +111,15 @@ public class SpotifyMissingTracksFetcher : BackgroundService
{ {
_playlistIdToName.Clear(); _playlistIdToName.Clear();
using var scope = _serviceProvider.CreateScope(); // Use configured playlist names instead of fetching from API
var proxyService = scope.ServiceProvider.GetRequiredService<JellyfinProxyService>(); for (int i = 0; i < _spotifySettings.Value.PlaylistIds.Count; i++)
foreach (var playlistId in _spotifySettings.Value.PlaylistIds)
{ {
try var playlistId = _spotifySettings.Value.PlaylistIds[i];
{ var playlistName = i < _spotifySettings.Value.PlaylistNames.Count
var playlistInfo = await proxyService.GetJsonAsync($"Items/{playlistId}", null, null); ? _spotifySettings.Value.PlaylistNames[i]
if (playlistInfo != null && playlistInfo.RootElement.TryGetProperty("Name", out var nameElement)) : playlistId; // Fallback to ID if name not configured
{
var name = nameElement.GetString() ?? ""; _playlistIdToName[playlistId] = playlistName;
if (!string.IsNullOrEmpty(name))
{
_playlistIdToName[playlistId] = name;
}
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to get name for playlist {PlaylistId}", playlistId);
}
} }
} }