Files
anime/api/subtitles.php
2025-10-02 13:28:21 +02:00

38 lines
743 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);
$index = $param["s"] ?? 0;
if (!is_dir("video/"))
mkdir("video/");
$err = ffmpeg($path, "video/$cacheid.vtt", ["-map", "0:s:$index"]);
if ($err)
{
header("Content-Type: text/plain");
echo $err;
} else {
header("Location: ../video/$cacheid.vtt", true, 302);
}
// Remove old videos and subtitles
foreach (scandir("video/") as $file)
{
$atime = fileatime("video/$file");
if (time() - $atime > 3600)
unlink("video/$file");
}
?>