Пример #1
0
 /**
  * Search for a track and build the response objects
  *
  * @param string $string
  *
  * @return Track
  */
 public function findTrack(string $string)
 {
     $result = $this->spotifyWebApi->search($string, 'track');
     if (count($result->tracks->items) === 0) {
         throw NoTracksFoundException::emptyResult();
     }
     $firstItem = $result->tracks->items[0];
     $images = $this->valueObjectBuilder->buildImages($firstItem->album->images);
     $album = $this->valueObjectBuilder->buildAlbumSimplified($firstItem->album, $images);
     $artists = $this->valueObjectBuilder->buildArtistsSimplified($firstItem->artists);
     $track = $this->valueObjectBuilder->buildTrack($firstItem, $album, $artists);
     return $track;
 }
Пример #2
0
<?php

use SpotifyWebAPI\SpotifyWebAPI;
use SpotifyWebApiExtensions\GuzzleClientFactory;
use SpotifyWebApiExtensions\GuzzleRequestAdapter;
use Doctrine\Common\Cache\FilesystemCache;
require_once './vendor/autoload.php';
$guzzleAdapter = new GuzzleRequestAdapter(GuzzleClientFactory::create(new FilesystemCache(__DIR__ . '/cache')));
$api = new SpotifyWebAPI($guzzleAdapter);
print_r($api->search('Nothing else matters', ['track'], ['market' => 'DE']));