List of Genre IDs?

Hey All

I've been looking at adding a visual representation of the song's first genre in my app and therefor was wondering if there's a list available somewhere of all the Genre's available in MusicKit and their IDs

e.g. Genre(id: "21", name: "Rock", parent: Genre(id: "34", name: "Music"))

So my questions:

  1. Is there a list of all IDs?
  2. Are these IDs the same in every country?

The reason why I would want this is to have my visuals be safe for localization. For example: If I'd call my asset icon-electronic and then localize my app in dutch it would ask for icon-electronisch. I hope this makes sense and I hope I don't have to browse and save a list of all Genre's by hand haha

Replies

AFAIU, ID are the same whatever country. But the name is effectively localized.

See Get a Catalog Genre in this page: https://rudrank.blog/exploring-musickit-genres#genres

May be you could try with "all" ID to retrieve the list ?

for genreNum in 1...9999 {
    do {
        let genreID = String(genreNum) // "1263"
        let countryCode = try await MusicDataRequest.currentCountryCode
        // following code

Fair enough! I ran it with let request = MusicCatalogResourceRequest<Genre>(matching: \.id, equalTo: MusicItemID(genreID)) and found some but feels like a lot are missing (compared to the ones I get from Song.genreNames)

Hey, man. I have a short list of genre IDs in my open-source app here: https://github.com/adityasaravana/Tuneder/blob/main/Tuneder/GenreSelection.swift, if you want to borrow some of those, and here's a simple script I run when my app launches to collect some genre data.

func search(_ query: String) async {
        /// This code fetches the genres and ids of songs that that you enter in searchTerm, useful for adding more genres (See GenreSelection)
        do {
            let songSearch = try await MCatalog.search(for: query, types: [.songs], limit: 3)
            for song in songSearch.songs {
                let songDetailed = try await MCatalog.song(id: song.id, fetch: [.genres])
                
                for genre in songDetailed.genres! {
                    print("⚠️⚠️⚠️⚠️⚠️⚠️ GENRE NAME: \(genre.name), ID: \(genre.id) ⚠️⚠️⚠️⚠️⚠️⚠️")
                }
            }
        } catch {
            print("caught at MusicManager.searchQuery")
        }
    }
.onAppear {
            
#if DEBUG
            /// Finding the IDs of genres to add to GenreSelection.
            Task {
                await musicManager.search("jazz")
            }
#endif
            
        }

UPDATE: You need to import MusadoraKit for the code above to work; https://github.com/rryam/MusadoraKit