/** * Get extra information about the album from Last.fm. * * @return array|false */ public function getInfo() { if ($this->id === self::UNKNOWN_ID) { return false; } $info = Lastfm::getAlbumInfo($this->name, $this->artist->name); // If our current album has no cover, and Last.fm has one, why don't we steal it? // Great artists steal for their great albums! if (!$this->has_cover && is_string($image = array_get($info, 'image')) && ini_get('allow_url_fopen')) { $extension = explode('.', $image); $this->writeCoverFile(file_get_contents($image), last($extension)); } return $info; }
/** * Get extra information about the artist from Last.fm. * * @return array|false */ public function getInfo() { if ($this->id === self::UNKNOWN_ID) { return false; } $info = Lastfm::getArtistInfo($this->name); // If our current artist has no image, and Last.fm has one, copy the image for our local use. if (!$this->image && is_string($image = array_get($info, 'image')) && ini_get('allow_url_fopen')) { try { $extension = explode('.', $image); $fileName = uniqid() . '.' . trim(strtolower(last($extension)), '. '); $coverPath = app()->publicPath() . '/public/img/artists/' . $fileName; file_put_contents($coverPath, file_get_contents($image)); $this->update(['image' => $fileName]); } catch (\Exception $e) { Log::error($e); } } return $info; }