@wwdrew/expo-apple-music 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ATTRIBUTION.md +24 -0
- package/LICENSE +190 -0
- package/NOTICE +7 -0
- package/README.md +81 -0
- package/android/build.gradle +26 -0
- package/android/libs/mediaplayback-release-1.1.1.aar +0 -0
- package/android/libs/musickitauth-release-1.1.2.aar +0 -0
- package/android/src/main/AndroidManifest.xml +16 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidCatalogService.kt +86 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidDeveloperToken.kt +39 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidHistoryService.kt +24 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidLibraryMutationsService.kt +30 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidLibraryService.kt +61 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidPlaybackController.kt +484 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidPlaybackObserver.kt +173 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidQueueService.kt +78 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidRatingsService.kt +27 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidRecommendationsService.kt +15 -0
- package/android/src/main/java/expo/modules/applemusic/AndroidSubscriptionService.kt +24 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicErrorCodes.kt +13 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicErrors.kt +46 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicHttpMethod.kt +8 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicJsonMapper.kt +258 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicNativeLoader.kt +32 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicRestJson.kt +40 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicRestQuery.kt +12 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicRestStack.kt +19 -0
- package/android/src/main/java/expo/modules/applemusic/AppleMusicRestTransport.kt +118 -0
- package/android/src/main/java/expo/modules/applemusic/AuthenticatedSession.kt +57 -0
- package/android/src/main/java/expo/modules/applemusic/BridgeResponses.kt +55 -0
- package/android/src/main/java/expo/modules/applemusic/CatalogRestClient.kt +306 -0
- package/android/src/main/java/expo/modules/applemusic/ExpoAppleMusicModule.kt +152 -0
- package/android/src/main/java/expo/modules/applemusic/HistoryRestClient.kt +60 -0
- package/android/src/main/java/expo/modules/applemusic/LibraryIds.kt +6 -0
- package/android/src/main/java/expo/modules/applemusic/LibraryMutationsRestClient.kt +95 -0
- package/android/src/main/java/expo/modules/applemusic/LibraryRestClient.kt +195 -0
- package/android/src/main/java/expo/modules/applemusic/MusicKitAuthContract.kt +78 -0
- package/android/src/main/java/expo/modules/applemusic/MusicKitAuthStorage.kt +76 -0
- package/android/src/main/java/expo/modules/applemusic/MusicKitTokenProvider.kt +13 -0
- package/android/src/main/java/expo/modules/applemusic/PaginationOptions.kt +14 -0
- package/android/src/main/java/expo/modules/applemusic/RatingsRestClient.kt +72 -0
- package/android/src/main/java/expo/modules/applemusic/RecommendationsRestClient.kt +37 -0
- package/android/src/main/java/expo/modules/applemusic/StorefrontRestClient.kt +44 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeAuth.kt +69 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeCatalog.kt +76 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeHistory.kt +35 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeLibrary.kt +54 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeLibraryMutations.kt +30 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgePlayer.kt +89 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeRatings.kt +29 -0
- package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeRecommendations.kt +18 -0
- package/app.plugin.js +1 -0
- package/build/ExpoAppleMusicModule.web.d.ts +15 -0
- package/build/ExpoAppleMusicModule.web.d.ts.map +1 -0
- package/build/ExpoAppleMusicModule.web.js +33 -0
- package/build/ExpoAppleMusicModule.web.js.map +1 -0
- package/build/api/call-native.d.ts +6 -0
- package/build/api/call-native.d.ts.map +1 -0
- package/build/api/call-native.js +35 -0
- package/build/api/call-native.js.map +1 -0
- package/build/api/decode-jwt-exp.d.ts +5 -0
- package/build/api/decode-jwt-exp.d.ts.map +1 -0
- package/build/api/decode-jwt-exp.js +28 -0
- package/build/api/decode-jwt-exp.js.map +1 -0
- package/build/api/library-ids.d.ts +4 -0
- package/build/api/library-ids.d.ts.map +1 -0
- package/build/api/library-ids.js +11 -0
- package/build/api/library-ids.js.map +1 -0
- package/build/api/pagination.d.ts +12 -0
- package/build/api/pagination.d.ts.map +1 -0
- package/build/api/pagination.js +13 -0
- package/build/api/pagination.js.map +1 -0
- package/build/api/parse-authorize-result.d.ts +3 -0
- package/build/api/parse-authorize-result.d.ts.map +1 -0
- package/build/api/parse-authorize-result.js +27 -0
- package/build/api/parse-authorize-result.js.map +1 -0
- package/build/api/require-music-user-token.d.ts +2 -0
- package/build/api/require-music-user-token.d.ts.map +1 -0
- package/build/api/require-music-user-token.js +14 -0
- package/build/api/require-music-user-token.js.map +1 -0
- package/build/api/sync-developer-token.d.ts +4 -0
- package/build/api/sync-developer-token.d.ts.map +1 -0
- package/build/api/sync-developer-token.js +27 -0
- package/build/api/sync-developer-token.js.map +1 -0
- package/build/bridge/bridge-methods.d.ts +17 -0
- package/build/bridge/bridge-methods.d.ts.map +1 -0
- package/build/bridge/bridge-methods.js +71 -0
- package/build/bridge/bridge-methods.js.map +1 -0
- package/build/bridge/bridge-responses.d.ts +64 -0
- package/build/bridge/bridge-responses.d.ts.map +1 -0
- package/build/bridge/bridge-responses.js +67 -0
- package/build/bridge/bridge-responses.js.map +1 -0
- package/build/bridge/handlers/auth-bridge.d.ts +11 -0
- package/build/bridge/handlers/auth-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/auth-bridge.js +49 -0
- package/build/bridge/handlers/auth-bridge.js.map +1 -0
- package/build/bridge/handlers/catalog-bridge.d.ts +34 -0
- package/build/bridge/handlers/catalog-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/catalog-bridge.js +58 -0
- package/build/bridge/handlers/catalog-bridge.js.map +1 -0
- package/build/bridge/handlers/history-bridge.d.ts +19 -0
- package/build/bridge/handlers/history-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/history-bridge.js +31 -0
- package/build/bridge/handlers/history-bridge.js.map +1 -0
- package/build/bridge/handlers/index.d.ts +124 -0
- package/build/bridge/handlers/index.d.ts.map +1 -0
- package/build/bridge/handlers/index.js +21 -0
- package/build/bridge/handlers/index.js.map +1 -0
- package/build/bridge/handlers/library-bridge.d.ts +23 -0
- package/build/bridge/handlers/library-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/library-bridge.js +41 -0
- package/build/bridge/handlers/library-bridge.js.map +1 -0
- package/build/bridge/handlers/library-mutations-bridge.d.ts +16 -0
- package/build/bridge/handlers/library-mutations-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/library-mutations-bridge.js +20 -0
- package/build/bridge/handlers/library-mutations-bridge.js.map +1 -0
- package/build/bridge/handlers/player-bridge.d.ts +18 -0
- package/build/bridge/handlers/player-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/player-bridge.js +42 -0
- package/build/bridge/handlers/player-bridge.js.map +1 -0
- package/build/bridge/handlers/ratings-bridge.d.ts +15 -0
- package/build/bridge/handlers/ratings-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/ratings-bridge.js +16 -0
- package/build/bridge/handlers/ratings-bridge.js.map +1 -0
- package/build/bridge/handlers/recommendations-bridge.d.ts +10 -0
- package/build/bridge/handlers/recommendations-bridge.d.ts.map +1 -0
- package/build/bridge/handlers/recommendations-bridge.js +14 -0
- package/build/bridge/handlers/recommendations-bridge.js.map +1 -0
- package/build/constants/apple-music-error-codes.d.ts +22 -0
- package/build/constants/apple-music-error-codes.d.ts.map +1 -0
- package/build/constants/apple-music-error-codes.js +21 -0
- package/build/constants/apple-music-error-codes.js.map +1 -0
- package/build/hooks/use-current-song.d.ts +10 -0
- package/build/hooks/use-current-song.d.ts.map +1 -0
- package/build/hooks/use-current-song.js +35 -0
- package/build/hooks/use-current-song.js.map +1 -0
- package/build/hooks/use-is-playing.d.ts +6 -0
- package/build/hooks/use-is-playing.d.ts.map +1 -0
- package/build/hooks/use-is-playing.js +21 -0
- package/build/hooks/use-is-playing.js.map +1 -0
- package/build/hooks/use-playback-state.d.ts +12 -0
- package/build/hooks/use-playback-state.d.ts.map +1 -0
- package/build/hooks/use-playback-state.js +41 -0
- package/build/hooks/use-playback-state.js.map +1 -0
- package/build/index.d.ts +52 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +44 -0
- package/build/index.js.map +1 -0
- package/build/mappers/apple-music-json-mapper.d.ts +94 -0
- package/build/mappers/apple-music-json-mapper.d.ts.map +1 -0
- package/build/mappers/apple-music-json-mapper.js +212 -0
- package/build/mappers/apple-music-json-mapper.js.map +1 -0
- package/build/modules/auth.d.ts +32 -0
- package/build/modules/auth.d.ts.map +1 -0
- package/build/modules/auth.js +60 -0
- package/build/modules/auth.js.map +1 -0
- package/build/modules/catalog.d.ts +46 -0
- package/build/modules/catalog.d.ts.map +1 -0
- package/build/modules/catalog.js +47 -0
- package/build/modules/catalog.js.map +1 -0
- package/build/modules/history.d.ts +17 -0
- package/build/modules/history.d.ts.map +1 -0
- package/build/modules/history.js +28 -0
- package/build/modules/history.js.map +1 -0
- package/build/modules/library-mutations.d.ts +9 -0
- package/build/modules/library-mutations.d.ts.map +1 -0
- package/build/modules/library-mutations.js +41 -0
- package/build/modules/library-mutations.js.map +1 -0
- package/build/modules/library.d.ts +21 -0
- package/build/modules/library.d.ts.map +1 -0
- package/build/modules/library.js +38 -0
- package/build/modules/library.js.map +1 -0
- package/build/modules/player.d.ts +53 -0
- package/build/modules/player.d.ts.map +1 -0
- package/build/modules/player.js +68 -0
- package/build/modules/player.js.map +1 -0
- package/build/modules/ratings.d.ts +10 -0
- package/build/modules/ratings.d.ts.map +1 -0
- package/build/modules/ratings.js +37 -0
- package/build/modules/ratings.js.map +1 -0
- package/build/modules/recommendations.d.ts +7 -0
- package/build/modules/recommendations.d.ts.map +1 -0
- package/build/modules/recommendations.js +15 -0
- package/build/modules/recommendations.js.map +1 -0
- package/build/native-module.d.ts +5 -0
- package/build/native-module.d.ts.map +1 -0
- package/build/native-module.js +5 -0
- package/build/native-module.js.map +1 -0
- package/build/native-module.web.d.ts +11 -0
- package/build/native-module.web.d.ts.map +1 -0
- package/build/native-module.web.js +11 -0
- package/build/native-module.web.js.map +1 -0
- package/build/rest/apple-music-rest-stack.d.ts +21 -0
- package/build/rest/apple-music-rest-stack.d.ts.map +1 -0
- package/build/rest/apple-music-rest-stack.js +21 -0
- package/build/rest/apple-music-rest-stack.js.map +1 -0
- package/build/rest/apple-music-rest-transport.d.ts +8 -0
- package/build/rest/apple-music-rest-transport.d.ts.map +1 -0
- package/build/rest/apple-music-rest-transport.js +2 -0
- package/build/rest/apple-music-rest-transport.js.map +1 -0
- package/build/rest/catalog-rest-client.d.ts +38 -0
- package/build/rest/catalog-rest-client.d.ts.map +1 -0
- package/build/rest/catalog-rest-client.js +189 -0
- package/build/rest/catalog-rest-client.js.map +1 -0
- package/build/rest/history-rest-client.d.ts +37 -0
- package/build/rest/history-rest-client.d.ts.map +1 -0
- package/build/rest/history-rest-client.js +30 -0
- package/build/rest/history-rest-client.js.map +1 -0
- package/build/rest/library-ids.d.ts +2 -0
- package/build/rest/library-ids.d.ts.map +1 -0
- package/build/rest/library-ids.js +2 -0
- package/build/rest/library-ids.js.map +1 -0
- package/build/rest/library-mutations-rest-client.d.ts +22 -0
- package/build/rest/library-mutations-rest-client.d.ts.map +1 -0
- package/build/rest/library-mutations-rest-client.js +37 -0
- package/build/rest/library-mutations-rest-client.js.map +1 -0
- package/build/rest/library-rest-client.d.ts +59 -0
- package/build/rest/library-rest-client.d.ts.map +1 -0
- package/build/rest/library-rest-client.js +141 -0
- package/build/rest/library-rest-client.js.map +1 -0
- package/build/rest/ratings-rest-client.d.ts +18 -0
- package/build/rest/ratings-rest-client.d.ts.map +1 -0
- package/build/rest/ratings-rest-client.js +37 -0
- package/build/rest/ratings-rest-client.js.map +1 -0
- package/build/rest/recommendations-rest-client.d.ts +32 -0
- package/build/rest/recommendations-rest-client.d.ts.map +1 -0
- package/build/rest/recommendations-rest-client.js +26 -0
- package/build/rest/recommendations-rest-client.js.map +1 -0
- package/build/rest/resource-ids-query.d.ts +2 -0
- package/build/rest/resource-ids-query.d.ts.map +1 -0
- package/build/rest/resource-ids-query.js +10 -0
- package/build/rest/resource-ids-query.js.map +1 -0
- package/build/rest/rest-json.d.ts +11 -0
- package/build/rest/rest-json.d.ts.map +1 -0
- package/build/rest/rest-json.js +29 -0
- package/build/rest/rest-json.js.map +1 -0
- package/build/rest/storefront-rest-client.d.ts +14 -0
- package/build/rest/storefront-rest-client.d.ts.map +1 -0
- package/build/rest/storefront-rest-client.js +36 -0
- package/build/rest/storefront-rest-client.js.map +1 -0
- package/build/types/album.d.ts +8 -0
- package/build/types/album.d.ts.map +1 -0
- package/build/types/album.js +2 -0
- package/build/types/album.js.map +1 -0
- package/build/types/albums-response.d.ts +5 -0
- package/build/types/albums-response.d.ts.map +1 -0
- package/build/types/albums-response.js +2 -0
- package/build/types/albums-response.js.map +1 -0
- package/build/types/android-authorize-options.d.ts +18 -0
- package/build/types/android-authorize-options.d.ts.map +1 -0
- package/build/types/android-authorize-options.js +2 -0
- package/build/types/android-authorize-options.js.map +1 -0
- package/build/types/artist.d.ts +9 -0
- package/build/types/artist.d.ts.map +1 -0
- package/build/types/artist.js +2 -0
- package/build/types/artist.js.map +1 -0
- package/build/types/auth-status.d.ts +19 -0
- package/build/types/auth-status.d.ts.map +1 -0
- package/build/types/auth-status.js +18 -0
- package/build/types/auth-status.js.map +1 -0
- package/build/types/authorize-result.d.ts +8 -0
- package/build/types/authorize-result.d.ts.map +1 -0
- package/build/types/authorize-result.js +2 -0
- package/build/types/authorize-result.js.map +1 -0
- package/build/types/catalog-album-tracks.d.ts +5 -0
- package/build/types/catalog-album-tracks.d.ts.map +1 -0
- package/build/types/catalog-album-tracks.js +2 -0
- package/build/types/catalog-album-tracks.js.map +1 -0
- package/build/types/catalog-charts.d.ts +25 -0
- package/build/types/catalog-charts.d.ts.map +1 -0
- package/build/types/catalog-charts.js +7 -0
- package/build/types/catalog-charts.js.map +1 -0
- package/build/types/catalog-resource-type.d.ts +11 -0
- package/build/types/catalog-resource-type.d.ts.map +1 -0
- package/build/types/catalog-resource-type.js +10 -0
- package/build/types/catalog-resource-type.js.map +1 -0
- package/build/types/catalog-search.d.ts +24 -0
- package/build/types/catalog-search.d.ts.map +1 -0
- package/build/types/catalog-search.js +9 -0
- package/build/types/catalog-search.js.map +1 -0
- package/build/types/check-subscription.d.ts +31 -0
- package/build/types/check-subscription.d.ts.map +1 -0
- package/build/types/check-subscription.js +5 -0
- package/build/types/check-subscription.js.map +1 -0
- package/build/types/library-music-videos.d.ts +5 -0
- package/build/types/library-music-videos.d.ts.map +1 -0
- package/build/types/library-music-videos.js +2 -0
- package/build/types/library-music-videos.js.map +1 -0
- package/build/types/library-mutations.d.ts +21 -0
- package/build/types/library-mutations.d.ts.map +1 -0
- package/build/types/library-mutations.js +8 -0
- package/build/types/library-mutations.js.map +1 -0
- package/build/types/library-search.d.ts +22 -0
- package/build/types/library-search.d.ts.map +1 -0
- package/build/types/library-search.js +9 -0
- package/build/types/library-search.js.map +1 -0
- package/build/types/music-item.d.ts +8 -0
- package/build/types/music-item.d.ts.map +1 -0
- package/build/types/music-item.js +7 -0
- package/build/types/music-item.js.map +1 -0
- package/build/types/music-video.d.ts +8 -0
- package/build/types/music-video.d.ts.map +1 -0
- package/build/types/music-video.js +2 -0
- package/build/types/music-video.js.map +1 -0
- package/build/types/pagination.d.ts +11 -0
- package/build/types/pagination.d.ts.map +1 -0
- package/build/types/pagination.js +2 -0
- package/build/types/pagination.js.map +1 -0
- package/build/types/playback-state.d.ts +9 -0
- package/build/types/playback-state.d.ts.map +1 -0
- package/build/types/playback-state.js +2 -0
- package/build/types/playback-state.js.map +1 -0
- package/build/types/playback-status.d.ts +10 -0
- package/build/types/playback-status.d.ts.map +1 -0
- package/build/types/playback-status.js +9 -0
- package/build/types/playback-status.js.map +1 -0
- package/build/types/playlist.d.ts +15 -0
- package/build/types/playlist.d.ts.map +1 -0
- package/build/types/playlist.js +2 -0
- package/build/types/playlist.js.map +1 -0
- package/build/types/rating.d.ts +34 -0
- package/build/types/rating.d.ts.map +1 -0
- package/build/types/rating.js +26 -0
- package/build/types/rating.js.map +1 -0
- package/build/types/recent-resource.d.ts +11 -0
- package/build/types/recent-resource.d.ts.map +1 -0
- package/build/types/recent-resource.js +2 -0
- package/build/types/recent-resource.js.map +1 -0
- package/build/types/recommendation.d.ts +37 -0
- package/build/types/recommendation.d.ts.map +1 -0
- package/build/types/recommendation.js +2 -0
- package/build/types/recommendation.js.map +1 -0
- package/build/types/song.d.ts +8 -0
- package/build/types/song.d.ts.map +1 -0
- package/build/types/song.js +2 -0
- package/build/types/song.js.map +1 -0
- package/build/types/station.d.ts +9 -0
- package/build/types/station.d.ts.map +1 -0
- package/build/types/station.js +2 -0
- package/build/types/station.js.map +1 -0
- package/build/types/storefront.d.ts +4 -0
- package/build/types/storefront.d.ts.map +1 -0
- package/build/types/storefront.js +2 -0
- package/build/types/storefront.js.map +1 -0
- package/build/types/tracks-from-library.d.ts +11 -0
- package/build/types/tracks-from-library.d.ts.map +1 -0
- package/build/types/tracks-from-library.js +2 -0
- package/build/types/tracks-from-library.js.map +1 -0
- package/build/utils/apple-music-error.d.ts +10 -0
- package/build/utils/apple-music-error.d.ts.map +1 -0
- package/build/utils/apple-music-error.js +13 -0
- package/build/utils/apple-music-error.js.map +1 -0
- package/build/utils/get-error-message.d.ts +2 -0
- package/build/utils/get-error-message.d.ts.map +1 -0
- package/build/utils/get-error-message.js +21 -0
- package/build/utils/get-error-message.js.map +1 -0
- package/build/utils/is-library-item.d.ts +2 -0
- package/build/utils/is-library-item.d.ts.map +1 -0
- package/build/utils/is-library-item.js +4 -0
- package/build/utils/is-library-item.js.map +1 -0
- package/build/utils/normalize-resource-ids.d.ts +4 -0
- package/build/utils/normalize-resource-ids.d.ts.map +1 -0
- package/build/utils/normalize-resource-ids.js +12 -0
- package/build/utils/normalize-resource-ids.js.map +1 -0
- package/build/web/MusicKitLoader.d.ts +11 -0
- package/build/web/MusicKitLoader.d.ts.map +1 -0
- package/build/web/MusicKitLoader.js +135 -0
- package/build/web/MusicKitLoader.js.map +1 -0
- package/build/web/WebAppleMusicApiClient.d.ts +151 -0
- package/build/web/WebAppleMusicApiClient.d.ts.map +1 -0
- package/build/web/WebAppleMusicApiClient.js +139 -0
- package/build/web/WebAppleMusicApiClient.js.map +1 -0
- package/build/web/WebAppleMusicRestTransport.d.ts +9 -0
- package/build/web/WebAppleMusicRestTransport.d.ts.map +1 -0
- package/build/web/WebAppleMusicRestTransport.js +31 -0
- package/build/web/WebAppleMusicRestTransport.js.map +1 -0
- package/build/web/WebPlaybackController.d.ts +12 -0
- package/build/web/WebPlaybackController.d.ts.map +1 -0
- package/build/web/WebPlaybackController.js +90 -0
- package/build/web/WebPlaybackController.js.map +1 -0
- package/build/web/WebPlaybackObserver.d.ts +22 -0
- package/build/web/WebPlaybackObserver.d.ts.map +1 -0
- package/build/web/WebPlaybackObserver.js +106 -0
- package/build/web/WebPlaybackObserver.js.map +1 -0
- package/build/web/WebQueueService.d.ts +10 -0
- package/build/web/WebQueueService.d.ts.map +1 -0
- package/build/web/WebQueueService.js +53 -0
- package/build/web/WebQueueService.js.map +1 -0
- package/build/web/WebSubscriptionService.d.ts +7 -0
- package/build/web/WebSubscriptionService.d.ts.map +1 -0
- package/build/web/WebSubscriptionService.js +24 -0
- package/build/web/WebSubscriptionService.js.map +1 -0
- package/build/web/apple-music-errors.d.ts +11 -0
- package/build/web/apple-music-errors.d.ts.map +1 -0
- package/build/web/apple-music-errors.js +31 -0
- package/build/web/apple-music-errors.js.map +1 -0
- package/build/web/extract-music-user-token.d.ts +4 -0
- package/build/web/extract-music-user-token.d.ts.map +1 -0
- package/build/web/extract-music-user-token.js +15 -0
- package/build/web/extract-music-user-token.js.map +1 -0
- package/build/web/map-auth-status.d.ts +17 -0
- package/build/web/map-auth-status.d.ts.map +1 -0
- package/build/web/map-auth-status.js +85 -0
- package/build/web/map-auth-status.js.map +1 -0
- package/build/web/music-kit-api.d.ts +18 -0
- package/build/web/music-kit-api.d.ts.map +1 -0
- package/build/web/music-kit-api.js +120 -0
- package/build/web/music-kit-api.js.map +1 -0
- package/build/web/musickit-types.d.ts +70 -0
- package/build/web/musickit-types.d.ts.map +1 -0
- package/build/web/musickit-types.js +3 -0
- package/build/web/musickit-types.js.map +1 -0
- package/build/web/pagination.d.ts +2 -0
- package/build/web/pagination.d.ts.map +1 -0
- package/build/web/pagination.js +2 -0
- package/build/web/pagination.js.map +1 -0
- package/expo-module.config.json +19 -0
- package/ios/AppleMusicBridgeError.swift +60 -0
- package/ios/AppleMusicErrorCodes.swift +11 -0
- package/ios/AppleMusicRestClient.swift +213 -0
- package/ios/AuthenticatedSession.swift +64 -0
- package/ios/BridgePagination.swift +17 -0
- package/ios/BridgeResponses.swift +82 -0
- package/ios/CatalogSearchStore.swift +13 -0
- package/ios/CatalogSearchStoreFactory.swift +31 -0
- package/ios/CatalogService.swift +307 -0
- package/ios/ExpoAppleMusic.podspec +29 -0
- package/ios/ExpoAppleMusicModule.swift +505 -0
- package/ios/HistoryService.swift +53 -0
- package/ios/LibraryMutationsService.swift +63 -0
- package/ios/LibraryService.swift +313 -0
- package/ios/MusicItemMapper.swift +171 -0
- package/ios/MusicKitAuthStorage.swift +38 -0
- package/ios/MusicKitCatalogSearchStore.swift +62 -0
- package/ios/PlaybackController.swift +201 -0
- package/ios/PlaybackObserver.swift +225 -0
- package/ios/QueueService.swift +166 -0
- package/ios/RatingsService.swift +66 -0
- package/ios/RecommendationsService.swift +34 -0
- package/ios/RestCatalogSearchStore.swift +62 -0
- package/ios/RestJsonMapper.swift +268 -0
- package/ios/StorefrontService.swift +55 -0
- package/ios/SubscriptionService.swift +119 -0
- package/ios/bridge/ExpoBridgeCatalog.swift +98 -0
- package/ios/bridge/ExpoBridgeHistory.swift +71 -0
- package/ios/bridge/ExpoBridgeLibrary.swift +93 -0
- package/ios/bridge/ExpoBridgeRecommendations.swift +28 -0
- package/package.json +89 -0
- package/plugin/build/index.d.ts +5 -0
- package/plugin/build/index.js +10 -0
- package/plugin/build/with-expo-apple-music.d.ts +10 -0
- package/plugin/build/with-expo-apple-music.js +50 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.Dispatchers
|
|
4
|
+
import kotlinx.coroutines.withContext
|
|
5
|
+
|
|
6
|
+
/** History-domain Apple Music REST (recently played, heavy rotation). */
|
|
7
|
+
internal class HistoryRestClient(
|
|
8
|
+
private val transport: AppleMusicRestTransport,
|
|
9
|
+
) {
|
|
10
|
+
suspend fun getRecentlyPlayed(musicUserToken: String): List<Map<String, Any?>> =
|
|
11
|
+
withContext(Dispatchers.IO) {
|
|
12
|
+
val json =
|
|
13
|
+
transport.getJson(musicUserToken, "/v1/me/recent/played", mapOf("limit" to "10"))
|
|
14
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentlyPlayed(it) }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
suspend fun getRecentlyPlayedTracks(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
|
|
18
|
+
withContext(Dispatchers.IO) {
|
|
19
|
+
val json =
|
|
20
|
+
transport.getJson(
|
|
21
|
+
musicUserToken,
|
|
22
|
+
"/v1/me/recent/played/tracks",
|
|
23
|
+
mapOf("limit" to limit.toString()),
|
|
24
|
+
)
|
|
25
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapSong(it) }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
suspend fun getHeavyRotation(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
|
|
29
|
+
withContext(Dispatchers.IO) {
|
|
30
|
+
val json =
|
|
31
|
+
transport.getJson(
|
|
32
|
+
musicUserToken,
|
|
33
|
+
"/v1/me/history/heavy-rotation",
|
|
34
|
+
mapOf("limit" to limit.toString()),
|
|
35
|
+
)
|
|
36
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentResource(it) }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
suspend fun getRecentlyPlayedStations(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
|
|
40
|
+
withContext(Dispatchers.IO) {
|
|
41
|
+
val json =
|
|
42
|
+
transport.getJson(
|
|
43
|
+
musicUserToken,
|
|
44
|
+
"/v1/me/recent/radio-stations",
|
|
45
|
+
mapOf("limit" to limit.toString()),
|
|
46
|
+
)
|
|
47
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapStation(it) }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
suspend fun getRecentlyAdded(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
51
|
+
withContext(Dispatchers.IO) {
|
|
52
|
+
val json =
|
|
53
|
+
transport.getJson(
|
|
54
|
+
musicUserToken,
|
|
55
|
+
"/v1/me/library/recently-added",
|
|
56
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
57
|
+
)
|
|
58
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentResource(it) }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.Dispatchers
|
|
4
|
+
import kotlinx.coroutines.withContext
|
|
5
|
+
import org.json.JSONArray
|
|
6
|
+
import org.json.JSONObject
|
|
7
|
+
|
|
8
|
+
/** Library write/mutation Apple Music REST. */
|
|
9
|
+
internal class LibraryMutationsRestClient(
|
|
10
|
+
private val transport: AppleMusicRestTransport,
|
|
11
|
+
) {
|
|
12
|
+
suspend fun addToLibrary(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
|
|
13
|
+
withContext(Dispatchers.IO) {
|
|
14
|
+
transport.request(
|
|
15
|
+
musicUserToken,
|
|
16
|
+
AppleMusicHttpMethod.POST,
|
|
17
|
+
"/v1/me/library",
|
|
18
|
+
query = buildIdsQuery(resourceIds),
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
suspend fun createLibraryPlaylist(
|
|
23
|
+
musicUserToken: String,
|
|
24
|
+
name: String,
|
|
25
|
+
description: String?,
|
|
26
|
+
isPublic: Boolean,
|
|
27
|
+
tracks: List<Map<String, String>>?,
|
|
28
|
+
): Map<String, Any?> =
|
|
29
|
+
withContext(Dispatchers.IO) {
|
|
30
|
+
val attributes =
|
|
31
|
+
JSONObject()
|
|
32
|
+
.put("name", name)
|
|
33
|
+
.put("isPublic", isPublic)
|
|
34
|
+
if (!description.isNullOrBlank()) {
|
|
35
|
+
attributes.put(
|
|
36
|
+
"description",
|
|
37
|
+
JSONObject().put("standard", description),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
val payload = JSONObject().put("attributes", attributes)
|
|
42
|
+
if (!tracks.isNullOrEmpty()) {
|
|
43
|
+
val trackData = JSONArray()
|
|
44
|
+
tracks.forEach { track ->
|
|
45
|
+
trackData.put(
|
|
46
|
+
JSONObject()
|
|
47
|
+
.put("id", track["id"])
|
|
48
|
+
.put("type", track["type"]),
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
payload.put(
|
|
52
|
+
"relationships",
|
|
53
|
+
JSONObject().put(
|
|
54
|
+
"tracks",
|
|
55
|
+
JSONObject().put("data", trackData),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
val json =
|
|
61
|
+
transport.request(
|
|
62
|
+
musicUserToken,
|
|
63
|
+
AppleMusicHttpMethod.POST,
|
|
64
|
+
"/v1/me/library/playlists",
|
|
65
|
+
body = payload,
|
|
66
|
+
)
|
|
67
|
+
val data = requireDataArray(json)
|
|
68
|
+
if (data.length() == 0) {
|
|
69
|
+
throw AppleMusicErrors.apiError("Create playlist returned no data")
|
|
70
|
+
}
|
|
71
|
+
AppleMusicJsonMapper.mapPlaylist(data.getJSONObject(0))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
suspend fun addTracksToLibraryPlaylist(
|
|
75
|
+
musicUserToken: String,
|
|
76
|
+
playlistId: String,
|
|
77
|
+
tracks: List<Map<String, String>>,
|
|
78
|
+
): Unit =
|
|
79
|
+
withContext(Dispatchers.IO) {
|
|
80
|
+
val trackData = JSONArray()
|
|
81
|
+
tracks.forEach { track ->
|
|
82
|
+
trackData.put(
|
|
83
|
+
JSONObject()
|
|
84
|
+
.put("id", track["id"])
|
|
85
|
+
.put("type", track["type"]),
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
transport.request(
|
|
89
|
+
musicUserToken,
|
|
90
|
+
AppleMusicHttpMethod.POST,
|
|
91
|
+
"/v1/me/library/playlists/$playlistId/tracks",
|
|
92
|
+
body = JSONObject().put("data", trackData),
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.Dispatchers
|
|
4
|
+
import kotlinx.coroutines.withContext
|
|
5
|
+
import org.json.JSONArray
|
|
6
|
+
import org.json.JSONObject
|
|
7
|
+
|
|
8
|
+
/** Library-domain Apple Music REST (user collection reads + playback id resolution). */
|
|
9
|
+
internal class LibraryRestClient(
|
|
10
|
+
private val transport: AppleMusicRestTransport,
|
|
11
|
+
) {
|
|
12
|
+
suspend fun getLibraryPlaylists(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
13
|
+
withContext(Dispatchers.IO) {
|
|
14
|
+
val json =
|
|
15
|
+
transport.getJson(
|
|
16
|
+
musicUserToken,
|
|
17
|
+
"/v1/me/library/playlists",
|
|
18
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
19
|
+
)
|
|
20
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapPlaylist(it) }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
suspend fun getLibrarySongs(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
24
|
+
withContext(Dispatchers.IO) {
|
|
25
|
+
val json =
|
|
26
|
+
transport.getJson(
|
|
27
|
+
musicUserToken,
|
|
28
|
+
"/v1/me/library/songs",
|
|
29
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
30
|
+
)
|
|
31
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapSong(it) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
suspend fun getPlaylistTracks(musicUserToken: String, playlistId: String): List<Map<String, Any?>> =
|
|
35
|
+
withContext(Dispatchers.IO) {
|
|
36
|
+
val json = transport.getJson(
|
|
37
|
+
musicUserToken,
|
|
38
|
+
"/v1/me/library/playlists/$playlistId/tracks")
|
|
39
|
+
val data = requireDataArray(json)
|
|
40
|
+
buildList {
|
|
41
|
+
for (i in 0 until data.length()) {
|
|
42
|
+
val resource = data.getJSONObject(i)
|
|
43
|
+
if (resource.optString("type", "").contains("song")) {
|
|
44
|
+
add(AppleMusicJsonMapper.mapSong(resource))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun librarySearchTypeParam(type: String): String? =
|
|
51
|
+
when (type) {
|
|
52
|
+
"library-songs", "songs" -> "library-songs"
|
|
53
|
+
"library-albums", "albums" -> "library-albums"
|
|
54
|
+
"library-artists", "artists" -> "library-artists"
|
|
55
|
+
"library-playlists", "playlists" -> "library-playlists"
|
|
56
|
+
"library-music-videos", "music-videos", "musicVideos" -> "library-music-videos"
|
|
57
|
+
else -> null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
suspend fun getLibraryArtists(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
61
|
+
withContext(Dispatchers.IO) {
|
|
62
|
+
val json =
|
|
63
|
+
transport.getJson(
|
|
64
|
+
musicUserToken,
|
|
65
|
+
"/v1/me/library/artists",
|
|
66
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
67
|
+
)
|
|
68
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapArtist(it) }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
suspend fun getLibraryAlbums(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
72
|
+
withContext(Dispatchers.IO) {
|
|
73
|
+
val json =
|
|
74
|
+
transport.getJson(
|
|
75
|
+
musicUserToken,
|
|
76
|
+
"/v1/me/library/albums",
|
|
77
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
78
|
+
)
|
|
79
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapAlbum(it) }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
data class LibrarySearchResult(
|
|
83
|
+
val songs: List<Map<String, Any?>>,
|
|
84
|
+
val albums: List<Map<String, Any?>>,
|
|
85
|
+
val artists: List<Map<String, Any?>>,
|
|
86
|
+
val playlists: List<Map<String, Any?>>,
|
|
87
|
+
val musicVideos: List<Map<String, Any?>>,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
suspend fun getLibraryMusicVideos(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
|
|
91
|
+
withContext(Dispatchers.IO) {
|
|
92
|
+
val json =
|
|
93
|
+
transport.getJson(
|
|
94
|
+
musicUserToken,
|
|
95
|
+
"/v1/me/library/music-videos",
|
|
96
|
+
mapOf("limit" to limit.toString(), "offset" to offset.toString()),
|
|
97
|
+
)
|
|
98
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapMusicVideo(it) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
suspend fun searchLibrary(
|
|
102
|
+
musicUserToken: String,
|
|
103
|
+
term: String,
|
|
104
|
+
types: List<String>,
|
|
105
|
+
limit: Int,
|
|
106
|
+
offset: Int,
|
|
107
|
+
): LibrarySearchResult =
|
|
108
|
+
withContext(Dispatchers.IO) {
|
|
109
|
+
val typeParam =
|
|
110
|
+
types
|
|
111
|
+
.mapNotNull { librarySearchTypeParam(it) }
|
|
112
|
+
.distinct()
|
|
113
|
+
.sorted()
|
|
114
|
+
.joinToString(",")
|
|
115
|
+
.ifEmpty { "library-songs,library-albums" }
|
|
116
|
+
|
|
117
|
+
val json =
|
|
118
|
+
transport.getJson(
|
|
119
|
+
musicUserToken,
|
|
120
|
+
"/v1/me/library/search",
|
|
121
|
+
mapOf(
|
|
122
|
+
"term" to term,
|
|
123
|
+
"types" to typeParam,
|
|
124
|
+
"limit" to limit.toString(),
|
|
125
|
+
"offset" to offset.toString(),
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
val results = json.optJSONObject("results") ?: JSONObject()
|
|
130
|
+
LibrarySearchResult(
|
|
131
|
+
songs =
|
|
132
|
+
mapResourceArray(results.optJSONObject("library-songs")?.optJSONArray("data")) {
|
|
133
|
+
AppleMusicJsonMapper.mapSong(it)
|
|
134
|
+
},
|
|
135
|
+
albums =
|
|
136
|
+
mapResourceArray(results.optJSONObject("library-albums")?.optJSONArray("data")) {
|
|
137
|
+
AppleMusicJsonMapper.mapAlbum(it)
|
|
138
|
+
},
|
|
139
|
+
artists =
|
|
140
|
+
mapResourceArray(results.optJSONObject("library-artists")?.optJSONArray("data")) {
|
|
141
|
+
AppleMusicJsonMapper.mapArtist(it)
|
|
142
|
+
},
|
|
143
|
+
playlists =
|
|
144
|
+
mapResourceArray(results.optJSONObject("library-playlists")?.optJSONArray("data")) {
|
|
145
|
+
AppleMusicJsonMapper.mapPlaylist(it)
|
|
146
|
+
},
|
|
147
|
+
musicVideos =
|
|
148
|
+
mapResourceArray(results.optJSONObject("library-music-videos")?.optJSONArray("data")) {
|
|
149
|
+
AppleMusicJsonMapper.mapMusicVideo(it)
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
suspend fun probeLibraryAccess(musicUserToken: String): Boolean =
|
|
155
|
+
withContext(Dispatchers.IO) {
|
|
156
|
+
try {
|
|
157
|
+
transport.getJson(
|
|
158
|
+
musicUserToken,
|
|
159
|
+
"/v1/me/library/songs", mapOf("limit" to "1"))
|
|
160
|
+
true
|
|
161
|
+
} catch (_: Exception) {
|
|
162
|
+
false
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
suspend fun resolveCatalogPlaybackId(musicUserToken: String, libraryId: String, mediaType: String): String =
|
|
167
|
+
withContext(Dispatchers.IO) {
|
|
168
|
+
val path =
|
|
169
|
+
when (mediaType) {
|
|
170
|
+
"song" -> "/v1/me/library/songs/$libraryId"
|
|
171
|
+
"album" -> "/v1/me/library/albums/$libraryId"
|
|
172
|
+
"playlist" -> "/v1/me/library/playlists/$libraryId"
|
|
173
|
+
else -> throw AppleMusicErrors.unknownMediaType(mediaType)
|
|
174
|
+
}
|
|
175
|
+
val json = transport.getJson(musicUserToken, path)
|
|
176
|
+
val resource = json.getJSONArray("data").getJSONObject(0)
|
|
177
|
+
AppleMusicJsonMapper.catalogPlaybackId(resource)
|
|
178
|
+
?: throw AppleMusicErrors.itemNotFound(mediaType.replaceFirstChar { it.uppercase() }, true)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
suspend fun resolveLibrarySongCatalogIds(musicUserToken: String, playlistId: String): List<String> =
|
|
182
|
+
withContext(Dispatchers.IO) {
|
|
183
|
+
val json = transport.getJson(
|
|
184
|
+
musicUserToken,
|
|
185
|
+
"/v1/me/library/playlists/$playlistId/tracks")
|
|
186
|
+
val data = requireDataArray(json)
|
|
187
|
+
buildList {
|
|
188
|
+
for (i in 0 until data.length()) {
|
|
189
|
+
val resource = data.getJSONObject(i)
|
|
190
|
+
if (!resource.optString("type", "").contains("song")) continue
|
|
191
|
+
AppleMusicJsonMapper.catalogPlaybackId(resource)?.let { add(it) }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import com.apple.android.sdk.authentication.AuthenticationFactory
|
|
7
|
+
import com.apple.android.sdk.authentication.TokenError
|
|
8
|
+
import com.apple.android.sdk.authentication.TokenResult
|
|
9
|
+
import expo.modules.kotlin.activityresult.AppContextActivityResultContract
|
|
10
|
+
import java.io.Serializable
|
|
11
|
+
|
|
12
|
+
internal data class MusicKitAuthInput(
|
|
13
|
+
val developerToken: String,
|
|
14
|
+
val startScreenMessage: String? = null,
|
|
15
|
+
val hideStartScreen: Boolean = false,
|
|
16
|
+
) : Serializable
|
|
17
|
+
|
|
18
|
+
internal data class MusicKitAuthOutput(
|
|
19
|
+
val status: String,
|
|
20
|
+
val musicUserToken: String? = null,
|
|
21
|
+
) : Serializable
|
|
22
|
+
|
|
23
|
+
internal class MusicKitAuthContract(
|
|
24
|
+
private val contextProvider: () -> Context,
|
|
25
|
+
) : AppContextActivityResultContract<MusicKitAuthInput, MusicKitAuthOutput> {
|
|
26
|
+
override fun createIntent(context: Context, input: MusicKitAuthInput): Intent {
|
|
27
|
+
val manager = AuthenticationFactory.createAuthenticationManager(context)
|
|
28
|
+
val builder =
|
|
29
|
+
manager
|
|
30
|
+
.createIntentBuilder(input.developerToken)
|
|
31
|
+
.setHideStartScreen(input.hideStartScreen)
|
|
32
|
+
|
|
33
|
+
if (!input.hideStartScreen) {
|
|
34
|
+
val message = input.startScreenMessage?.trim()
|
|
35
|
+
if (!message.isNullOrEmpty()) {
|
|
36
|
+
builder.setStartScreenMessage(message)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return builder.build()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override fun parseResult(
|
|
44
|
+
input: MusicKitAuthInput,
|
|
45
|
+
resultCode: Int,
|
|
46
|
+
intent: Intent?,
|
|
47
|
+
): MusicKitAuthOutput {
|
|
48
|
+
// SDK cancel paths: upsell X (USER_CANCELLED intent), Apple Music back (no intent / empty token).
|
|
49
|
+
if (intent == null) {
|
|
50
|
+
return MusicKitAuthOutput(status = "denied")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
val manager = AuthenticationFactory.createAuthenticationManager(contextProvider())
|
|
54
|
+
return mapTokenResult(manager.handleTokenResult(intent))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fun mapTokenResult(result: TokenResult): MusicKitAuthOutput {
|
|
58
|
+
if (result.isError) {
|
|
59
|
+
val status =
|
|
60
|
+
when (result.error) {
|
|
61
|
+
TokenError.USER_CANCELLED -> "denied"
|
|
62
|
+
TokenError.NO_SUBSCRIPTION, TokenError.SUBSCRIPTION_EXPIRED -> "restricted"
|
|
63
|
+
TokenError.TOKEN_FETCH_ERROR -> "unknown"
|
|
64
|
+
// handleTokenResult() uses UNKNOWN when the intent has no token or error extras.
|
|
65
|
+
TokenError.UNKNOWN -> "denied"
|
|
66
|
+
}
|
|
67
|
+
return MusicKitAuthOutput(status = status)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
val token = result.musicUserToken
|
|
71
|
+
if (token.isNullOrBlank()) {
|
|
72
|
+
// Apple Music cancel can return RESULT_OK with an empty music_user_token extra.
|
|
73
|
+
return MusicKitAuthOutput(status = "denied")
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return MusicKitAuthOutput(status = "authorized", musicUserToken = token)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
internal object MusicKitAuthStorage {
|
|
6
|
+
private const val PREFS_NAME = "expo.modules.applemusic.auth"
|
|
7
|
+
private const val KEY_DEVELOPER_TOKEN = "developerToken"
|
|
8
|
+
private const val KEY_MUSIC_USER_TOKEN = "musicUserToken"
|
|
9
|
+
|
|
10
|
+
fun saveDeveloperToken(context: Context, token: String) {
|
|
11
|
+
context
|
|
12
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
13
|
+
.edit()
|
|
14
|
+
.putString(KEY_DEVELOPER_TOKEN, token)
|
|
15
|
+
.apply()
|
|
16
|
+
invalidateSession(context)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Persists for native playback SDK (iOS [MusicKitAuthStorage] parity); JS still owns long-term storage. */
|
|
20
|
+
fun saveMusicUserToken(context: Context, token: String) {
|
|
21
|
+
val trimmed = token.trim()
|
|
22
|
+
context
|
|
23
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
24
|
+
.edit()
|
|
25
|
+
.putString(KEY_MUSIC_USER_TOKEN, trimmed)
|
|
26
|
+
.apply()
|
|
27
|
+
AuthenticatedSessionCache.rememberMusicUserToken(trimmed)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun getMusicUserToken(context: Context): String? {
|
|
31
|
+
AuthenticatedSessionCache.musicUserToken?.let { return it }
|
|
32
|
+
val stored =
|
|
33
|
+
context
|
|
34
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
35
|
+
.getString(KEY_MUSIC_USER_TOKEN, null)
|
|
36
|
+
?.trim()
|
|
37
|
+
?.takeIf { it.isNotEmpty() }
|
|
38
|
+
if (stored != null) {
|
|
39
|
+
AuthenticatedSessionCache.rememberMusicUserToken(stored)
|
|
40
|
+
}
|
|
41
|
+
return stored
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private fun invalidateSession(context: Context) {
|
|
45
|
+
AuthenticatedSessionCache.invalidate()
|
|
46
|
+
context
|
|
47
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
48
|
+
.edit()
|
|
49
|
+
.remove(KEY_MUSIC_USER_TOKEN)
|
|
50
|
+
.apply()
|
|
51
|
+
AndroidPlaybackController.resetInstance()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fun getDeveloperToken(context: Context): String? =
|
|
55
|
+
context
|
|
56
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
57
|
+
.getString(KEY_DEVELOPER_TOKEN, null)
|
|
58
|
+
|
|
59
|
+
fun clearDeveloperToken(context: Context) {
|
|
60
|
+
context
|
|
61
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
62
|
+
.edit()
|
|
63
|
+
.remove(KEY_DEVELOPER_TOKEN)
|
|
64
|
+
.apply()
|
|
65
|
+
invalidateSession(context)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun clearAll(context: Context) {
|
|
69
|
+
context
|
|
70
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
71
|
+
.edit()
|
|
72
|
+
.clear()
|
|
73
|
+
.apply()
|
|
74
|
+
invalidateSession(context)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.apple.android.sdk.authentication.TokenProvider
|
|
5
|
+
|
|
6
|
+
internal class MusicKitTokenProvider(
|
|
7
|
+
private val context: Context,
|
|
8
|
+
) : TokenProvider {
|
|
9
|
+
override fun getDeveloperToken(): String = AndroidDeveloperToken.requireStored(context)
|
|
10
|
+
|
|
11
|
+
override fun getUserToken(): String =
|
|
12
|
+
MusicKitAuthStorage.getMusicUserToken(context).orEmpty()
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
internal data class PaginationOptions(
|
|
4
|
+
val limit: Int,
|
|
5
|
+
val offset: Int,
|
|
6
|
+
) {
|
|
7
|
+
companion object {
|
|
8
|
+
fun fromMap(options: Map<String, Any?>): PaginationOptions {
|
|
9
|
+
val limit = (options["limit"] as? Number)?.toInt()?.coerceAtLeast(1) ?: 25
|
|
10
|
+
val offset = (options["offset"] as? Number)?.toInt()?.coerceAtLeast(0) ?: 0
|
|
11
|
+
return PaginationOptions(limit, offset)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.Dispatchers
|
|
4
|
+
import kotlinx.coroutines.withContext
|
|
5
|
+
import org.json.JSONObject
|
|
6
|
+
|
|
7
|
+
/** Ratings and favorites Apple Music REST. */
|
|
8
|
+
internal class RatingsRestClient(
|
|
9
|
+
private val transport: AppleMusicRestTransport,
|
|
10
|
+
) {
|
|
11
|
+
suspend fun getRating(musicUserToken: String, resourceType: String, id: String): Map<String, Any?>? =
|
|
12
|
+
withContext(Dispatchers.IO) {
|
|
13
|
+
try {
|
|
14
|
+
val json = transport.getJson(
|
|
15
|
+
musicUserToken,
|
|
16
|
+
"/v1/me/ratings/$resourceType/$id")
|
|
17
|
+
AppleMusicJsonMapper.mapRating(json)
|
|
18
|
+
} catch (error: expo.modules.kotlin.exception.CodedException) {
|
|
19
|
+
if (error.message?.contains("(404)") == true) {
|
|
20
|
+
return@withContext null
|
|
21
|
+
}
|
|
22
|
+
throw error
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
suspend fun setRating(musicUserToken: String, resourceType: String, id: String, value: Int): Map<String, Any?> =
|
|
27
|
+
withContext(Dispatchers.IO) {
|
|
28
|
+
val body =
|
|
29
|
+
JSONObject()
|
|
30
|
+
.put("type", "rating")
|
|
31
|
+
.put(
|
|
32
|
+
"attributes",
|
|
33
|
+
JSONObject().put("value", value),
|
|
34
|
+
)
|
|
35
|
+
val json =
|
|
36
|
+
transport.request(
|
|
37
|
+
musicUserToken,
|
|
38
|
+
AppleMusicHttpMethod.PUT,
|
|
39
|
+
"/v1/me/ratings/$resourceType/$id",
|
|
40
|
+
body = body,
|
|
41
|
+
)
|
|
42
|
+
AppleMusicJsonMapper.mapRating(json)
|
|
43
|
+
?: throw AppleMusicErrors.apiError("Invalid Apple Music API response")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
suspend fun clearRating(musicUserToken: String, resourceType: String, id: String): Unit =
|
|
47
|
+
withContext(Dispatchers.IO) {
|
|
48
|
+
transport.request(
|
|
49
|
+
musicUserToken,
|
|
50
|
+
AppleMusicHttpMethod.DELETE, "/v1/me/ratings/$resourceType/$id")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
suspend fun addToFavorites(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
|
|
54
|
+
withContext(Dispatchers.IO) {
|
|
55
|
+
transport.request(
|
|
56
|
+
musicUserToken,
|
|
57
|
+
AppleMusicHttpMethod.POST,
|
|
58
|
+
"/v1/me/favorites",
|
|
59
|
+
query = buildIdsQuery(resourceIds),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
suspend fun removeFromFavorites(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
|
|
64
|
+
withContext(Dispatchers.IO) {
|
|
65
|
+
transport.request(
|
|
66
|
+
musicUserToken,
|
|
67
|
+
AppleMusicHttpMethod.DELETE,
|
|
68
|
+
"/v1/me/favorites",
|
|
69
|
+
query = buildIdsQuery(resourceIds),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package expo.modules.applemusic
|
|
2
|
+
|
|
3
|
+
import kotlinx.coroutines.Dispatchers
|
|
4
|
+
import kotlinx.coroutines.withContext
|
|
5
|
+
|
|
6
|
+
/** Recommendations and Replay Apple Music REST. */
|
|
7
|
+
internal class RecommendationsRestClient(
|
|
8
|
+
private val transport: AppleMusicRestTransport,
|
|
9
|
+
) {
|
|
10
|
+
suspend fun getRecommendations(musicUserToken: String, ids: List<String>?): List<Map<String, Any?>> =
|
|
11
|
+
withContext(Dispatchers.IO) {
|
|
12
|
+
val query =
|
|
13
|
+
if (!ids.isNullOrEmpty()) {
|
|
14
|
+
mapOf("ids" to ids.joinToString(","))
|
|
15
|
+
} else {
|
|
16
|
+
emptyMap()
|
|
17
|
+
}
|
|
18
|
+
val json = transport.getJson(
|
|
19
|
+
musicUserToken,
|
|
20
|
+
"/v1/me/recommendations", query)
|
|
21
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecommendation(it) }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
suspend fun getReplay(musicUserToken: String, year: Int?): List<Map<String, Any?>> =
|
|
25
|
+
withContext(Dispatchers.IO) {
|
|
26
|
+
val query =
|
|
27
|
+
if (year != null) {
|
|
28
|
+
mapOf("filter[year]" to year.toString())
|
|
29
|
+
} else {
|
|
30
|
+
emptyMap()
|
|
31
|
+
}
|
|
32
|
+
val json = transport.getJson(
|
|
33
|
+
musicUserToken,
|
|
34
|
+
"/v1/me/music-summaries", query)
|
|
35
|
+
mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapReplaySummary(it) }
|
|
36
|
+
}
|
|
37
|
+
}
|