mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user