From 2bb1ffa581a326e6b6fd18fd284a020e263d88e5 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Tue, 3 Feb 2026 00:06:08 -0500 Subject: [PATCH] Fix Spotify playlist to return local tracks + external tracks Local tracks in Jellyfin playlist are now returned first, with matched external tracks (from squid.wtf) appended at the end. Previously the code tried to match local tracks by exact title/artist which often failed due to naming differences. --- allstarr/Controllers/JellyfinController.cs | 29 ++++++---------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index accbf47..330d6d7 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -2828,33 +2828,18 @@ public class JellyfinController : ControllerBase } } - // Build final track list in Spotify playlist order - var finalTracks = new List(); - foreach (var missingTrack in missingTracks) - { - // Check if we have it locally first - var existingTrack = existingTracks.FirstOrDefault(t => - t.Title.Equals(missingTrack.Title, StringComparison.OrdinalIgnoreCase) && - t.Artist.Equals(missingTrack.PrimaryArtist, StringComparison.OrdinalIgnoreCase)); - - if (existingTrack != null) - { - finalTracks.Add(existingTrack); - } - else if (matchedBySpotifyId.TryGetValue(missingTrack.SpotifyId, out var matchedTrack)) - { - finalTracks.Add(matchedTrack); - } - // Skip tracks we couldn't match - } + // Build final track list: local tracks first, then matched external tracks + // Local tracks are already in Jellyfin's playlist - just return them as-is + // Append external matches at the end for tracks the plugin couldn't find locally + var finalTracks = new List(existingTracks); + finalTracks.AddRange(matchedBySpotifyId.Values); await _cache.SetAsync(cacheKey, finalTracks, TimeSpan.FromHours(1)); - _logger.LogInformation("Final playlist: {Total} tracks ({Existing} local, {Matched} matched, {Missing} missing)", + _logger.LogInformation("Final playlist: {Total} tracks ({Existing} local + {Matched} external)", finalTracks.Count, existingTracks.Count, - matchedBySpotifyId.Count, - missingTracks.Count - existingTracks.Count - matchedBySpotifyId.Count); + matchedBySpotifyId.Count); return _responseBuilder.CreateItemsResponse(finalTracks); }