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

 !( 9Xq}������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������}rZ;.z������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������0O������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Q:����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������<������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������$������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������(��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������$����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������\������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������g���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� l�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������XNOOOOOOOOOOOOONVz��������������������H69999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996H��������������������XNOOOOOOOOOOOOONX�������������������'�����������������L>������������������������������������LK�����������������6`����������������
��������������������������������������������������u����������������(��������������������������������()��������������������������������m��������������������������������������������������������������*������������������������������*+���������������������������������������������������������������������������������������������������������������������������������������%������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&���������������**������������������������������**���������������&����������������������������������������������������������������&����������������((��������������������������������((����������������&��������������������������������������������������������������������&������������������JK������������������������������������JK������������������&��������������������~XNOOOOOOOOOOOOONX����������������������������������������~XNOOOOOOOOOOOOONX��������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&�����������������������������������������������������������<�����>�����������������������������������������������������������&��������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������������������E�����������������������������������������������������������&��������������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������E�����������������D�����������������������������������������������������������&�������������������������������������������������������������������������������D�����������������������������������������������������������&���������������������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	��������������������������E�����������������������������������������������������������&�����������������������������������������������������������	����������������������������E�����������������������������������������������������������&�����������������������������������������������������������	������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������������������������E�����������������������������������������������������������&��������������������XNOOOOOOOOOOOOONVz��������������������	������������������������������������������������������D��������������������XNOOOOOOOOOOOOONX��������������������&������������������L>������������������	��������������������������������������������������������D������������������LK������������������&�����������������
�����������������	����������������������������������������������������������D����������������������������������&����������������(����������������	������������������������������������������������������������D����������������()����������������&����������������m���������������	��������������������������������������������������������������E��������������������������������&���������������*���������������	����������������������������������������������������������������E���������������*+���������������&������������������������������	������������������������������������������������������������������E������������������������������&������������������������������	��������������������������������������������������������������������D������������������������������&������������������������������	����������������������������������������������������������������������9������������������������������&������������������������������	�����������������������������������������������������������������������m������������������������������&������������������������������	������������������������������������������������������������������������X������������������������������&������������������������������	�������������������������������������������������������������������������������������������������������&������������������������������	�������������������������������������������������������������������������i������������������������������&������������������������������	��������������������������������������������������������������������������������������������������������&������������������������������	��������������������������������������������������������������������������������������������������������&������������������������������	��������������������������������������������������������������������������������������������������������&������������������������������	��������������������������������������������������������������������������������������������������������&������������������������������	�������������������������������������������������������������������������j������������������������������&������������������������������	�������������������������������������������������������������������������������������������������������&������������������������������	������������������������������������������������������������������������X������������������������������&������������������������������	�����������������������������������������������������������������������l������������������������������&������������������������������	����������������������������������������������������������������������9������������������������������&������������������������������	��������������������������������������������������������������������E������������������������������&������������������������������	������������������������������������������������������������������E������������������������������&���������������**���������������	����������������������������������������������������������������F���������������**���������������&��������������������������������	��������������������������������������������������������������E��������������������������������&����������������((����������������	������������������������������������������������������������E����������������((����������������&����������������������������������	����������������������������������������������������������E����������������������������������&������������������JK������������������	��������������������������������������������������������D������������������JK������������������&��������������������~XNOOOOOOOOOOOOONX��������������������	������������������������������������������������������D��������������������~XNOOOOOOOOOOOOONX��������������������&�����������������������������������������������������������	����������������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	������������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	����������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	��������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	������������������������������F�����������������������������������������������������������&�����������������������������������������������������������	����������������������������F�����������������������������������������������������������&�����������������������������������������������������������	��������������������������F�����������������������������������������������������������&�����������������������������������������������������������������������������������F�����������������������������������������������������������&���������������������������������������������������������������������������������F�����������������������������������������������������������&�������������������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������F�����������������E�����������������������������������������������������������&��������������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������������������F�����������������������������������������������������������&��������������������������������������������������������������������E�����������������������������������������������������������&�����������������������������������������������������������D�����@�����������������������������������������������������������&�����������������������������������������������������������	�����������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&����������������������������������������������������������������������������������������������������������������������&��������������������XNOOOOOOOOOOOOONVz����������������������������������������XNOOOOOOOOOOOOONX��������������������&������������������L>������������������������������������LK������������������&�����������������
���������������������������������������������������&����������������(��������������������������������()����������������&����������������m�����������������������������������������������&���������������*������������������������������*+���������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������&������������������������������������������������������������%���������������������������������������������������������������������������**������������������������������**�����������������������������������������������������������������������������������������������((��������������������������������((����������������a������������������������������������������������������������������q'�����������������JK������������������������������������JK�����������������2�������������������~XNOOOOOOOOOOOOONX��������������������H69999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996H��������������������~XNOOOOOOOOOOOOONX�������������������k����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������y���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������U������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������`����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������z�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������1����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������7F������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������L*v������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������|-8Wq}������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������}qX8

index.php

<?php
include('base.php');

if (empty($vidID)) {
    echo "
<head>
<title>YouTube Embed Helper</title>
    <style>
        body {
            background-color: #2d2d2d;
            color: white;
        }

        a {
            color: white;
            text-decoration: underline;
        }
    </style>
</head><body>";

    // Display the form for entering the video ID
    echo "<h1>YouTube Embed Helper</h1>";
    if (!empty($proxy)) {
        echo "<p>(including Media Proxy)</p>";
    }
    echo '<form method="post" action="input.php">';
    echo '<input style="width:100%;" type="password" name="pwd" placeholder="Password"><br>';
    echo '<input style="width:100%;" type="text" name="vid" placeholder="Video ID or URL"><br>';
    echo '<input type="radio" name="format" value="watch" checked> <label>Watch here</label>';
    echo '<input type="radio" name="format" value="html"> <label>Generate Embed Code</label>';
    echo '<input type="radio" name="format" value="video"> <label>Video</label>';
    echo '<input type="radio" name="format" value="audio"> <label>Audio</label>';
    echo '<input type="radio" name="format" value="image"> <label>Thumbnail</label>';
    echo '<input type="radio" name="format" value="json"> <label>Metadata/JSON</label>';
    echo '<br><input type="submit" value="Do it"></form>';
    echo '<hr><h2>Site for private use only!</h2><p>This site is not meant for public use. Please search for another Project or selfhost using the <a href="source-code.php">Source Code</a>.</p>';
    echo "</body>";
    exit();
}

switch ($action) {
    case "get-chat":
        // get Link to Live Chat (only YouTube)
        $command = "$yt_dlp_path --get-id {$vidID}";
        $output = shell_exec($command);
        if (empty($output)) {
            echo "There was an Error<br>Tries again in 15 Seconds<br><meta http-equiv='refresh' content='15'>";
            exit();
        }
        $output = "https://studio.youtube.com/live_chat?is_popout=1&v=$output";
        break;

    case "audio":
        // get Link to audio (cache not used for reason: getting video, not audio)
        $command = "$yt_dlp_path --prefer-free-formats -x --get-url {$vidID}";
        $output = shell_exec($command);

        break;
    case "image":
        // get Link to thumbnail
        $output = $data["thumbnail"];
        break;

    case "html":
        // show how to embed on website
        echo "
<head>
<title>YouTube Embed Code</title>
    <style>
        body {
            background-color: #2d2d2d;
            color: white;
        }

        a {
            color: white;
            text-decoration: underline;
        }
    </style>
</head><body>";
        echo "<p>You can use this Code to embed the Video on your Website:</p>";
        echo "<h1>Video:</h1>";
        echo "<code>&lt;video preload='none' controls src='$currentURL?vid=$vidID' poster='$currentURL?vid=$vidID&format=image'&gt;&lt;/video&gt;</code><br>";
        echo "<video preload='none' controls src='$currentURL?vid=$vidID' poster='$currentURL?vid=$vidID&format=image'></video>";
        echo "<h1>Audio:</h1>";
        echo "<code>&lt;audio preload='none' controls src='$currentURL?vid=$vidID&format=audio'&gt;&lt;/audio&gt;</code><br>";
        echo "<audio preload='none' controls src='$currentURL?vid=$vidID&format=audio'></audio>";
        echo "<h2>About Livestreams</h2>YouTube, Twitch and other Livestreaming platforms will return m3u8 files. The Video/Audio Tag is not able to Play m3u8 files. You might be able to get it working with special javascript code. You can still use URLs like '$currentURL?vid=$vidID' in VLC.";
        echo "</body>";
        exit();
    case "json":
        // give out metadata about video
        header("Content-Type: application/json");
        echo "$jsonData";
        exit();

    case "watch":
        // prettyfy link a bit
        if ($data["extractor"] == "youtube") {
            $vidID = $data["id"];
        }
        header("Location: $currentURL/watch?v=$vidID"); // not using below header bc: you might use a proxy
        break;
    case "sub_proxy":
        // subtitle Proxy (Cross Origin is bad)
	if (empty($vidID)) {
            die("Error: VTT URL is missing.");
        }
        header("Content-Type: text/vtt; charset=UTF-8");
	$vttContent = file_get_contents($vidID);
	echo $vttContent;
        exit();

    default:
        // get the Link to the Video
        $output = $data["url"];
}

if (!empty($output)) {
    // Redirect to the YouTube video with the specified ID (Through my proxy to further reduce tracking.)
    header("Location: $proxy$output");
    exit();
} else {
    // Display an error message if the command failed
    echo "<h1>Error</h1>";
    echo "<p>The specified video ID ($vidID) could not be downloaded.</p>";
    echo "<p>Please try again.</p>";
    exit();
}
?>

input.php

<?php
$vid = $_POST['vid'];
$pwd = md5($_POST['pwd'] . "youtube-who-likes-you?");
$format = $_POST['format'];

if($pwd == '5b490991b81c2693eeef70330db790d7') header("Location: ..?vid=$vid&format=$format");
else echo "Wrong Password. <a href='..'>Go Back home!</a>";
?>

source-code.php

<?php
function getAllFiles($dir) {
    $files = glob($dir . '/*');
    $allFiles = [];
    
    foreach ($files as $file) {
        if (is_dir($file)) {
            $allFiles = array_merge($allFiles, getAllFiles($file));
        } else {
            $allFiles[] = $file;
        }
    }
    
    return $allFiles;
}

$currentDir = __DIR__; // Current directory
$allFiles = getAllFiles($currentDir);

// Output the list of files with "/var/www/my_webapp__3/www/" removed
foreach ($allFiles as $file) {
    $cleanedFilePath = str_replace("$currentDir/", "", $file);
    echo "<h1>$cleanedFilePath</h1>";
    $content = file_get_contents($file);
    echo '<pre>', htmlspecialchars($content), '</pre>';
}
?>

watch/index.php

<?php

if (empty($_GET["v"])) {
    echo "Please provide Video ID or URL! Go <a href='..'>home</a>";
    exit();
} else {
    $vidID = $_GET["v"];
    $correctPath = "../";
    include "../base.php";
}

// Video Infos
$title = $data["title"];
$uploaderName = $data["channel"];
$uploaderUrl = $data["channel_url"];
$channelSubs = $data["channel_follower_count"];
if ($data["channel_is_verified"]) {
    $verify = "✓";
}
$vidUrl = $data["url"];
$thumbnail = $data["thumbnail"];
$description = nl2br(
    htmlspecialchars($data["description"], ENT_QUOTES, "UTF-8")
);
if (empty($description)) {
    $description = "This videos Description is empty.";
}
$vidLikes = $data["like_count"];
$vidDate = $data["upload_date"];
$vidDate = DateTime::createFromFormat("Ymd", $vidDate);
$vidDate = $vidDate->format("F j, Y");
$vidViews = $data["view_count"];
$vidComments = $data["comment_count"];
$vidHeight = $data["height"];
$vidWidth = $data["width"];
$platform = $data["extractor_key"];
$vidShare = $data["webpage_url"];
if (!empty($proxy)) {
    $proxyText = "This site proxies every connection to $platform.";
}
// Building site
$cleaned_title = trim(str_replace("'", "", "$title - $uploaderName - $platform")); // Meta Title without ' for meta title (SEO)
echo "<!DOCTYPE html> 
<html lang='{$data["language"]}'>
<head>
    <meta charset='UTF-8'>
    <meta property='og:title' content='$cleaned_title'>
    <meta property='og:description' content='$description'>
    <meta property='og:image' content='$proxy$thumbnail'>
    <meta property='og:video' content='{$currentURL}?vid=$vidID'>
    <meta property='og:video:secure_url' content='{$currentURL}?vid=$vidID'>
    <meta property='og:video:type' content='video/mp4'>
    <meta property='og:video:width' content='vidWidth'>
    <meta property='og:video:height' content='$vidHeight'>
    <meta property='og:video:poster' content='$proxy$thumbnail'>
    <title>$title - $uploaderName - $platform</title>
    <style>
        body {
            background-color: #2d2d2d;
            color: white;
        }

        a {
            color: white;
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div style='width: 80%; margin-left: 10%;'>
<h1>$title</h1>
<video class='center' controls poster='$proxy$thumbnail' src='$proxy$vidUrl' style='margin-left:auto;margin-right:auto;display:block; max-height:80vh;max-width:100%'>
";
//Subtitles TODO: Optimize!
if (isset($data["subtitles"]) && is_array($data["subtitles"])) {
    // Loop through each language
    foreach ($data["subtitles"] as $langCode => $languageSubtitles) {
        foreach ($languageSubtitles as $subtitle) {
            if ($subtitle["ext"] == "vtt") {
                $url = urlencode($subtitle["url"]);
                echo "<track label='{$subtitle["name"]}' kind='subtitles' srclang='$langCode' src='../?format=sub_proxy&vid=$url'/>";
            }
        }
    }
}

// Auto Subtitles (Original)
if (
    isset($data["automatic_captions"]) &&
    is_array($data["automatic_captions"])
) {
    // Loop through each language
    foreach ($data["automatic_captions"] as $langCode => $languageSubtitles) {
        foreach ($languageSubtitles as $subtitle) {
            if (
                $subtitle["ext"] == "vtt" &&
                !empty($subtitle["name"]) &&
                stripos($subtitle["name"], "original")
            ) {
                $url = urlencode($subtitle["url"]);
                echo "<track label='Auto-{$subtitle["name"]}' kind='subtitles' srclang='$langCode' src='../?format=sub_proxy&vid=$url'/>";
            }
        }
    }
}

// Auto Subtitles
if (
    isset($data["automatic_captions"]) &&
    is_array($data["automatic_captions"])
) {
    // Loop through each language
    foreach ($data["automatic_captions"] as $langCode => $languageSubtitles) {
        foreach ($languageSubtitles as $subtitle) {
            if (
                $subtitle["ext"] == "vtt" &&
                !empty($subtitle["name"]) &&
                !stripos($subtitle["name"], "original")
            ) {
                $url = urlencode($subtitle["url"]);
                echo "<track label='Auto-{$subtitle["name"]}' kind='subtitles' srclang='$langCode' src='../?format=sub_proxy&vid=$url'/>";
            }
        }
    }
}

echo "
</video>
<p><a href='$uploaderUrl' target='_blank'>$uploaderName</a>$verify($channelSubs) | $vidDate | 👀 $vidViews | 👍 $vidLikes | 💬 $vidComments</p>
<hr><p>Availability: {$data["availability"]} | Age Limit: {$data["age_limit"]}<br>Category: ";
foreach ($data["categories"] as $tag) {
    echo "$tag ";
}
if (!empty($data["tags"])) {
    echo "<br>Tags: ";
}
foreach ($data["tags"] as $tag) {
    echo "$tag, ";
}
echo "</p>
<p><a href='$vidShare' target='_blank'>Open on $platform</a> | <a href='..?vid=$vidID&format=html' target='_blank'>Embed Code</a></p>
<hr>
<h2>Description</h2>
<p>$description</p>
</div><br>
<small>Disclaimer: this site doesn't host any of the above content. It is hosted on $platform. $proxyText Please send (DMCA) Takedown requests directly to $platform!</small>
</body>
</html>";

?>