diff --git a/app/Http/Controllers/LiveVideoController.php b/app/Http/Controllers/LiveVideoController.php new file mode 100644 index 0000000..7537681 --- /dev/null +++ b/app/Http/Controllers/LiveVideoController.php @@ -0,0 +1,34 @@ +fileService = new FileService(); + } + + // + public function add(Request $request) + { + $data = $request->json()->all(); + $eventType = $data["EventType"]; + $eventData = $data["EventData"]; + Log::info("bilibili live record webhook data : ", json_encode($data)); + if ($eventType == self::EVENT_TYPE_FILE_CLOSED) { + Log::info($eventData["RelativePath"]); + $this->fileService->renameFileAndAddToQueue("/mnt/e/rec/" . $eventData["RelativePath"], "flv", "mp4"); + } +// Log::info($data["EventData"]); +// Log::info($data["EventType"]); + return response("", 200); + } +} diff --git a/app/Services/FileService.php b/app/Services/FileService.php index a47cf13..39f1e66 100644 --- a/app/Services/FileService.php +++ b/app/Services/FileService.php @@ -1242,6 +1242,19 @@ class FileService { } } + public function renameFileAndAddToQueue($file, $fromExtension, $toExtension) + { + if (is_file($file)) { + $pathInfo = pathinfo($file); + if ($pathInfo[PATHINFO_EXTENSION] == $fromExtension) { + $newFile = str_replace($fromExtension, $toExtension, $file); + dump("now rename file $file to $newFile"); + rename($file, $newFile); + $this->queuedFfmpegService->addToQueue($newFile); + } + } + } + public function copySelectedFilesToMappedDirectory(array $sourceToDestMap) { foreach ($sourceToDestMap as $sourceDir => $destDir) { diff --git a/app/Services/QueuedFfmpegService.php b/app/Services/QueuedFfmpegService.php index 9f7a11c..6239e38 100644 --- a/app/Services/QueuedFfmpegService.php +++ b/app/Services/QueuedFfmpegService.php @@ -42,6 +42,7 @@ class QueuedFfmpegService { public function addToQueue($file) { // BilibiliEncode::dispatch($file); + Log::info("add $file to ffmpeg process queue"); Redis::connection()->rpush("file_to_encode", $file); // $result = Redis::publish("file_to_process", $file); // echo $result; diff --git a/routes/web.php b/routes/web.php index e560890..4816907 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,5 +11,6 @@ Route::get('api/weibo/list', 'WeiboController@list'); Route::post('api/weibo/store', 'WeiboController@store'); Route::get('google/photo/connect', 'GooglePhotoController@connect'); Route::get('google/photo/index', 'GooglePhotoController@index'); +Route::post("api/live/video/add", "LiveVideoController@add");