Displaying videos directly from link from symfony cast website without downloading.
This commit is contained in:
@@ -10,15 +10,17 @@ class ChapterController extends Controller
|
|||||||
public function __invoke(Course $course, int $chapter, SymfonyCastDlService $symfonyCastDlService)
|
public function __invoke(Course $course, int $chapter, SymfonyCastDlService $symfonyCastDlService)
|
||||||
{
|
{
|
||||||
$chapter = $course->chapters->firstWhere('order', $chapter);
|
$chapter = $course->chapters->firstWhere('order', $chapter);
|
||||||
|
|
||||||
$symfonyCastDlService->videoSize($chapter);
|
$symfonyCastDlService->videoSize($chapter);
|
||||||
if ($chapter->sync_offline) {
|
if ($chapter->sync_offline) {
|
||||||
$symfonyCastDlService->downloadFile($chapter);
|
$symfonyCastDlService->downloadFile($chapter);
|
||||||
|
$videoUrl = $chapter->video_url;
|
||||||
|
} else {
|
||||||
|
$videoUrl = $symfonyCastDlService->getChapterInfo($chapter);
|
||||||
}
|
}
|
||||||
$chapters = $chapter->course->chapters;
|
|
||||||
|
|
||||||
|
$chapters = $chapter->course->chapters;
|
||||||
$next = $chapters->where('order', '>', $chapter->order)->first();
|
$next = $chapters->where('order', '>', $chapter->order)->first();
|
||||||
$prev = $chapters->where('order', '<', $chapter->order)->sortByDesc('order')->first();
|
$prev = $chapters->where('order', '<', $chapter->order)->sortByDesc('order')->first();
|
||||||
return view('chapter.index', compact('chapter', 'chapters', 'prev', 'next'));
|
return view('chapter.index', compact('chapter', 'chapters', 'prev', 'next', 'videoUrl'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ class HtmlParser
|
|||||||
foreach ($document->find('ul.chapter-list li') as $chapterItem) {
|
foreach ($document->find('ul.chapter-list li') as $chapterItem) {
|
||||||
if ($chapterItem->first('.col')) {
|
if ($chapterItem->first('.col')) {
|
||||||
$chapterId++;
|
$chapterId++;
|
||||||
|
|
||||||
$chapter = Chapter::firstOrNew(['course_id' => $courseId, 'order' => $chapterId]);
|
$chapter = Chapter::firstOrNew(['course_id' => $courseId, 'order' => $chapterId]);
|
||||||
$chapter->duration = $chapterItem->first('.length-styling')?->text();
|
$chapter->duration = $chapterItem->first('.length-styling')?->text();
|
||||||
$chapter->order = $chapterId;
|
$chapter->order = $chapterId;
|
||||||
@@ -63,8 +62,13 @@ class HtmlParser
|
|||||||
$chapters->add($chapter);
|
$chapters->add($chapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $chapters;
|
return $chapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVideoSource(Response $respose): string
|
||||||
|
{
|
||||||
|
$document = new Document($respose->getBody()->getContents());
|
||||||
|
return $document->first('video source')->getAttribute('src');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use App\Models\Chapter;
|
|||||||
use App\Models\Course;
|
use App\Models\Course;
|
||||||
use GuzzleHttp\TransferStats;
|
use GuzzleHttp\TransferStats;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
|
||||||
class SymfonyCastDlService
|
class SymfonyCastDlService
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,13 @@ class SymfonyCastDlService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getChapterInfo(Chapter $chapter): string
|
||||||
|
{
|
||||||
|
$course = $chapter->course;
|
||||||
|
$chapterPage = $this->client->get('/screencast/' . $course->link . DIRECTORY_SEPARATOR . $chapter->link);
|
||||||
|
return $this->htmlParser->getVideoSource($chapterPage);
|
||||||
|
}
|
||||||
|
|
||||||
public function videoSize(Chapter $chapter): Chapter
|
public function videoSize(Chapter $chapter): Chapter
|
||||||
{
|
{
|
||||||
if (!$chapter->video_size) {
|
if (!$chapter->video_size) {
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@if($chapter->is_video_file)
|
|
||||||
<div class="d-flex justify-content-center">
|
<div class="d-flex justify-content-center">
|
||||||
<video class="mx-auto" width="500" controls>
|
<video class="mx-auto" width="500" controls>
|
||||||
<source src="{{ $chapter->video_url }}" type="video/mp4"/>
|
<source src="{{ $videoUrl }}" type="video/mp4"/>
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
|
@if($chapter->is_video_file)
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user