Reading file size
This commit is contained in:
22
app/Console/Commands/UpdateVideoSize.php
Normal file
22
app/Console/Commands/UpdateVideoSize.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\DownloadVideoFile;
|
||||
use App\Jobs\GetVideoFileSize;
|
||||
use App\Models\Chapter;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UpdateVideoSize extends Command
|
||||
{
|
||||
protected $signature = 'symfonycast:video_size';
|
||||
|
||||
protected $description = 'Updates information about video size';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$chapters = Chapter::where('video_size', 0)->get();
|
||||
$chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id));
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ class Index extends Controller
|
||||
{
|
||||
$courses = Course::with('chapters')->withCount('chapters')->get();
|
||||
|
||||
// dd($courses->toArray());
|
||||
return view('index', compact(['courses']));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class SymfonyCastDlService
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
public function getInfo(): void
|
||||
{
|
||||
$coursePage = $this->client->get('courses/filtering');
|
||||
|
||||
@@ -64,8 +64,11 @@ class SymfonyCastDlService
|
||||
|
||||
public function downloadFile(Chapter $chapter): void
|
||||
{
|
||||
if (!is_dir(public_path($chapter->directory_path))) {
|
||||
mkdir(public_path($chapter->directory_path));
|
||||
if (is_null($chapter->video_link)) {
|
||||
return;
|
||||
}
|
||||
if (!is_dir($chapter->directory_path)) {
|
||||
mkdir($chapter->directory_path);
|
||||
}
|
||||
if (!$chapter->is_video_file) {
|
||||
$this->client->request(
|
||||
|
||||
@@ -46,14 +46,14 @@ class Chapter extends Model
|
||||
protected function videoPath(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->directory_path . '/' . $this->id . '.' . $this->link . '.mp4'
|
||||
get: fn() => $this->directory_path . '/' . $this->order . '.mp4'
|
||||
);
|
||||
}
|
||||
|
||||
protected function directoryPath(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->course_id . '.' . $this->course->link
|
||||
get: fn() => public_path($this->course_id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,4 +63,16 @@ class Chapter extends Model
|
||||
get: fn() => is_file($this->video_path)
|
||||
);
|
||||
}
|
||||
|
||||
public function videoSizeHuman(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function () {
|
||||
$base = log($this->video_size) / log(1024);
|
||||
$suffix = ["", "k", "M", "G", "T"][floor($base)];
|
||||
return round(pow(1024, $base - floor($base)), 2) . $suffix;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user