Downloading video to correct directory and displaying it on a chapter page.

This commit is contained in:
Krzysztof Płaczek
2022-11-17 08:24:17 +01:00
parent 21f61b0911
commit 2c62880282
4 changed files with 42 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ use App\Models\Chapter;
use App\Models\Course;
use GuzzleHttp\TransferStats;
use GuzzleHttp\Client;
use Illuminate\Support\Str;
class SymfonyCastDlService
{
@@ -54,7 +55,6 @@ class SymfonyCastDlService
{
try {
if (!$chapter->video_size) {
echo 1;
$response = $this->client->head($chapter->video_link);
if ($response->hasHeader('Content-Length')) {
$chapter->video_size = $response->getHeader('Content-Length')[0];
@@ -66,16 +66,17 @@ class SymfonyCastDlService
return $chapter;
}
public function downloadFile(Chapter $chapter): bool
public function downloadFile(Chapter $chapter): void
{
if (!is_dir($chapter->course_id . '/')) {
mkdir($chapter->course_id);
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],
);
}
$this->client->request(
'GET',
$chapter->video_link,
['sink' => $chapter->course_id . '/' . $chapter->id . '.mp4']
);
return true;
}
}