music-companion / apple-music
Apple Music SDK
4.0.0
2024-03-24 13:52 UTC
Requires
- php: ~8.2
- innmind/colour: ~4.0
- innmind/immutable: ~4.4|~5.0
- innmind/json: ~1.4
- innmind/operating-system: ~4.0|~5.0
- innmind/url: ~4.1
- innmind/validation: ~1.4
- lcobucci/jwt: ~4.3|~5.0
Requires (Dev)
- innmind/black-box: ~5.5
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~10.2
- vimeo/psalm: ~5.15
README
This is a sdk to consume part of the Apple Music API.
Installation
composer require music-companion/apple-music
Usage
use MusicCompanion\AppleMusic\{ SDK, Key, }; use Innmind\OperatingSystem\Factory; use Innmind\TimeContinuum\Earth\Period\Hour; use Innmind\Url\Path; use Innmind\Filesystem\Name; use Innmind\Immutable\Set; $os = Factory::build(); $sdk = SDK::of( $os->clock(), $os->remote()->http(), Key::of( // @see https://help.apple.com/developer-account/#/devce5522674 to understand howto generate the key 'KEY_ID', 'TEAM_ID', $os ->filesystem() ->mount(Path::of('config_dir/')) ->get(new Name('AuthKey_TEAM_ID.p8')) ->match( static fn($file) => $file->content(), static fn() => throw new \RuntimeException('Key file not found'), ), ), new Hour(1) // expire the generated token after an hour ); $sdk->storefronts()->all(); // Set<SDK\Storefront> $catalog = $sdk->catalog(new SDK\Storefront\Id('fr')); $result = $catalog->search('Pendulum Live at Brixton'); $albums = $result->albums()->map($catalog->album(...)); // @see https://developer.apple.com/documentation/applemusicapi/getting_keys_and_creating_tokens // to retrieve the user token $sdk->library($userToken)->match( static fn($libray) => $libray->artists(), // Set<SDK\Library\Artist> static fn() => throw new \RuntimeException('Invalid user token'), );