base.php
<?php
// ini_set('display_errors', 1);
// error_reporting(E_ALL);
// !!! HEAD !!!
if ($_GET["proxy"] != "false") {
$proxy = "https://proxy.dhusch.de/";
} // enter CORS proxy if wanted (with trailing /)
$mail = "yt-embed@dhusch.de";
$yt_dlp_path = "$correctPath../bin/yt-dlp"; // where is yt-dlp installed?
$cache_path = "$correctPath../cache/";
// get the URL, where this script is installed
$protocol =
isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on"
? "https://"
: "http://";
$host = $_SERVER["HTTP_HOST"];
$currentURL = $protocol . $host;
// !!! HEAD END !!!
// Get Vid ID
if (!empty($_GET["vid"]) or !empty($vidID)) {
if (!empty($_GET["vid"])) {
$vidID = $_GET["vid"];
$action = $_GET["format"];
}
// Delete files older than one hour in the cache directory
$files = glob($cache_path . "*.json");
$currentTimestamp = time();
foreach ($files as $file) {
$fileAge = $currentTimestamp - filemtime($file);
if ($fileAge > 3600) {
unlink($file);
}
}
// read cache and create if necessary
if (
!file_exists($cache_path . md5($vidID) . ".json") or
$_GET["cache"] == "false"
) {
$jsonCmd = shell_exec(
"$yt_dlp_path -j -f 'best/bestvideo+bestaudio' $vidID"
);
file_put_contents($cache_path . md5($vidID) . ".json", $jsonCmd);
}
$jsonData = file_get_contents($cache_path . md5($vidID) . ".json");
$data = json_decode($jsonData, true);
}
favicon.ico