Downloading video to correct directory and displaying it on a chapter page.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user