$artist_albums_result = $db->query("select * from album where Artist_Spotify_id='" . SQLite3::escapeString($artist_spotify_id) . "'"); //Getting album dictionary using spotify id. while ($album = $artist_albums_result->fetchArray()) { //Loop in this array to check if album in database. //here you have database fetched artist albums. saved during last run. use it $item = new stdClass(); //Declaring item class. $item->name = $album['Album_name']; //Creating dictionary. $item->id = $album['Album_id']; $artist_albums->items[] = $item; //Seting dictionary inside to database. } if (count($artist_albums->items) == 0) { // search spotify for artist albums only if database does not contain any albums. $artist_albums = $api->getArtistAlbums($artist_spotify_id); foreach ($artist_albums->items as $album) { $spotify_album_name = $album->name; $spotify_album_id = $album->id; $db->exec('insert into album ("Album_name","Album_id", "Artist_spotify_id") values (' . "'" . SQLite3::escapeString($spotify_album_name) . "','" . $spotify_album_id . "','" . $artist_spotify_id . "')"); } } foreach ($artist_albums->items as $album) { $spotify_album_name = $album->name; $spotify_album_id = $album->id; $spotify_tracks = new stdClass(); $spotify_tracks->items = array(); $spotify_tracks_result = $db->query("select * from tracks where Album_id='" . SQLite3::escapeString($spotify_album_id) . "'"); while ($track = $spotify_tracks_result->fetchArray()) { // Geting tracks using albums id in database. //here you have database fetched artist albums tacks. saved during last run. use it
public function testGetArtistAlbums() { $options = array('album_type' => array('album', 'single'), 'limit' => 10, 'market' => 'SE'); $expected = array('album_type' => 'album,single', 'market' => 'SE', 'limit' => 10); $headers = array('Authorization' => 'Bearer ' . $this->accessToken); $return = array('body' => get_fixture('artist-albums')); $stub = $this->setupStub('GET', '/v1/artists/36QJpDe2go2KgaRleHCDTp/albums', $expected, $headers, $return); $api = new SpotifyWebAPI\SpotifyWebAPI($stub); $api->setAccessToken($this->accessToken); $response = $api->getArtistAlbums('36QJpDe2go2KgaRleHCDTp', $options); $this->assertObjectHasAttribute('items', $response); }
$name_user = $_SESSION['valid_username']; $id_user = $_SESSION['valid_userid']; $tracks = $api->getArtistTopTracks($id, array('country' => 'fr')); $artist = $api->getArtist($id); return $app['twig']->render('top_tracks_artist.html.twig', array('tracks' => $tracks, 'artist' => $artist, 'name_user' => $name_user)); })->bind('getartiststoptracksbyartistid'); //Get an Artist's Albums by artist ID $app->get('/api/artist/{id}/albums', function ($id) use($api, $app) { session_start(); if (empty($_SESSION['valid_userid'])) { header("location:loginerror.php"); exit; } $name_user = $_SESSION['valid_username']; $id_user = $_SESSION['valid_userid']; $albums = $api->getArtistAlbums($id); $artist = $api->getArtist($id); return $app['twig']->render('albums_artist.html.twig', array('albums' => $albums, 'artist' => $artist, 'name_user' => $name_user)); })->bind('getartistsalbumsbyartistid'); ////obtenir des infos d'album par item 'album' et des mots clés $app->get('/api/search/album/{name}', function ($name) use($api, $app) { session_start(); if (empty($_SESSION['valid_userid'])) { header("location:loginerror.php"); exit; } $name_user = $_SESSION['valid_username']; $id_user = $_SESSION['valid_userid']; $results = $api->search($name, 'album'); return $app['twig']->render('info_album.html.twig', array('results' => $results, 'name_user' => $name_user)); });