Swiftpack.co - jjotaum/AmuseKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jjotaum.
jjotaum/AmuseKit 0.5.0
A swift package to facilitate Apple Music API integration for iOS, MacOS, tvOS & watchOS projects.
⭐️ 15
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/jjotaum/AmuseKit.git", from: "0.5.0")

AmuseKit

A swift package to facilitate Apple Music Api integration for iOS, MacOS, tvOS & watchOS projects.

USAGE

Import

import AmuseKit

Init AmuseKit provider.

You can initialize AmuseKit using a StorageConfiguration that specifies service name and keys that will be used to save developer token & user token on keychain.

let configuration = AmuseKit.StorageConfiguration(serviceName: "KEYCHAIN_SERVICE_NAME",
                                                  developerTokenKey: "DEV_TOKEN_KEYCHAIN_KEY",
                                                  userTokenKey: "USER_TOKEN_KEYCHAIN_KEY")
let amuseProvider = AmuseKit.DataProvider(configuration)
amuseProvider.setDeveloperToken("YOUR_DEV_TOKEN")

Set User Token.

amuseProvider.setUserToken("USER_TOKEN")

Set User Country Code.

amuseProvider.setUserCountryCode("USER_COUNTRY_CODE")

Retrieve Apple Music catalog resources by ids.

Supported values are: albums, artists, musicVideos, playlists, songs.

let response = try await amuseProvider.catalog(.albums, ids: ["123", "456", "789"])
print(response.data)
amuseProvider.catalog(.albums, ids: ["123", "456", "789"])
    .sink { _ in
    } receiveValue: { response in
        print(response.data)
    }

Search on Apple Music catalog.

let response = try await amuseProvider.catalogSearch(searchTerm: "YOUR_QUERY_TEXT")
print(response.results?.albums)
print(response.results?.artists)
print(response.results?.musicVideos)
print(response.results?.playlists)
print(response.results?.songs)
print(response.results?.stations)
amuseProvider.catalogSearch(searchTerm: "YOUR_QUERY_TEXT")
    .sink { _ in
    } receiveValue: { response in
        // content will be found under results properties.
        print(response.results?.albums)
        print(response.results?.artists)
        print(response.results?.musicVideos)
        print(response.results?.playlists)
        print(response.results?.songs)
        print(response.results?.stations)
    }

Search on Apple Music catalog for specific resources types.

let response = try await amuseProvider.catalogSearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
print(response.results?.playlists)
print(response.results?.songs)
amuseProvider.catalogSearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
    .sink { _ in
    } receiveValue: { response in
        print(response.results?.playlists)
        print(response.results?.songs)
    }

Retrieve User Library resources.

Supported values are: albums, artists, musicVideos, playlists, songs.

let response = try await dataProvider.library(.albums)
print(response.data)
amuseProvider.library(.albums)
    .sink { _ in
    } receiveValue: { response in
        print(response.data)
    }

Search on User Library.

let response = try await amuseProvider.librarySearch(searchTerm: "YOUR_QUERY_TEXT")
print(response.results?.albums)
print(response.results?.artists)
print(response.results?.musicVideos)
print(response.results?.playlists)
print(response.results?.songs)
amuseProvider.librarySearch(searchTerm: "YOUR_QUERY_TEXT")
    .sink { _ in
    } receiveValue: { response in
        // content will be found under results properties.
        print(response.results?.albums)
        print(response.results?.artists)
        print(response.results?.musicVideos)
        print(response.results?.playlists)
        print(response.results?.songs)
    }

Search on User Library for specific resources types.

let response = try await amuseProvider.librarySearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
print(response.results?.playlists)
print(response.results?.songs)
amuseProvider.librarySearch([.playlists, .songs], searchTerm: "YOUR_QUERY_TEXT")
    .sink { _ in
    } receiveValue: { response in
        print(response.results?.playlists)
        print(response.results?.songs)
    }

GitHub

link
Stars: 15
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.5.0
1 year ago

What's Changed

  • Refactor data provider service to use new request coordinator protocol
  • Rename catalog resources objects
  • Improve & restructure overall resources model definitions
  • Add async support to DataProvider class
  • Fix encapsulation issues
  • Add async support for search methods

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics