Browse Source

add webhook for live video record

feature/new_bilibili_and_instagram_sxs20191126
shixuesen 3 years ago
parent
commit
53d41dec04
4 changed files with 49 additions and 0 deletions
  1. +34
    -0
      app/Http/Controllers/LiveVideoController.php
  2. +13
    -0
      app/Services/FileService.php
  3. +1
    -0
      app/Services/QueuedFfmpegService.php
  4. +1
    -0
      routes/web.php

+ 34
- 0
app/Http/Controllers/LiveVideoController.php View File

@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Services\FileService;
use Illuminate\Http\Request;
use Log;
class LiveVideoController extends Controller
{
const EVENT_TYPE_FILE_CLOSED = "FileClosed";
private $fileService;
public function __construct()
{
$this->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);
}
}

+ 13
- 0
app/Services/FileService.php View File

@ -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) public function copySelectedFilesToMappedDirectory(array $sourceToDestMap)
{ {
foreach ($sourceToDestMap as $sourceDir => $destDir) { foreach ($sourceToDestMap as $sourceDir => $destDir) {


+ 1
- 0
app/Services/QueuedFfmpegService.php View File

@ -42,6 +42,7 @@ class QueuedFfmpegService {
public function addToQueue($file) public function addToQueue($file)
{ {
// BilibiliEncode::dispatch($file); // BilibiliEncode::dispatch($file);
Log::info("add $file to ffmpeg process queue");
Redis::connection()->rpush("file_to_encode", $file); Redis::connection()->rpush("file_to_encode", $file);
// $result = Redis::publish("file_to_process", $file); // $result = Redis::publish("file_to_process", $file);
// echo $result; // echo $result;


+ 1
- 0
routes/web.php View File

@ -11,5 +11,6 @@ Route::get('api/weibo/list', 'WeiboController@list');
Route::post('api/weibo/store', 'WeiboController@store'); Route::post('api/weibo/store', 'WeiboController@store');
Route::get('google/photo/connect', 'GooglePhotoController@connect'); Route::get('google/photo/connect', 'GooglePhotoController@connect');
Route::get('google/photo/index', 'GooglePhotoController@index'); Route::get('google/photo/index', 'GooglePhotoController@index');
Route::post("api/live/video/add", "LiveVideoController@add");

Loading…
Cancel
Save