client = new Client([ 'base_uri' => config('symfonycast.base_url'), 'cookies' => true ]); $response = $this->client->get('login'); $token = $htmlParser->getCsrfToken($response); $this->client->post('login', [ 'form_params' => [ 'email' => config('symfonycast.login'), 'password' => config('symfonycast.password'), '_csrf_token' => $token ], 'on_stats' => function (TransferStats $stats) use (&$currentUrl) { $currentUrl = $stats->getEffectiveUri(); } ]); } public function getInfo() { $coursePage = $this->client->get('courses/filtering'); $courses = $this->htmlParser->getCourses($coursePage); $courses->each->save(); /** @var Course $course */ foreach ($courses as $course) { $singleCoursePage = $this->client->get('/screencast/' . $course->link); $chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id); $chapters->each->save(); $chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id)); } } public function videoSize(Chapter $chapter): Chapter { try { if (!$chapter->video_size) { $response = $this->client->head($chapter->video_link); if ($response->hasHeader('Content-Length')) { $chapter->video_size = $response->getHeader('Content-Length')[0]; } $chapter->save(); } } catch (\Exception $exception) { } return $chapter; } public function downloadFile(Chapter $chapter): void { if (!is_dir($chapter->directory_path)) { mkdir($chapter->directory_path); } if (!is_file($chapter->video_path)) { $this->client->request( 'GET', $chapter->video_link, ['sink' => $chapter->video_path], ); } } }