Files
anime/api/subtitles.php

38 lines
743 B
PHP
Raw Permalink Normal View History

2025-10-02 13:07:50 +02:00
<?php
chdir("..");
require_once "src/util.php";
require_once "src/ffmpeg.php";
$query = $_SERVER["QUERY_STRING"];
parse_str($query, $param);
2025-10-02 13:28:21 +02:00
$cacheid = hash("sha256", $query);
2025-10-02 13:07:50 +02:00
$path = urlsafe_b64decode($param["file"]);
$path = "./" . $path;
$path = str_replace("..", "", $path);
$index = $param["s"] ?? 0;
if (!is_dir("video/"))
mkdir("video/");
2025-10-02 13:28:21 +02:00
$err = ffmpeg($path, "video/$cacheid.vtt", ["-map", "0:s:$index"]);
2025-10-02 13:07:50 +02:00
if ($err)
{
header("Content-Type: text/plain");
echo $err;
} else {
2025-10-02 13:28:21 +02:00
header("Location: ../video/$cacheid.vtt", true, 302);
2025-10-02 13:07:50 +02:00
}
// Remove old videos and subtitles
foreach (scandir("video/") as $file)
{
$atime = fileatime("video/$file");
if (time() - $atime > 3600)
unlink("video/$file");
}
?>