The ultimate companion to MusicKit.

Last update: May 19, 2022

MusadoraKit

The ultimate companion to MusicKit.

MusadoraKit Logo

Twitter Follow

MusadoraKit is a Swift framework that uses the latest MusicKit and Apple Music API, making it easy to integrate Apple Music into your app. It uses the new async/await pattern introduced in Swift 5.5. Currently, it is available for iOS 15.0+, macOS 12.0+, watchOS 8.0+ and tvOS 15.0+.

It goes well with my book on Exploring MusicKit and Apple Music API, as all the documentation and references are mentioned in the book. Otherwise, the code itself is well documented.

Support

You can support my open-source by buying my book, "Exploring MusicKit and Apple Music API" or by buying me a book!

Catalog

To easily access the Apple Music Catalog, you can use pre-defined methods from MusadoraKit. The method are similar across the music items.

Example of working with fetching a catalog song by its identifier:

let song = try await MusadoraKit.catalogSong(id: "1613834314", with: [.albums])

Example of searching the catalog:

let searchResponse = try await MusadoraKit.catalogSearch(for: "weeknd", types: [Song.self, Artist.self])

print(searchResponse.songs)
print(searchResponse.artists)

Library

While this is natively not available in MusicKit, you can fetch library resources using MusadoraKit that uses Apple Music API under the hood. The method are similar across the music items.

Example of fetching all library songs in alphabetical order:

let songs = try await MusadoraKit.librarySongs()

Example of searching the user's library:

let searchResponse = try await MusadoraKit.librarySearch(for: "hello", types: [Song.self])

print(searchResponse.songs)

Recommendations

You can take advantage of Apple's Music recommendation system and use it in your app. For example, to fetch the default recommendations:

let recommendations = try await MusadoraKit.recommendations()

guard let recommendation = recommendations.first else { return }

print(recommendation.albums)
print(recommendation.playlists)
print(recommendation.stations)

History

You can also fetch historial data from the user's library. For example, to get the recently played resources:

let recentlyPlayedItems = try await MusadoraKit.recentlyPlayed()

let recentlyPlayedAlbums: [Album] = recentlyPlayedItems.compactMap { item in
    guard case let .album(album) = item else { return nil }
    return album
}

MusicCatalogResourcesRequest:

To fetch multiple catalog music items by their identifiers in the same request. For example:

let request = MusicCatalogResourcesRequest(types: [.songs: ["1456313177"], .albums: ["1531125029", "1575203352"]])
let response = try await request.response()

print(response.songs)
print(response.albums)

MusicLibraryResourcesRequest:

To fetch multiple library music items by their identifiers in the same request. For example:

let request = MusicLibraryResourcesRequest(types: [.songs: ["i.pmzqzM0S2rl5N4L"], .playlists: ["p.PkxVBgps2zOdV3r"]])
let response = try await request.response()

print(response.songs)
print(response.playlists)

I hope you love working with MusadoraKit!

GitHub

https://github.com/rryam/MusadoraKit
You might also like...

Alby-installer-macos - The Extension and Companion Installer for Alby

Alby-installer-macos - The Extension and Companion Installer for Alby

Alby macOS Installer This is the Extension and Companion Installer for Alby. Cli

Mar 4, 2022

NFCMate - A NFC Companion built using Swift with CoreNFC Framework

NFCMate - A NFC Companion built using Swift with CoreNFC Framework

NFCMate NFCMate NFCMate is a NFC app written in Swift for iOS devices. Moreover,

Mar 14, 2022

Companion app and XCode extension for adding SwiftUI recipes to your code.

Companion app and XCode extension for adding SwiftUI recipes to your code.

SwiftUI Recipes Companion Free Companion app and XCode extension for adding SwiftUI recipes to your code. Choose from a rich selection of SwiftUI reci

May 7, 2022

A Jetpack-powered companion app for WooCommerce.

A Jetpack-powered companion app for WooCommerce.

for iOS A Jetpack-powered companion app for WooCommerce. Build Instructions • Documentation • Contributing • Automation • Security • Need Help? • Reso

May 16, 2022

An Elden Ring companion app using SwiftUI + GraphQL

The Roundtable The bustling hub area that exists outside of the Lands Between. A place to mingle with other adventurerers, craftsmen, resupply and dis

May 13, 2022
Comments
  • 1. Refactor MusicHistoryRequest and MusicRecommendationRequest to have albums, stations and playlists as properties

    With the current implementation, it feels confusing to use and get an array of albums from the items:

    var recentlyPlayedAlbums: [Album] = []
    
    let request = MusicHistoryRequest(for: .recentlyPlayed)
    let response = try await request.response()
    
    recentlyPlayedAlbums = response.items.compactMap { item in 
        switch item {
            case .album(let album): return album
            default: return nil
        }
    }
    

    It would be nice if you could directly fetch the items:

    var recentlyPlayedAlbums: Albums?
    
    let request = MusicHistoryRequest(for: .recentlyPlayed)
    let response = try await request.response()
    
    recentlyPlayedAlbums = response.albums
    
    Reviewed by rudrankriyam at 2022-04-20 19:55
  • 2. Add documentation for catalog resource requests

    There are many methods for each song, artists, albums, etc, making it easier to access the Apple Music catalog. Document the remaining music items like Curator, Stations, RadioShow and RecordLabel

    Reviewed by rudrankriyam at 2022-04-10 12:45
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible.
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible.

The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends UIView/NSView, NSArray, and NSLayoutConstrai

May 19, 2022
The ultimate spinning wheel view that supports dynamic content and rich customization.
The ultimate spinning wheel view that supports dynamic content and rich customization.

The ultimate spinning wheel control that supports dynamic content and rich customization. Main Features ?? Dynamic content, supports texts, images, an

May 17, 2022
Tictactoe-ultimatum - iOS implementation of Ultimate Tic-Tac-Toe game
Tictactoe-ultimatum - iOS implementation of Ultimate Tic-Tac-Toe game

TicTacToe Ultimatum An iOS app in Swift implementing the classic game of Ultimat

Jan 21, 2022
An original board game for 2 players, a mash-up of Sudoku and Ultimate Tic-Tac-Toe
An original board game for 2 players, a mash-up of Sudoku and Ultimate Tic-Tac-Toe

An original board game for 2 players, a mash-up of Sudoku and Ultimate Tic-Tac-Toe. It is implemented as an iOS app in Swift and C/C++

Feb 9, 2022
This is my copy of the "Ultimate Portfolio Project" tutorial series in Hacking with Swift+.

UltimatePortfolio This is my version of the "Ultimate Portfolio Project" tutorial series in Hacking with Swift+. I What have I learned in this series?

Mar 29, 2022
Animal Crossing New Horizon companion app in SwiftUI
Animal Crossing New Horizon companion app in SwiftUI

You can now download the app on the App Store! The best Animal Crossing New Horizons companion app! 最高の「あつまれ どうぶつの森」コンパニオンアプリ Animal Crossing New Hori

May 17, 2022
A travel companion for your apps, a solitaire friend for Walker
A travel companion for your apps, a solitaire friend for Walker

A travel companion for your apps, a solitaire friend for Walker. This library aims to make the job of using day to day animations easier, just with on

Apr 10, 2021
Infini-iOS - an InfiniTime Companion App for iOS

Infini-iOS - an InfiniTime Companion App for iOS This is a proof-of-concept, barely-functional iOS application to interact with your PineTime running

May 16, 2022
A companion app for after-cancer treatment patients

Amber - your smart companion We have developed the iOS app Amber - a companion for after-cancer treatment patients. It connects patients with their do

Oct 24, 2021
iOS Companion App for PineTime

InfiniLink - an InfiniTime Companion App for iOS This iOS application allows you to interact with your PineTime smartwatch running InfiniTime (and per

May 19, 2022