diff --git a/app/Console/Commands/UpdateVideoSize.php b/app/Console/Commands/UpdateVideoSize.php new file mode 100644 index 0000000..d168c50 --- /dev/null +++ b/app/Console/Commands/UpdateVideoSize.php @@ -0,0 +1,22 @@ +get(); + $chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id)); + return self::SUCCESS; + } +} diff --git a/app/Http/Controllers/Index.php b/app/Http/Controllers/Index.php index 1d35e7d..f25dc8b 100644 --- a/app/Http/Controllers/Index.php +++ b/app/Http/Controllers/Index.php @@ -13,7 +13,6 @@ class Index extends Controller { $courses = Course::with('chapters')->withCount('chapters')->get(); -// dd($courses->toArray()); return view('index', compact(['courses'])); } diff --git a/app/Http/SymfonyCastDl/SymfonyCastDlService.php b/app/Http/SymfonyCastDl/SymfonyCastDlService.php index 34ccaec..2ca419a 100644 --- a/app/Http/SymfonyCastDl/SymfonyCastDlService.php +++ b/app/Http/SymfonyCastDl/SymfonyCastDlService.php @@ -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( diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php index 7434594..341b9ff 100644 --- a/app/Models/Chapter.php +++ b/app/Models/Chapter.php @@ -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; + }, + ); + } + } diff --git a/resources/views/course/index.blade.php b/resources/views/course/index.blade.php index f104013..8c28e89 100644 --- a/resources/views/course/index.blade.php +++ b/resources/views/course/index.blade.php @@ -1,6 +1,6 @@

- {{ $course->name }} + List » {{ $course->name }}

Sync all chapters offline @@ -10,6 +10,8 @@ Title Duration Sync offline + Synced offline + File size @foreach($course->chapters()->get() as $chapter) @@ -18,12 +20,14 @@ {{ $chapter->duration }} {{ $chapter->sync_offline?'Yes':'no' }} {{ $chapter->is_video_file?'Yes':'-' }} + {{ $chapter->video_size_human }} @endforeach Total: {{ $course->course_duration }} + Size: {{ $course->total_size_human }}