Hi! Im attempting to make a spotify to apple playlist converter and to do so am using the Catalog search functionality of the api. My question is, is there anyway to convert these songs to apple music urls (or ids) that does not spam api calls. I know you can batch catalog searches if you have apple music song ids, but I obviously dont have that since the song was shared from spotify. Any ideas/help is appreciated!
Post
Replies
Boosts
Views
Activity
Hi all, I am working with MusicKit and have managed to get a user's recommendation playlists (favorites, get up, etc). Isolating just one, I am trying to access the tracks in there using .tracks but it returns nothing. Wondering if I am doing something wrong or if these don't have tracks necessarily associated with them.
Code is below
(not everything just kinda where I am accessing the playlist)
try await requestMusicAuthorization()
let request = MusicPersonalRecommendationsRequest()
let response = try await request.response()
guard let madeForYou = response.recommendations.first(where: { $0.title == "Made for You" }) else {
throw NSError(domain: "RecommendationError", code: 0, userInfo: [NSLocalizedDescriptionKey: "No 'Made for You' recommendation found."])
}
guard let firstPlaylist = madeForYou.playlists.first else {
throw NSError(domain: "PlaylistError", code: 1, userInfo: [NSLocalizedDescriptionKey: "No playlists found in 'Made for You' recommendation."])
}
print("Fetching tracks for playlist: \(firstPlaylist.name ?? "Unknown")")
let playlistRequest = MusicCatalogResourceRequest<Playlist>(matching: \.id, equalTo: firstPlaylist.id)
let playlistResponse = try await playlistRequest.response()
guard let playlist = playlistResponse.items.first else {
throw NSError(domain: "PlaylistError", code: 2, userInfo: [NSLocalizedDescriptionKey: "Couldn't fetch the playlist details."])
}
guard let tracks = playlist.tracks else {
throw NSError(domain: "PlaylistError", code: 3, userInfo: [NSLocalizedDescriptionKey: "No tracks found in the playlist."])
}