diff --git a/music/explore.php b/music/explore.php
index 19d592b..85fd472 100644
--- a/music/explore.php
+++ b/music/explore.php
@@ -3,51 +3,14 @@ require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
-$html = '';
+session_start();
$client_id = $_ENV['SPOTIFY_CLIENT_ID'];
$client_secret = $_ENV['SPOTIFY_CLIENT_SECRET'];
$auth_code = $_GET['code'];
$client_credentials = get_client_credentials($client_id, $client_secret);
-// TODO: Dynamically retrieve top 10 albums from Spotify API
-// TODO: Implement server-side caching for faster load times.
-$albums = [
- '2FQieUp8BxPN7OR8fE76TE',
- '5mUo2e4QpUA7NJl2t51uFu',
- '7ycBtnsMtyVbbwTfJwRjSP',
- '2ZytN2cY4Zjrr9ukb2rqTP',
- '4ZDBQSIDIZRUBOG2OHcN3T',
- '1FHREwXgTQvqiG8q5KlRzc',
- '1MmVkhiwTH0BkNOU3nw5d3',
- '79dL7FLiJFOO0EoehUHQBv',
- '35qVMfUfBN6q2xzm9rZn5a',
- '2eQMC9nJE3f3hCNKlYYHL1'
-];
-
-shuffle($albums);
-
-$content = '';
-foreach ($albums as $album_id) {
- $data = get_album($client_credentials, $album_id);
- $content = $content . '
-  |
- ' . $data['name'] . ' |
- ' . $data['artists'][0]['name'] . ' |
- Spotify |
-
';
-}
-
-$html = '
-
-
-| Art |
-Name |
-Artist |
-Spotify |
-
' . $content . '
';
-
function get_client_credentials($client_id, $client_secret)
{
$url = 'https://accounts.spotify.com/api/token';
@@ -173,15 +136,22 @@ function get_albums($auth_code, $client_id, $client_secret)
curl_close($ch);
$song_data = [];
- foreach ($top_songs as $song) {
- $song_data[] = array(
- 'image' => $song['album']['images'][0]['url'],
- 'song_name' => $song['name'],
- 'song_id' => $song['id'],
- 'album_name' => $song['album']['name'],
- 'album_id' => $song['album']['id'],
- 'artist' => $song['artists'][0]['name'],
- );
+ if ($_SESSION['data'] == null) {
+ foreach ($top_songs as $song) {
+ $song_data[] = array(
+ 'image' => $song['album']['images'][0]['url'],
+ 'song_name' => $song['name'],
+ 'song_id' => $song['id'],
+ 'album_name' => $song['album']['name'],
+ 'album_id' => $song['album']['id'],
+ 'artist' => $song['artists'][0]['name'],
+ );
+ }
+
+ echo "saving data to $_SESSION";
+ $_SESSION['data'] = $song_data;
+ } else {
+ $song_data = $_SESSION['data'];
}
foreach ($song_data as $s) {
@@ -196,5 +166,4 @@ function get_albums($auth_code, $client_id, $client_secret)
}
get_albums($auth_code, $client_id, $client_secret);
-// echo $html;
?>