mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-10 07:58:39 -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
|
// Build final track list: local tracks first, then matched external tracks
|
||||||
var finalTracks = new List<Song>();
|
// Local tracks are already in Jellyfin's playlist - just return them as-is
|
||||||
foreach (var missingTrack in missingTracks)
|
// Append external matches at the end for tracks the plugin couldn't find locally
|
||||||
{
|
var finalTracks = new List<Song>(existingTracks);
|
||||||
// Check if we have it locally first
|
finalTracks.AddRange(matchedBySpotifyId.Values);
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
await _cache.SetAsync(cacheKey, finalTracks, TimeSpan.FromHours(1));
|
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,
|
finalTracks.Count,
|
||||||
existingTracks.Count,
|
existingTracks.Count,
|
||||||
matchedBySpotifyId.Count,
|
matchedBySpotifyId.Count);
|
||||||
missingTracks.Count - existingTracks.Count - matchedBySpotifyId.Count);
|
|
||||||
|
|
||||||
return _responseBuilder.CreateItemsResponse(finalTracks);
|
return _responseBuilder.CreateItemsResponse(finalTracks);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user