*/ class TestCommand extends Command { /** * The name of command. * * @var string */ protected $name = 'mead:test'; /** * The description of command. * * @var string */ protected $description = 'Create a new course.'; /** * The type of class being generated. * * @var string */ protected $type = 'course'; /** * Execute the command. * * @return void * @see fire() */ public function handle() { $this->loadCourse(1, storage_path('app/public/zhongjingdaketang')); $this->line('ok'); } /** * 加载课程 * @param $id * @param $path * @return void */ public function loadCourse($id, $path) { $course = Course::query()->where('id', 1)->first(); $files = []; foreach (glob("{$path}/*") as $file) { $files[] = pathinfo($file); } foreach ($files as $file) { $file_name = $file['filename']; dd($file); $arr = str2arr($file_name, '-'); $time = Carbon::parse(str_replace('.', '-', $arr[0]))->toDateTimeString(); dd($time); $video_name = $arr[1]; $teacher = str2arr($arr[2], '.')[0]; $path = "zhongjingdaketang/{$file['basename']}"; // $resource = Resource::query()->updateOrCreate([ // 'name' => $file, // 'path' => $path, // 'disk' => 'public', // 'original_name' => $file, // ], [ // 'url' => Storage::disk('public')->url($path) // ]); // Video::query()->updateOrCreate([ // 'course_id' => $course->id, // 'title' => $video_name, // 'url' => $resource->id, // 'short_description' => $video_name, // 'description' => $video_name, // 'published_at' => $time, // ], [ // 'slug' => Str::random(), // 'status' => ModelStatusEnum::OK // ]); } } public static function getVideoDuration($videoPath) { $cmd = "ffmpeg -i " . escapeshellarg($videoPath) . " 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"; exec($cmd, $output, $returnCode); if ($returnCode === 0 && !empty($output)) { $duration = $output[0]; // Convert duration string to seconds $timeParts = explode(':', $duration); $hours = (int)$timeParts[0]; $minutes = (int)$timeParts[1]; $seconds = (float)$timeParts[2]; $totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds; return $totalSeconds; } else { return null; } } }