Are you currently seeking a professional PHP YouTube Video Downloader Script for your web-based application? If so, you’re in the right place. I am excited to share with you my extensively modified PHP script, which serves as an exceptional API system for downloading YouTube videos.
With careful attention to detail, this PHP YouTube downloader script has been developed to ensure seamless performance across all video types, including shorts videos, HD videos, and even 4K videos. Given YouTube’s status as the leading platform for video sharing, it often becomes necessary to obtain these videos for offline use.
If you happen to be a PHP developer, it’s highly likely that you’re in need of a reliable PHP script that enables the direct downloading of YouTube videos onto your local server. Therefore, I am thrilled to present to you my highly acclaimed and widely recognized PHP YouTube Video Downloader Script in this post.
Step – 1
Create index.php file and paste below code.
<?php error_reporting(0); ?>
<?php require './_faction/functions.php'; $error = "";?>
<!DOCTYPE html>
<html>
<title>Youtube to MP4 - Convert Youtube Videos to MP4 HD - Andamantech</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?>">
<meta property="og:url" content="https://andamantech.com/" />
<meta property="og:type" content="website">
<link rel="stylesheet" href="css/main_cs.css">
<link rel="stylesheet" href="css/pasts__.css">
<link rel="stylesheet" href="css/current__.css">
<script
src="https://code.jquery.com/jquery-3.6.0.js"
integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
crossorigin="anonymous"></script>
<body class="noclass" id="mode">
<div id="page">
<header class="navbar navbar-light">
<div class="_container _bar">
<h1 class="brand">
<a href=".">
<img src="img/logo.png" width="110" height="32" alt="Tabler" class="navbar-img">
</a>
</h1>
<div class="_right">
<div class="nightic">
<div class="nav-item">
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="4" /><path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7" /></svg>
</a>
</div>
<div class="nav-item _m-left">
<a href="#?">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 18" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M14 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2" /><path d="M20 12h-13l3 -3m0 6l-3 -3" /></svg>
</a>
</div>
<div class="nav-item _hid-sm _m-left">
<a href="#">
<span class="avatar avatar-sm" style="background-image: url(img/islands.jpg)"></span>
<div class="">Acount</div>
<div class="_tiny text-muted font4">user ID</div>
</a>
</div>
</div>
</div>
</div>
</header>
<div class="navbar navbar-light _top">
<div class="_container _bar" id="myNavbar">
<div class="_hid-sm">
<ul class="navbar menu">
<li class="nav-item active"><a href="." class="_bar-item nav-link">
<span class="nav-link-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><polyline points="5 12 3 12 12 3 21 12 19 12"></polyline><path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7"></path><path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6"></path></svg>
</span>
<span class="nav-link-title">
Home
</span>
</a>
</li>
<li class="nav-item _dropdown-hover">
<div class="_bar-item nav-link">
<span class="nav-link-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><polyline points="12 3 20 7.5 20 16.5 12 21 4 16.5 4 7.5 12 3"></polyline><line x1="12" y1="12" x2="20" y2="7.5"></line><line x1="12" y1="12" x2="12" y2="21"></line><line x1="12" y1="12" x2="4" y2="7.5"></line><line x1="16" y1="5.25" x2="8" y2="9.75"></line></svg>
</span>
<span class="_show-inline-block">About Us</span>
</div>
</li>
<li class="nav-item _dropdown-hover">
<div class="_bar-item nav-link">
<span class="nav-link-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><circle cx="12" cy="10" r="4"></circle><path d="M6.75 16a8.015 8.015 0 1 0 9.25 -13"></path><line x1="12" y1="18" x2="12" y2="22"></line><line x1="8" y1="22" x2="16" y2="22"></line></svg>
</span>
<span class="_show-inline-block">Contact</span>
</div>
</li>
<li class="nav-item _dropdown-hover">
<div class="_bar-item nav-link">
<span class="nav-link-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><circle cx="5" cy="12" r="1"></circle><circle cx="12" cy="12" r="1"></circle><circle cx="19" cy="12" r="1"></circle></svg>
</span>
<span class="_show-inline-block">More</span>
</div>
</li>
</ul>
</div>
<a href="javascript:void(0)" class="_bar-item _button _right _hid-lar" onclick="_a_open()">
≡
</a>
</div>
</div>
<nav class="_sidebar _bar-block _black _card _animate-left _hid-lar" style="display:none" id="mySidebar">
<a href="javascript:void(0)" onclick="_a_close()" class="_bar-item _button _large p_tb-16">Close ×</a>
<a href="javascript:void(0);" onclick="_a_close()" class="_bar-item _button">Home</a>
<a href="javascript:void(0);" onclick="_a_close()" class="_bar-item _button">About Us</a>
<a href="javascript:void(0);" onclick="_a_close()" class="_bar-item _button">Contact</a>
</nav>
<div class="_container p_tb-48">
<div class="_row-padding">
<?php if(isset($_POST['submit'])){ ?>
<?php
error_reporting(0);
$video_link = $_POST['video_link']; // main link
parse_str( parse_url( $video_link, PHP_URL_QUERY ), $parse_url );
$checkurl_= explode("=",parse_url($video_link, PHP_URL_QUERY))[0];
if($checkurl_=="v"){
$video_id = $parse_url['v'];
}
else if($checkurl_=="feature"){
$link_array = explode('/',$video_link);
$clrurl = substr(end($link_array), 0, strpos(end($link_array), "?"));
$video_id=$clrurl;
}
else{
$link_array = explode('/',$video_link);
$video_id=end($link_array);
}
if(strlen($video_id)!="11"){
echo "<h2 class='font8 _center '>php syntax error, unexpected</h2>";
}$video = json_decode(getVideoInfo("$video_id"));
$formats = $video->streamingData->formats;
$adaptiveFormats = $video->streamingData->adaptiveFormats;
$thumbnails = $video->videoDetails->thumbnail->thumbnails;
$title = $video->videoDetails->title;
$short_description = $video->videoDetails->shortDescription;
$thumbnail = end($thumbnails)->url;
}
?>
<div class="_col m4 stickybar">
<div class="_card ctour pricefix_">
<?php if(isset($_POST['submit'])){ ?>
<div class="price">
<div class="d-flex">
<img src="<?php echo $thumbnail; ?>" style="width:100%">
</div>
<div class="card-body">
<h1><?php echo $title; ?></h1>
<p><?php echo str_split($short_description, 100)[0]; ?></p>
</div>
</div>
<?php } else{ ?><img src="img/sidebar.jpg" style="width:100%"><?php } ?>
</div>
</div>
<div class="_col m8">
<div class="_card mark_ ctour">
<div class="">
<div class="p-large">
<form method="post" action="">
<div class="input-group">
<input class="form-control" type="text" name="video_link" placeholder="Paste Youtube link" <?php if(isset($_POST['video_link'])) echo "value='".$_POST['video_link']."'"; ?> required>
</div>
<input type="submit" class="_btn submitbt" value="Convert MP4" name="submit">
<div class="_center text-muted">By using our service you are accepting our terms of service</div>
</form>
<?php if($error) :?>
<div style="color:red;font-weight: bold;text-align: center"><?php print $error?></div>
<?php endif;?>
</div>
<hr>
<div class="p-large">
<div class="p_tb-16"><?php if(!empty($formats)): ?>
<?php if(@$formats[0]->url == ""): ?>
<div class="card formSmall">
<div class="card-header">
<strong>This video is currently not supported by our downloader!</strong>
<small><?php
$signature = "https://example.com?".$formats[0]->signatureCipher;
parse_str( parse_url( $signature, PHP_URL_QUERY ), $parse_signature );
$url = $parse_signature['url']."&sig=".$parse_signature['s'];
?>
</small>
</div>
</div>
<?php
die();
endif;
?>
<div class="card formSmall">
<div class="card-header">
<strong>With Video & Sound</strong>
</div>
<div class="card-body">
<table class="table ">
<tr>
<td>Type</td>
<td>Quality</td>
<td>Download</td>
</tr>
<?php foreach($formats as $format): ?>
<?php
if(@$format->url == ""){
$signature = "https://example.com?".$format->signatureCipher;
parse_str( parse_url( $signature, PHP_URL_QUERY ), $parse_signature );
$url = $parse_signature['url']."&sig=".$parse_signature['s'];
}else{
$url = $format->url;
}
?>
<tr>
<td>
<?php if($format->mimeType) echo explode(";",explode("/",$format->mimeType)[1])[0]; else echo "Unknown";?>
</td>
<td>
<?php if($format->qualityLabel) echo $format->qualityLabel; else echo "Unknown"; ?>
</td>
<td>
<a class="_btn btn-primary"
href="_faction/downloader.php?link=<?php echo urlencode($url)?>&title=<?php echo urlencode($title)?>&type=<?php if($format->mimeType) echo explode(";",explode("/",$format->mimeType)[1])[0]; else echo "mp4";?>"
>Download</a>
</td>
</tr>
</div>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<section class="p_tb-64 swclr">
<div class="_container">
<div class="_card calsec">
<div class="_row-padding">
<div class="_col m5">
<p class="_opacity">Contact Us</p>
<h2 class="font8">Let's Connect to<br>Discuss your Project</h2>
</div>
<div class="_col m7">
<div class="_row-padding">
<div class="_col m6">
<img src="img/icon16.png"><br>
<span class="font5">Call us-</span>
<p>+91-9933266338</p>
</div>
<div class="_col m6">
<img src="img/email.png"><br>
<span class="font5">Drop us a Mail-</span>
<p>[email protected]</p>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<div id="backdrop" class="backdrop mobile-only" style="display: none"></div>
<footer class="footer">
<div class="waves">
<div class="wave" id="wave1"></div>
<div class="wave" id="wave2"></div>
<div class="wave" id="wave3"></div>
<div class="wave" id="wave4"></div>
</div>
<div class="_xlarge _section">
<a href="javascript:0;" class="_text-white"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 10v4h3v7h4v-7h3l1 -4h-4v-2a1 1 0 0 1 1 -1h3v-4h-3a5 5 0 0 0 -5 5v2h-3" /></svg></a>
</div>
<p>Powered by <a href="https://andamantech.com/" title="Andamantech" target="_blank" class="_hover-text-green">Andamantech</a></p>
</footer>
</div>
</body>
</html>
Step – 2
Create folder and file (name functions.php) _faction → functions.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
function getVideoInfo($video_id){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.youtube.com/youtubei/v1/player?key=YOUR_API_KEY');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "context": { "client": { "hl": "en", "clientName": "WEB", "clientVersion": "2.20210721.00.00", "clientFormFactor": "UNKNOWN_FORM_FACTOR", "clientScreen": "WATCH", "mainAppWebInfo": { "graftUrl": "/watch?v='.$video_id.'", } }, "user": { "lockedSafetyMode": false }, "request": { "useSsl": true, "internalExperimentFlags": [], "consistencyTokenJars": [] } }, "videoId": "'.$video_id.'", "playbackContext": { "contentPlaybackContext": { "vis": 0, "splay": false, "autoCaptionsDefaultOn": false, "autonavState": "STATE_NONE", "html5Preference": "HTML5_PREF_WANTS", "lactMilliseconds": "-1" } }, "racyCheckOk": false, "contentCheckOk": false}');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
Step – 3
Create file inside folder you created name (downloader.php) inside _faction → downloader.php
<?php
$downloadURL = urldecode($_GET['link']);
$type = urldecode($_GET['type']);
$title = urldecode($_GET['title']);
$fileName = $title.'.'.$type;
header("Location: $downloadURL&utm_ref=andamantech.com");
This file download force from YouTube video.
I hope you have found the PHP YouTube Video Downloader Script that I have modified to be helpful. Please feel free to download and use it according to your requirements. Additionally, I encourage you to subscribe to my YouTube Channel, TECHboto, where you can find more engaging tutorials and gain inspiration for your future projects.
Really nice pattern and fantastic content, practically
nothing else we need :D.