How to Download Video from Youtube online using Php Script

Authors: CodeToday | PHP Code | Views: 739 | Posted: 04 AM: 09/14/2017

In the normal way, if you want to download videos from youtube you need software or add on the browser, today I will guide the download direct link using the php script

To get the download link from youtube video, you do not need to have youtube API key, you just need Video ID

Ex:, Video ID: 4rb8aOzy9t4

Link to get information from youtube below:

You can change the Video ID depending on the video you want to download. After running the link above, the results shown below:

You can use the php script to analyze this data like the code below

PHP Script Source Code

$url     = '';
$data    = curlGet($url);
$getInfo = urldecode($data); 

$arrayInfo = explode("&",str_replace(',','&',$getInfo));

echo '<ul>';

foreach($arrayInfo as $info) { $i++;

   if(stristr($info,"") == true ) { 
      $info = str_replace(',','&',$info);
	  $linkVideo = str_replace(array(',','?'),array('&','?type=&'),$url);	  // Fix for get Mime		    
	      if(stristr($linkVideo,"") == false)  {
		        $link = $linkVideo.'&title='. urlencode($title);				
				echo '<li>'.$link.'</li>';				
echo '</ul>';	

function curlGet($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HTTPGET, 1 );
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_URL, $url );
	curl_setopt($ch, CURLOPT_REFERER, $ref );
	curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	$data = curl_exec($ch);
	return $data;

Below is the result obtained when running the code above, with this result you can display and filter according to the format you want to display.

How to Download Video from Youtube online using Php Script

If you have any questions, please leave a message below