Downloading files, calculating video size.
This commit is contained in:
@@ -7,7 +7,6 @@ use App\Models\Chapter;
|
||||
use App\Models\Course;
|
||||
use GuzzleHttp\TransferStats;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SymfonyCastDlService
|
||||
{
|
||||
@@ -53,25 +52,22 @@ class SymfonyCastDlService
|
||||
|
||||
public function videoSize(Chapter $chapter): Chapter
|
||||
{
|
||||
try {
|
||||
if (!$chapter->video_size) {
|
||||
$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 = (int)$response->getHeader('Content-Length')[0];
|
||||
$chapter->save();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
public function downloadFile(Chapter $chapter): void
|
||||
{
|
||||
if (!is_dir($chapter->directory_path)) {
|
||||
mkdir($chapter->directory_path);
|
||||
if (!is_dir(public_path($chapter->directory_path))) {
|
||||
mkdir(public_path($chapter->directory_path));
|
||||
}
|
||||
if (!is_file($chapter->video_path)) {
|
||||
if (!$chapter->is_video_file) {
|
||||
$this->client->request(
|
||||
'GET',
|
||||
$chapter->video_link,
|
||||
|
||||
Reference in New Issue
Block a user