/** * @param string $url * @return array */ public function create(string $url) : array { $config = $this->config; /* @service SoundcloudFacade */ $service = new SoundCloudDriver($config['client_id'], $config['client_secret']); /* @var $responseSoundcloud \Njasm\Soundcloud\Request\Response */ $responseSoundcloud = $service->get('/resolve', ['url' => $url])->asJson()->request(); /* @var $track \StdClass */ $track = $responseSoundcloud->bodyObject(); /* @var $parsed array */ $parsed = parse_url($track->location); /* @var $response \Njasm\Soundcloud\Request\Response */ $response = $service->get($parsed['path'])->request(); return $response->bodyArray() ?: ['id' => null, 'title' => null, 'description' => null, 'uri' => null, 'artwork_url' => null]; }
/** * resolve the url data * * @return mixed */ protected function doResolve() { $this->id = $this->id ? $this->id : $this->validate(); $soundcloud = new Soundcloud($this->config()->get('soundcloudKey'), $this->config()->get('soundcloudSecret')); // if we have the track id get info directly else if the id is a string try to resolve the url and retry // with the retrieved id if (ctype_digit($this->id)) { $response = $soundcloud->get('/tracks/' . $this->id)->request()->bodyArray(); } elseif (is_string($this->id)) { $response = $soundcloud->get('/resolve', ['url' => $this->url])->request()->bodyArray(); // extract id from location if available if (isset($response['location'])) { $this->id = substr($response['location'], strrpos($response['location'], '/') + 1); $this->id = strtok($this->id, '?'); // retry with the new ID return $this->doResolve(); } return false; } if (isset($response['kind']) and $response['kind'] == 'track') { return $response; } return false; }