public function getAlbumInfo($name, $artistName)
{
if (!$this->enabled()) {
return false;
}
$name = urlencode($name);
$artistName = urlencode($artistName);
try {
$cacheKey = md5("lastfm_album_{$name}_{$artistName}");
if ($response = Cache::get($cacheKey)) {
$response = simplexml_load_string($response);
} else {
if ($response = $this->get("?method=album.getInfo&autocorrect=1&album={$name}&artist={$artistName}")) {
Cache::put($cacheKey, $response->asXML(), 24 * 60 * 7);
}
}
$response = json_decode(json_encode($response), true);
if (!$response || !($album = array_get($response, 'album'))) {
return false;
}
return ['url' => array_get($album, 'url'), 'image' => count($album['image']) > 3 ? $album['image'][3] : $album['image'][0], 'wiki' => ['summary' => $this->formatText(array_get($album, 'wiki.summary')), 'full' => $this->formatText(array_get($album, 'wiki.content'))], 'tracks' => array_map(function ($track) {
return ['title' => $track['name'], 'length' => (int) $track['duration'], 'url' => $track['url']];
}, array_get($album, 'tracks.track', []))];
} catch (Exception $e) {
Log::error($e);
return false;
}
}