Skip to content

Instantly share code, notes, and snippets.

@iGlitch
Last active April 11, 2025 17:58
Show Gist options
  • Save iGlitch/8621b1afa6ed707a57bd31fb140cd33d to your computer and use it in GitHub Desktop.
Save iGlitch/8621b1afa6ed707a57bd31fb140cd33d to your computer and use it in GitHub Desktop.
Simple Front-end for YT-DLP
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['link']) && function_exists('shell_exec')) {
$link = escapeshellarg($_POST['link']);
$unique_dir = 'downloads/' . time();
mkdir($unique_dir, 0777, true);
$command = "TMPDIR=/home/username/tmp-dl /home/username/yt-dlp_linux -o '$unique_dir/[watermarkdomainthing.com] %(title)s.%(ext)s' $link";
// Add audio only option if checked
if (isset($_POST['audioOnly'])) {
$command .= " -f bestaudio -x --embed-thumbnail";
// need to add --audio-format mp3 above inside the quotation marks, but there is no FFMPEG installed...
} else {
$command .= " ";
}
// If prefer to have USER INPUTTED PROXY DATA.
/*if (!empty($_POST['proxyHost']) && !empty($_POST['proxyPort']) && !empty($_POST['proxyUsername']) && !empty($_POST['proxyPassword'])) {
$proxyHost = escapeshellarg($_POST['proxyHost']);
$proxyPort = escapeshellarg($_POST['proxyPort']);
$proxyUsername = escapeshellarg($_POST['proxyUsername']);
$proxyPassword = escapeshellarg($_POST['proxyPassword']);
$proxyProtocol = escapeshellarg($_POST['proxyProtocol']);
$command .= " --no-check-certificate --proxy $proxyProtocol:$proxyUsername:$proxyPassword@$proxyHost:$proxyPort";
}*/
if (isset($_POST['useProxy'])) {
// Hardcoded proxies
$proxySettings = [
'136.0.194.169' => [
'port' => '6906',
'username' => 'sdrvxrwm',
'password' => 'tpbkz3g46yen',
'protocol' => 'http'
],
'216.74.115.167' => [
'port' => '6761',
'username' => 'sdrvxrwm',
'password' => 'tpbkz3g46yen',
'protocol' => 'http'
],
];
// Random proxy
$selectedHost = array_rand($proxySettings);
// Retrieve the corresponding settings for the selected host
$proxyHost = str_replace("'", "", escapeshellarg($selectedHost));
$proxyPort = str_replace("'", "", escapeshellarg($proxySettings[$selectedHost]['port']));
$proxyUsername = str_replace("'", "", escapeshellarg($proxySettings[$selectedHost]['username']));
$proxyPassword = str_replace("'", "", escapeshellarg($proxySettings[$selectedHost]['password']));
$proxyProtocol = str_replace("'", "", escapeshellarg($proxySettings[$selectedHost]['protocol']));
// Add proxy settings to the command
$command .= " --no-check-certificate --proxy '$proxyProtocol://$proxyUsername:$proxyPassword@$proxyHost:$proxyPort'";
}
// Check for user-agent setting and add it to the command
if (!empty($_POST['userAgent'])) {
$userAgent = escapeshellarg($_POST['userAgent']);
$command .= " --user-agent $userAgent";
}
if (isset($_FILES['proxyCookies']) && $_FILES['proxyCookies']['error'] == 0) {
$uploadedFilePath = $_FILES['proxyCookies']['tmp_name'];
// Optionally, move the file to a permanent location if needed
// $destination = '/path/to/uploads/' . basename($_FILES['proxyCookies']['name']);
// move_uploaded_file($uploadedFilePath, $destination);
$escapedFilePath = escapeshellarg($uploadedFilePath);
$command .= " --cookies $escapedFilePath";
}
$output = shell_exec($command);
// Check if the download was successful
if ($output === null) {
echo "Error: execution failed.";
} else {
$video_files = glob("$unique_dir/*.{mp4,mkv,webm,m2ts,ts,m4a,mp3,opus,aac,flac}", GLOB_BRACE);
if (!empty($video_files)) {
$video_file = $video_files[0];
if (file_exists($video_file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($video_file) . '"');
header('Content-Length: ' . filesize($video_file));
readfile($video_file);
// Remove the downloaded video file after
unlink($video_file);
rmdir($unique_dir);
exit;
} else {
echo "Error: Video file not found after download.";
}
} else {
rmdir($unique_dir);
echo "Error: No video file found.";
}
}
} else {
echo "Error: Invalid input or shell_exec not allowed.";
}
exit;
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YT-DLP Downloader - Download Youtube, Facebook, Instagram, Tiktok, Twitter Videos</title>
<meta name="description" content="The simplest working solution to downloading videos with the URL straight from the browser!" />
<meta name="author" content="Glitch">
<meta name="theme-color" content="#FFDB47">
<meta name="keywords" content="youtube downloader, youtube to mp3, youtube2mp3, url to mp3" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body, html {
height: 100%;
margin: 0;
background-color:#222;
color:white;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
@media (max-width: 768px) {
body {
width: 100%;
}
}
.input-group {
max-width: 700px;
margin-top: 20px;
}
.form-control {
border-radius: 15px;
padding: 15px;
font-size: 16px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.3s ease;
}
.form-control:focus {
box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
border-color: #007bff;
}
.btn {
border-radius: 15px;
padding: 10px 20px;
font-size: 16px;
background-color: #007bff;
color: white;
border: none;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #0056b3;
}
.alert {
margin-top: 20px;
display: none;
}
.advanced-settings {
display: none;
margin-top: 20px;
text-align: left;
}
.advanced-settings input, .advanced-settings select, .advanced-settings textarea {
margin-bottom: 10px;
}
.advanced-settings label {
font-weight: bold;
}
</style>
</head>
<body onselectstart="return false;" oncontextmenu="return false;">
<div class="container px-3 py-4">
<div class="text-center">
<img src="/logo.webp" alt="Logo" class="img-fluid"/>
</div>
<div class="row">
<form id="urlForm" enctype="multipart/form-data" method="POST">
<div class="input-group">
<input type="text" id="urlInput" name="link" class="form-control" placeholder="Paste your URL here" required>
<button class="btn" type="submit">Submit</button>
</div>
<!-- Audio Only Checkbox -->
<div class="form-check mt-3">
<input class="form-check-input" type="checkbox" id="audioOnly" name="audioOnly">
<label class="form-check-label" for="audioOnly">
Audio Only
</label>
</div>
<!-- Advanced Settings Toggle -->
<div class="form-check mt-3">
<input class="form-check-input" type="checkbox" id="toggleAdvancedSettings">
<label class="form-check-label" for="toggleAdvancedSettings">
Advanced Settings
</label>
</div>
<!-- Advanced Settings Section -->
<div id="advancedSettings" class="advanced-settings">
<!-- Use Proxy -->
<div class="form-check mt-3">
<input class="form-check-input" type="checkbox" id="useProxy" name="useProxy" checked>
<label class="form-check-label" for="useProxy">
Use Proxy
</label>
</div>
<!--<div class="mb-3">
<label for="proxyHost" class="form-label">Proxy Host</label>
<input type="text" id="proxyHost" name="proxyHost" class="form-control" placeholder="Enter Proxy Host">
</div>
<div class="mb-3">
<label for="proxyPort" class="form-label">Proxy Port</label>
<input type="number" id="proxyPort" name="proxyPort" class="form-control" placeholder="Enter Proxy Port">
</div>
<div class="mb-3">
<label for="proxyUsername" class="form-label">Proxy Username</label>
<input type="text" id="proxyUsername" name="proxyUsername" class="form-control" placeholder="Enter Proxy Username">
</div>
<div class="mb-3">
<label for="proxyPassword" class="form-label">Proxy Password</label>
<input type="password" id="proxyPassword" name="proxyPassword" class="form-control" placeholder="Enter Proxy Password">
</div>
<div class="mb-3">
<label for="proxyProtocol" class="form-label">Proxy Protocol</label>
<select id="proxyProtocol" name="proxyProtocol" class="form-select">
<option value="http">HTTP</option>
<option value="https">HTTPS</option>
<option selected value="socks5">SOCKS5</option>
</select>
</div>-->
<div class="mb-3">
<label for="cookies" class="form-label">Cookies</label>
<input type="file" id="cookies" name="proxyCookies" class="form-control" accept=".txt">
</div>
<div class="mb-3">
<label for="userAgent" class="form-label">User Agent</label>
<input type="text" id="userAgent" name="userAgent" class="form-control" placeholder="Enter User Agent">
</div>
</div>
</form>
</div>
</div>
<script>
document.getElementById('urlInput').addEventListener('input', function() {
var urlInput = document.getElementById('urlInput').value;
var submitButton = document.querySelector('button[type="submit"]');
if (urlInput.includes('http') && urlInput.length >= 10) {
submitButton.disabled = false;
} else {
submitButton.disabled = true;
}
});
document.getElementById('toggleAdvancedSettings').addEventListener('change', function() {
var advancedSettings = document.getElementById('advancedSettings');
if (this.checked) {
advancedSettings.style.display = 'block';
} else {
advancedSettings.style.display = 'none';
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js" integrity="sha512-7Pi/otdlbbCR+LnW+F7PwFcSDJOuUJB3OxtEHbg4vSMvzvJjde4Po1v4BR9Gdc9aXNUNFVUY+SK51wWT8WF0Gg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment