From 51adf19eae6ca40e29135eceaa39120bfdabf260 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 17 Mar 2023 14:11:18 -0700 Subject: [PATCH] video: support new vod post api Signed-off-by: Varun Patil --- lib/Controller/VideoController.php | 50 +++++++++++++++++++++++------- scripts/get-exiftool.sh | 2 +- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index 4d75bc41..44872962 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -196,19 +196,18 @@ class VideoController extends ApiBase // Transcode video if allowed if ($transcode && !$this->config->getSystemValue('memories.vod.disable', true)) { - // If video path not given, write to temp file - if (!$liveVideoPath) { - $liveVideoPath = tempnam(sys_get_temp_dir(), 'livevideo'); - file_put_contents($liveVideoPath, $blob); + try { + // If video path not given, write to temp file + if (!$liveVideoPath) { + $liveVideoPath = self::postFile($transcode, $blob)['path']; + } - register_shutdown_function(function () use ($liveVideoPath) { - unlink($liveVideoPath); - }); - } - - // If this is H.264 it won't get transcoded anyway - if ($this->getUpstream($transcode, $liveVideoPath, 'max.mov') === 200) { - exit; + // If this is H.264 it won't get transcoded anyway + if ($liveVideoPath && 200 === $this->getUpstream($transcode, $liveVideoPath, 'max.mov')) { + exit; + } + } catch (\Exception $e) { + // Transcoding failed, just return the original video } } @@ -408,6 +407,33 @@ class VideoController extends ApiBase return $returnCode; } + /** + * POST to go-vod to create a temporary file. + * + * @param mixed $blob + */ + private static function postFile(string $client, $blob) + { + $url = self::getGoVodUrl($client, '/create', 'ignore'); + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $blob); + + $response = curl_exec($ch); + $returnCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if (200 !== $returnCode) { + throw new \Exception("Could not create temporary file ({$returnCode})"); + } + + return json_decode($response, true); + } + /** * Construct the goVod config JSON and put it to a file. * diff --git a/scripts/get-exiftool.sh b/scripts/get-exiftool.sh index 48e403c4..d54ec050 100755 --- a/scripts/get-exiftool.sh +++ b/scripts/get-exiftool.sh @@ -20,7 +20,7 @@ mv "exiftool-$exifver" exiftool rm -rf *.zip exiftool/t exiftool/html chmod 755 exiftool/exiftool -govod="0.0.32" +govod="0.0.33" echo "Getting go-vod $govod" wget -q "https://github.com/pulsejet/go-vod/releases/download/$govod/go-vod-amd64" wget -q "https://github.com/pulsejet/go-vod/releases/download/$govod/go-vod-aarch64"