From cfc84a1d4d172a8b79bfe61eeb3dc3d7f390d273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Sat, 8 Apr 2023 09:52:44 +0200 Subject: [PATCH] Handling the case when there is no video yet, locally or online. --- app/Http/SymfonyCastDl/HtmlParser.php | 4 ++-- app/Http/SymfonyCastDl/SymfonyCastDlService.php | 4 ++-- resources/views/chapter/index.blade.php | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Http/SymfonyCastDl/HtmlParser.php b/app/Http/SymfonyCastDl/HtmlParser.php index 0a2d808..b3c5f7c 100644 --- a/app/Http/SymfonyCastDl/HtmlParser.php +++ b/app/Http/SymfonyCastDl/HtmlParser.php @@ -65,10 +65,10 @@ class HtmlParser return $chapters; } - public function getVideoSource(Response $respose): string + public function getVideoSource(Response $respose): ?string { $document = new Document($respose->getBody()->getContents()); - return $document->first('video source')->getAttribute('src'); + return $document->first('video source')?->getAttribute('src'); } } diff --git a/app/Http/SymfonyCastDl/SymfonyCastDlService.php b/app/Http/SymfonyCastDl/SymfonyCastDlService.php index c84f066..c8c0a5a 100644 --- a/app/Http/SymfonyCastDl/SymfonyCastDlService.php +++ b/app/Http/SymfonyCastDl/SymfonyCastDlService.php @@ -55,7 +55,7 @@ class SymfonyCastDlService $chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id)); } - public function getChapterInfo(Chapter $chapter): string + public function getChapterInfo(Chapter $chapter): ?string { $course = $chapter->course; $chapterPage = $this->client->get('/screencast/' . $course->link . DIRECTORY_SEPARATOR . $chapter->link); @@ -64,7 +64,7 @@ class SymfonyCastDlService public function videoSize(Chapter $chapter): Chapter { - if (!$chapter->video_size) { + if (!$chapter->video_size && $chapter->video_link) { $response = $this->client->head($chapter->video_link); if ($response->hasHeader('Content-Length')) { $chapter->video_size = (int)$response->getHeader('Content-Length')[0]; diff --git a/resources/views/chapter/index.blade.php b/resources/views/chapter/index.blade.php index ad80019..c54e240 100644 --- a/resources/views/chapter/index.blade.php +++ b/resources/views/chapter/index.blade.php @@ -17,12 +17,14 @@ @endif
+ @if($videoUrl)
- @if($chapter->is_video_file) + @else + no video @endif