Initial commit
This commit is contained in:
36
api/info.php
Normal file
36
api/info.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
chdir("..");
|
||||
require_once "src/util.php";
|
||||
|
||||
$query = $_SERVER["QUERY_STRING"];
|
||||
parse_str($query, $param);
|
||||
|
||||
$path = urlsafe_b64decode($param["file"]);
|
||||
$path = "./" . $path;
|
||||
$path = str_replace("..", "", $path);
|
||||
|
||||
$descSpec = [
|
||||
0 => array("pipe", "r"),
|
||||
1 => array("pipe", "w"),
|
||||
2 => array("pipe", "w"),
|
||||
];
|
||||
$proc = proc_open(["ffprobe", "-show_streams", "-of", "json", $path], $descSpec, $pipes);
|
||||
|
||||
fclose($pipes[0]);
|
||||
|
||||
$stdout = stream_get_contents($pipes[1]);
|
||||
$stderr = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
|
||||
$code = proc_close($proc);
|
||||
|
||||
if ($code)
|
||||
{
|
||||
header("Content-Type: text/plain");
|
||||
echo $stderr;
|
||||
} else {
|
||||
header("Content-Type: application/json");
|
||||
echo $stdout;
|
||||
}
|
||||
?>
|
||||
35
api/subtitles.php
Normal file
35
api/subtitles.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
chdir("..");
|
||||
require_once "src/util.php";
|
||||
require_once "src/ffmpeg.php";
|
||||
|
||||
$query = $_SERVER["QUERY_STRING"];
|
||||
parse_str($query, $param);
|
||||
|
||||
$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/$query.vtt", ["-map", "0:s:$index"]);
|
||||
|
||||
if ($err)
|
||||
{
|
||||
header("Content-Type: text/plain");
|
||||
echo $err;
|
||||
} else {
|
||||
header("Location: ../video/$query.vtt", true, 302);
|
||||
}
|
||||
|
||||
// Remove old videos and subtitles
|
||||
foreach (scandir("video/") as $file)
|
||||
{
|
||||
$atime = fileatime("video/$file");
|
||||
if (time() - $atime > 3600)
|
||||
unlink("video/$file");
|
||||
}
|
||||
?>
|
||||
36
api/video.php
Normal file
36
api/video.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
chdir("..");
|
||||
require_once "src/util.php";
|
||||
require_once "src/ffmpeg.php";
|
||||
|
||||
$query = $_SERVER["QUERY_STRING"];
|
||||
parse_str($query, $param);
|
||||
|
||||
$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/$query.mp4", ["-map", "0:v:$video", "-map", "0:a:$audio", "-c", "copy"]);
|
||||
|
||||
if ($err)
|
||||
{
|
||||
header("Content-Type: text/plain");
|
||||
echo $err;
|
||||
} else {
|
||||
header("Location: ../video/$query.mp4", true, 302);
|
||||
}
|
||||
|
||||
// Remove old videos and subtitles
|
||||
foreach (scandir("video/") as $file)
|
||||
{
|
||||
$atime = fileatime("video/$file");
|
||||
if (time() - $atime > 3600)
|
||||
unlink("video/$file");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user