diff --git a/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs b/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs index fecaacd..b0c6ce8 100644 --- a/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs +++ b/allstarr/Services/SquidWTF/SquidWTFMetadataService.cs @@ -298,18 +298,21 @@ public class SquidWTFMetadataService : IMusicMetadataService var odesliJson = await odesliResponse.Content.ReadAsStringAsync(); var odesliDoc = JsonDocument.Parse(odesliJson); + // Extract Spotify track ID from the Spotify URL if (odesliDoc.RootElement.TryGetProperty("linksByPlatform", out var platforms) && platforms.TryGetProperty("spotify", out var spotifyPlatform) && - spotifyPlatform.TryGetProperty("entityUniqueId", out var spotifyIdEl)) + spotifyPlatform.TryGetProperty("url", out var spotifyUrlEl)) { - var rawSpotifyId = spotifyIdEl.GetString(); - // Odesli returns format "SPOTIFY_SONG::trackid", extract just the track ID - if (!string.IsNullOrEmpty(rawSpotifyId)) + var spotifyUrl = spotifyUrlEl.GetString(); + if (!string.IsNullOrEmpty(spotifyUrl)) { - song.SpotifyId = rawSpotifyId.Contains("::") - ? rawSpotifyId.Split("::")[1] - : rawSpotifyId; - _logger.LogInformation("✓ Converted squidwtf/{ExternalId} → Spotify ID {SpotifyId}", externalId, song.SpotifyId); + // Extract ID from URL: https://open.spotify.com/track/{id} + var match = System.Text.RegularExpressions.Regex.Match(spotifyUrl, @"spotify\.com/track/([a-zA-Z0-9]+)"); + if (match.Success) + { + song.SpotifyId = match.Groups[1].Value; + _logger.LogInformation("✓ Converted squidwtf/{ExternalId} → Spotify ID {SpotifyId}", externalId, song.SpotifyId); + } } } }