mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
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.
This commit is contained in:
@@ -2828,33 +2828,18 @@ public class JellyfinController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
// Build final track list in Spotify playlist order
|
||||
var finalTracks = new List<Song>();
|
||||
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<Song>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user