blob: 7ba6a1b6cb83b1c49aa7f8680358e1615a009462 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
$env = require __DIR__ . '/.env.php';
use TCB\Credentials;
use TCB\HistoryStorage;
use TCB\HttpServer;
use TCB\SpotifyApiClient;
use TCB\TokenManager;
use TCB\TokenStorage;
$credentials = new Credentials(
$env['clientID'],
$env['clientSecret'],
$env['redirectURI'],
$env['state'],
);
$httpServer = new HttpServer(
$env['serverAddress'],
(int) $env['serverPort'],
(int) $env['serverTimeout'],
);
$tokenStorage = TokenStorage::load(__DIR__ . '/.token_storage.json');
$historyStorage = HistoryStorage::load(__DIR__ . '/.history_storage.json');
$tokenManager = new TokenManager($credentials, $httpServer, $tokenStorage);
$client = new SpotifyApiClient($tokenManager, $historyStorage);
$song = $client->pickRandomSongFromPlaylist($env['playlistName']);
$name = $song['name'] ?? '';
$artists = implode(',', array_map(function (array $artist): string {
return $artist['name'];
}, $song['artists'] ?? []));
echo "The song picked is $name by $artists\n";
exit(0);
|