public static function get(Artist $artist, $name, $isCompilation = false)
{
// If this is a compilation album, its artist must be "Various Artists"
if ($isCompilation) {
$artist = Artist::getVarious();
}
return self::firstOrCreate(['artist_id' => $artist->id, 'name' => $name ?: self::UNKNOWN_NAME]);
}
/** * Sync a song with all available media info against the database. * * @param SplFileInfo $file The SplFileInfo instance of the file. * * @return bool|Song A Song object on success, * true if file existing but unmodified, * or false on error. */ public function syncFile(SplFileInfo $file) { if (!($info = $this->getInfo($file))) { return false; } if (!$this->isNewOrChanged($file)) { return true; } $artist = Artist::get($info['artist']); $album = Album::get($artist, $info['album']); if ($info['cover'] && !$album->has_cover) { try { $album->generateCover($info['cover']); } catch (Exception $e) { Log::error($e); } } $info['album_id'] = $album->id; unset($info['artist']); unset($info['album']); unset($info['cover']); $song = Song::updateOrCreate(['id' => $this->getHash($file->getPathname())], $info); $song->save(); return $song; }