The ultimate companion to MusicKit.

Overview

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!

Comments
  • LibraryPlaylistCreation - warnings.

    LibraryPlaylistCreation - warnings.

    My issue is regarding the two '#TODO' warning notes in the code.

    #warning("TODO: ADD RELATIONSHIPS") #warning("TODO: ADD OPTION TO ADD TRACKS.")

    When can we expect relationship and add track to playlist functions in the playlist class?

    Thanks!

    bug high-priority 
    opened by raymondwelch33 8
  • Value of type 'MusicCatalogSearchRequest' has no member 'includeTopResults'

    Value of type 'MusicCatalogSearchRequest' has no member 'includeTopResults'

    Just updated packages for MusadoraKit to latest with Xcode 13.4.1 and when I try to build, I get this error in CatalogSearch.swift:

    Value of type 'MusicCatalogSearchRequest' has no member 'includeTopResults'

    On line 74: request.includeTopResults = includeTopResults

    opened by aeip 4
  • Cannot find library song with MPMediaItem playbackStoreID

    Cannot find library song with MPMediaItem playbackStoreID

    I'm trying to convert a list of MPMediaItems to their cloud version but am I getting the following error from the below code:

    The specified music item could not be found for 1631024269.

    Code:

    @State var songs = [MPMediaItem]()
    
                let list = songs[0...19].map { MusicItemID(stringLiteral: $0.playbackStoreID) }
                let testSongs = try await MusadoraKit.librarySong(id: list[0])
                print(testSongs.title)
    

    I feel like it should work because MusadoraKit.librarySong(id: ) takes a MusicItemID. And I have received that from an MPMediaItem's playbackStoreID.

    Am I just searching with the wrong function from Musadora Kit? Thank you

    opened by aeip 3
  • Create an endpoint to add songs to an existing playlist

    Create an endpoint to add songs to an existing playlist

    I couldn't find an existing function to hit this url

    The response is an empty json and I couldn't think of any value in adding a return type to the function

    opened by bbauman1 2
  • Unable to use Artist Artwork

    Unable to use Artist Artwork

    I installed your package (amazing btw, I would love to talk to you about it) and I am no longer able to access the Artwork property on Artists. Any idea why?

    opened by Palumbo93 1
  • Get count of library items

    Get count of library items

    It would be nice to have a method to get a count of library items users have. For example, a count of total songs someone has in their library, a count of total number of playlists, etc.

    opened by aeip 1
  • How to get charts data use MusadoraKit

    How to get charts data use MusadoraKit

    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

    opened by csmarku 1
  • Refactor MusicHistoryRequest and MusicRecommendationRequest to have albums, stations and playlists as properties

    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
    
    enhancement 
    opened by rudrankriyam 0
  • Add documentation for catalog resource requests

    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

    documentation good first issue 
    opened by rudrankriyam 0
Releases(v1.9.4)
  • v1.9.4(Dec 30, 2022)

    Version 1.9.4

    Added more methods for adding to library (thanks to @bbauman1) + DoC documentation at https://rryam.github.io/MusadoraKit/documentation/musadorakit/

    It will be the last release of 2022. Amazing year. Hoping for a greater 2023! 🎊

    Source code(tar.gz)
    Source code(zip)
  • v1.9.3(Nov 23, 2022)

    Added more functionality to createPlaylist.

    Usage for adding any music item, whether it is a song, library song, music video, or a library music video.

    let librarySong = try await MusadoraKit.librarySong(id: "i.zpZeAOdFmZ0kMQo")
    let musicVideo = try await MusadoraKit.catalogMusicVideo(id: "1444338558")
    let song = try await MusadoraKit.catalogSong(id: "956135760")
    
    let playlist = try await MusadoraKit.createPlaylist(name: "TESTING ANY ITEMS", items: [song, librarySong, musicVideo])
    

    Usage for adding a collection of tracks as MusicItemCollection<Track>.

    var album = try await MusadoraKit.catalogAlbum(id: "1363309866").with(.tracks)
    
    var playlist = try await MusadoraKit.createPlaylist(name: "TESTING SEQUENCE", items: album.tracks!)
    

    Enjoy!

    Source code(tar.gz)
    Source code(zip)
  • v1.9.2(Nov 22, 2022)

  • v1.9.1(Nov 22, 2022)

    Added option to create playlist with songs for iOS 15.

    Usage:

    let song = try await MusadoraKit.catalogSong(id: "1651994123")
    let playlist = try await MusadoraKit.createPlaylist(name: "TESTING SONGS", items: .init(arrayLiteral: song))
    
    Source code(tar.gz)
    Source code(zip)
  • v1.9.0(Oct 6, 2022)

    Add LibraryPlaylist and libraryPlaylists() method.

    You can now directly fetch ALL playlists of a user in a single line:

    let playlists = try await MusadoraKit.libraryPlaylists()
    

    This method fetches the playlists from the user library. It is helpful when you are targeting iOS 15, and cannot use MusicLibraryRequest introduced in iOS 16, yet.

    Source code(tar.gz)
    Source code(zip)
  • v1.8.1(Aug 29, 2022)

  • v1.8.0(Aug 29, 2022)

    Add more methods for working with MusicKit easier and with fewer lines of code.

    Full Changelog: https://github.com/rryam/MusadoraKit/compare/v1.7.2...v1.8.0

    Source code(tar.gz)
    Source code(zip)
  • v1.7.2(Aug 11, 2022)

  • v1.7.1(Aug 5, 2022)

  • v1.7.0(Jul 23, 2022)

    Added methods for easily accessing all additional properties of a music item.

    For example,

    let song = try await MusadoraKit.catalogSong(id: id)
    

    will also fetch the additional properties - [.albums, .artists, .composers, .genres, .musicVideos, .artistURL, .station, .audioVariants].

    This way, you do not have to make two network calls. However, note that this is slower than fetching just the basic properties of a Song.

    Make sure you are using the method where there is no with parameter.

    Source code(tar.gz)
    Source code(zip)
  • v1.6.1(Jul 23, 2022)

  • v1.6.0(Jul 23, 2022)

  • v1.5.0(Jul 17, 2022)

    ⛔️ Breaking changes:

    The initializer of MusicAddResourcesRequest is an array of tuple now instead of a dictionary.

    Also, there are handy methods to add items to the user's music library:

    let _ = try await MusadoraKit.addAlbumToLibrary(id: id)
    

    Enjoy! 🎉

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jul 17, 2022)

  • v1.3.3(Jun 21, 2022)

    New in this release:

    Add catalog top charts genre. Use it to fetch all genres for the current top charts.

    let genres = try await MusadoraKit.catalogTopChartsGenres()
    print(genres) // <-- MusicItemCollection<Genre>
    
    Source code(tar.gz)
    Source code(zip)
  • v1.3.2(Jun 11, 2022)

  • v1.3.1(May 11, 2022)

  • v1.3.0(May 10, 2022)

    New in this Release

    You can now fetch an equivalent Apple Music catalog music item for a given music item in the user's library!

    Usage:

    let album = try await MusadoraKit.libraryAlbum(id: "l.uxuoDQh")
    let catalogAlbum = try await album.catalog
    
    print(catalogAlbum)
    
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Apr 23, 2022)

    New in this release

    Added MusicAddResourcesRequest and MusicDataPostRequest.

    Example usage to add a resource to the user's iCloud Music Library:

    let request = MusicAddResourcesRequest(types: [.songs: ["1619816360"]])
    let response = try await request.response()
    
    if response {
        print("SUCCESSFULLY ADDED OUT OF TIME BY THE WEEKND TO MY LIBRARY")
    }
    
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Apr 23, 2022)

    New in this release

    Add MusicCatalogResourcesRequest and MusicLibraryResourcesRequest to fetch multiple types in the same request.

    Example usage:

    MusicCatalogResourcesRequest:

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

    MusicLibraryResourcesRequest:

    let request = MusicLibraryResourcesRequest(types: [.songs: ["i.pmzqzM0S2rl5N4L"], .playlists: ["p.PkxVBgps2zOdV3r"]])
    let response = try await request.response()
    
    print(response.songs)
    print(response.playlists)
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Apr 23, 2022)

  • v1.0.1(Apr 22, 2022)

    New in this release

    Added recently played tracks and stations endpoints to MusicHistoryRequest. Now you can fetch it like:

    let stations = MusadoraKit.recentlyPlayedStations()
    let tracks = MusadoraKit.recentlyPlayedTracks()
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Apr 21, 2022)

    After 9 months of working late nights and weekends, I am proud to release MusadoraKit, the ultimate companion to MusicKit.

    It simplifies working with Apple Music API and MusicKit, and for you to easily integrate MusicKit into your app.

    Looking forward to your feedback!

    Source code(tar.gz)
    Source code(zip)
  • v0.9.1(Apr 20, 2022)

    MusicHistoryRequest & MusicRecommendationRequest directly support accessing properties:

    let request = MusicHistoryRequest(for: .recentlyPlayed)
    let response = try await request.response()
    print(response.albums)
    

    and

    let request = MusicRecommendationRequest()
    let response = try await request.response()
    
    guard let recommendation = response.items.first else { return }
    
    print(recommendation.stations)
    

    Enjoy! Thanks @aeip for bringing this enhancement to my attention!

    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Apr 14, 2022)

    Now that all the custom structures are done for suggestions, recommendations, history and charts, I have added more documentation everywhere.

    Very close to v1.0!

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Apr 10, 2022)

    Hi there!

    Another release for the day. I have added Curator, RadioShow, Station, and RecordLabel. Some are available from iOS 15.4 onwards, so do note that.

    Enjoy easily accessing the Apple Music catalog now!

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Apr 10, 2022)

    Hi there!

    MusadoraKit is finally shaping up, and I am releasing it as a beta! While the custom structures need more love, all the catalog methods are ready to be used in production!

    Let me know what you think!

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Apr 2, 2022)

    Hi there!

    After a year of experimenting with MusicKit, I slowly understand the framework better and the relevant structures and methods. While the framework is excellent, parts are still missing compared to the Apple Music API, specifically related to library items.

    MusadoraKit is my attempt to fill in the gap and provide a much better experience built on top of MusicKit. There are custom structures with similar implementation to MusicKit, which is the framework's alpha release!

    I will continue working on it every month and make it the ultimate Swift Package if you use MusicKit in your app!

    Source code(tar.gz)
    Source code(zip)
Owner
rudrank
Creating packages to user in your app
rudrank
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

PureLayout 7.6k Jan 6, 2023
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

Sherzod Khashimov 250 Dec 27, 2022
Tictactoe-ultimatum - iOS implementation of Ultimate Tic-Tac-Toe game

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

Max Khrapov 1 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. It is implemented as an iOS app in Swift and C/C++

Max Khrapov 10 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?

Justin Holt 0 Jun 16, 2022
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

Thomas Ricouard 1.6k Dec 29, 2022
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

Ramon Gilabert 97 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

null 141 Dec 24, 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

Alex Studnička 1 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

null 142 Dec 28, 2022
Alby-installer-macos - The Extension and Companion Installer for Alby

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

Alby 4 Mar 4, 2022
NFCMate - A NFC Companion built using Swift with CoreNFC Framework

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

Navemics 7 Nov 21, 2022
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

Gordan Glavaš 17 Nov 20, 2022
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

WooCommerce 196 Jan 8, 2023
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

Thomas Ricouard 45 Sep 25, 2022