Edit: I didn't see that this question was for MusicKit JS. Apologies.
I don't know how to delete the answer, so I'll leave it for someone else to find it helpful.
You can extract the song ID from the link by creating a URL component and getting the query items out of the component.
Here, the query parameter is "i" with the value 1035048414 as the song ID. You get the first query item and fetch the value out of it:
let components = URLComponents(string: "https://music.apple.com/us/album/take-on-me-1985-12-mix-2015-remastered/1035047659?i=1035048414")
guard let songID = components?.queryItems?.first?.value else { return }
print("SONG ID IS - \(songID)")
Now, you can just use a standard MusicCatalogResourceRequest
:
let request = MusicCatalogResourceRequest<Song>(matching: \.id, equalTo: MusicItemID(songID))
do {
let response = try await request.response()
print(response.description)
} catch {
print(error)
}
When I print it:
SONG ID IS - 1035048414
MusicCatalogResourceResponse<Song>(
items: [
Song(id: "1035048414", title: "Take On Me (1985 12" Mix) [2015 Remastered]", artistName: "a-ha")
]
)
I hope that helps!