Added total time of a course, marking chapters and courses to sync offline.
This commit is contained in:
@@ -41,24 +41,27 @@ class SymfonyCastDlService
|
||||
|
||||
$courses = $this->htmlParser->getCourses($coursePage);
|
||||
$courses->each(fn($course) => $course->save());
|
||||
$singleCoursePage = $this->client->get($courses[3]->link);
|
||||
// $singleCoursePage = $this->client->get($courses[3]->link);
|
||||
/** @var Course $course */
|
||||
foreach ($courses as $course) {
|
||||
$singleCoursePage = $this->client->get($course->link);
|
||||
$chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id);
|
||||
$chapters->each(fn($chapter) => $this->videoSize($chapter)->save());
|
||||
// $chapters->each(fn($chapter) => $this->videoSize($chapter)->save());
|
||||
$chapters->each(fn($chapter) => $chapter->save());
|
||||
}
|
||||
}
|
||||
|
||||
public function videoSize(Chapter $chapter): Chapter
|
||||
{
|
||||
try {
|
||||
$response = $this->client->head($chapter->video_link);
|
||||
if ($response->hasHeader('Content-Length')) {
|
||||
$chapter->video_size = $response->getHeader('Content-Length')[0];
|
||||
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 (\GuzzleHttp\Exception\ClientException $exception) {
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user