argument('type'); $url = $this->prepareExportUrlBy($type); $date = $this->getDate(); $path = storage_path('/'.$type."_".$date.".json.gz"); if (!file_exists($path)) { $this->downloadFile($url, $path); } } private function getDate(): string { return date('m_d_Y',strtotime("-1 days")); } private function prepareExportUrlBy(string $type): string { $date = $this->getDate(); if ($type === 'tv_series'){ return 'https://files.tmdb.org/p/exports/tv_series_ids_'.$date.'.json.gz'; } return 'https://files.tmdb.org/p/exports/movie_ids_'.$date.'.json.gz'; } private function downloadFile($url, $path): void { $newFileName = $path; $file = fopen ($url, 'rb'); $newFile = null; if ($file) { $newFile = fopen ($newFileName, 'wb'); if ($newFile) { while(!feof($file)) { fwrite($newFile, fread($file, 1024 * 8), 1024 * 8); } } } if ($file) { fclose($file); } if ($newFile) { fclose($newFile); } } }