count() === 1) { return $this->getLocalPath($songs->first()); } return (new SongZipArchive()) ->addSongs($songs) ->finish() ->getPath(); } public function getLocalPath(Song $song): ?string { if (!$song->storage->supported()) { return null; } if ($song->isEpisode()) { $playable = EpisodePlayable::retrieveForEpisode($song); if (!$playable?->valid()) { $playable = EpisodePlayable::createForEpisode($song); } return $playable->path; } if ($song->storage === SongStorageType::LOCAL) { return File::exists($song->path) ? $song->path : null; } if ($song->storage === SongStorageType::SFTP) { return app(SftpStorage::class)->copyToLocal($song); } switch ($song->storage) { case SongStorageType::DROPBOX: $cloudStorage = app(DropboxStorage::class); break; case SongStorageType::S3: case SongStorageType::S3_LAMBDA: $cloudStorage = app(S3CompatibleStorage::class); break; default: return null; } return $cloudStorage->copyToLocal($song); } }