Files
anime/api/video.php

39 lines
832 B
PHP

<?php
chdir("..");
require_once "src/util.php";
require_once "src/ffmpeg.php";
$query = $_SERVER["QUERY_STRING"];
parse_str($query, $param);
$cacheid = hash("sha256", $query);
$path = urlsafe_b64decode($param["file"]);
$path = "./" . $path;
$path = str_replace("..", "", $path);
$video = $param["v"] ?? 0;
$audio = $param["a"] ?? 0;
if (!is_dir("video/"))
mkdir("video/");
$err = ffmpeg($path, "video/$cacheid.mp4", ["-movflags", "faststart", "-map", "0:v:$video", "-map", "0:a:$audio", "-c", "copy"]);
if ($err)
{
header("Content-Type: text/plain");
echo $err;
} else {
header("Location: ../video/$cacheid.mp4", true, 302);
}
// Remove old videos and subtitles
foreach (scandir("video/") as $file)
{
$atime = fileatime("video/$file");
if (time() - $atime > 3600)
unlink("video/$file");
}
?>