rryam / MusadoraKit

The ultimate companion to MusicKit.
http://exploringmusickit.com
MIT License
344 stars 22 forks source link

How to get charts data use MusadoraKit #3

Closed csmarku closed 2 years ago

csmarku commented 2 years ago

Hi rudrankriyam Thank you to made this wonderful project. I have bought your book to support you. And I want to know how to get apple music charts data use MusadoraKit

Thanks

rudrankriyam commented 2 years ago

Heya! Thank you so much for buying my book! I hugely appreciate it. I haven't updated the book with charts because I am now waiting if Apple may release it during WWDC '22.

Here is an example based on MusadoraKit:

let request = MusicCatalogChartRequest(for: [Song.self, Album.self])
let response = try await request.response()

guard let chartWithSongs = response.songs.first else { return }

print(chartWithSongs.name)
print(chartWithSongs.items) /// <-- Array of songs

guard let chartWithAlbums = response.albums.first else { return }

print(chartWithAlbums.name)
print(chartWithAlbums.items) /// <-- Array of albums

Note that the response returns different charts based on the type like songs or albums, and each chart has an array of the songs, albums, playlists, or music video