diff --git a/allstarr/Controllers/AdminController.cs b/allstarr/Controllers/AdminController.cs index 2c11ab4..1a38cdb 100644 --- a/allstarr/Controllers/AdminController.cs +++ b/allstarr/Controllers/AdminController.cs @@ -262,14 +262,21 @@ public class AdminController : ControllerBase foreach (var item in cachedPlaylistItems) { - // Check if it's a local track (has Path) or external (no Path) - if (item.TryGetValue("Path", out var pathObj) && pathObj != null) + // Check if it's external by looking for ProviderIds (external songs have this) + var isExternal = false; + if (item.TryGetValue("ProviderIds", out var providerIdsObj) && providerIdsObj != null) { - localCount++; + // Has ProviderIds = external track + isExternal = true; + } + + if (isExternal) + { + externalCount++; } else { - externalCount++; + localCount++; } } diff --git a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs index a60ccba..4828e92 100644 --- a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs +++ b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs @@ -302,12 +302,32 @@ public class SpotifyTrackMatchingService : BackgroundService // Check cache - use snapshot/timestamp to detect changes var existingMatched = await _cache.GetAsync>(matchedTracksKey); - if (existingMatched != null && existingMatched.Count >= tracksToMatch.Count) + + // Check if we have manual mappings that need to be preserved + var hasManualMappings = false; + foreach (var track in tracksToMatch) + { + var manualMappingKey = $"spotify:manual-map:{playlistName}:{track.SpotifyId}"; + var manualMapping = await _cache.GetAsync(manualMappingKey); + if (!string.IsNullOrEmpty(manualMapping)) + { + hasManualMappings = true; + break; + } + } + + // Skip if cache exists AND no manual mappings need to be applied + if (existingMatched != null && existingMatched.Count >= tracksToMatch.Count && !hasManualMappings) { _logger.LogInformation("Playlist {Playlist} already has {Count} matched tracks cached, skipping", playlistName, existingMatched.Count); return; } + + if (hasManualMappings) + { + _logger.LogInformation("Manual mappings detected for {Playlist}, rebuilding cache to apply them", playlistName); + } var matchedTracks = new List(); var isrcMatches = 0;