From 7e6bed51e166f9c32d63d2948a9396034cd7c133 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Sat, 7 Feb 2026 12:06:48 -0500 Subject: [PATCH] refactor: extract Spotify ID from URL instead of entityUniqueId - Use linksByPlatform.spotify.url from Odesli response - Extract track ID from Spotify URL using regex - More reliable than parsing entityUniqueId format - Matches the approach used in ConvertToSpotifyIdViaOdesliAsync --- .../SquidWTF/SquidWTFMetadataService.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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); + } } } }