rryam / MusadoraKit

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

Searching Catalog by Genre #5

Closed mjdierkes closed 2 years ago

mjdierkes commented 2 years ago

Hi Rudrank,

Great Package! Is it possible to search for songs by their Genre ID? I haven't been able to find anything regarding Genre search yet.

rudrankriyam commented 2 years ago

Hi there!

Thank you for appreciating MusadoraKit!

I am not sure there is any functionality like that in the Apple Music API.

However, you can get a chart for a particular genre that contains the most played songs:

var request = MusicCatalogChartRequest(types: [Song.self])
request.genre = "34"
let response = try await request.response()

print(response.songs)

Let me know what you think!

mjdierkes commented 2 years ago

Awesome! That works great!

Do you have a way to easily get all the available genres?

mjdierkes commented 2 years ago

Never mind, your blog helped out :) https://rudrank.blog/exploring-musickit-genres

rudrankriyam commented 2 years ago

Just want to bump up this issue again, MusadoraKit does not have the capability to fetch all the genres, right? @mjdierkes

rudrankriyam commented 2 years ago

In iOS 16, they have a new initializer for MusicCatalogResourceRequest for fetching the genres but they forgot to confirm the protocol MusicCatalogTopLevelResourceRequesting to Genre in the first beta.

To fetch the genres, all you will have to do is:

let request = MusicCatalogResourceRequest<Genre>() 
let response = try await request.response() 

print(response) // <-- MusicItemCollection<Genre>
rudrankriyam commented 2 years ago

Don't want to annoy you, but now you can get the catalog top chart genres simply by:

print(try await MusadoraKit.catalogTopChartsGenres())

Let me know what you think!