Location: PHPKode > scripts > YouTube video download > youtubedownload_Class.php
<?php
//Copyrights Abdulkadir kucuk www.dersanlat.com
//Copyrights Abdulkadir kucuk www.dersanlat.com
//working version http://www.dersanlat.com/ytb/
//proxy 89.208.32.109:3128
//64.66.192.62:32080
class youtubedownload {
public $url;
public $methodi;
private $proxy='64.66.192.62:32080';
private $useproxy=0; // if you don't want to use proxy make it 0
public function download($url,$methodi){
@ini_set('output_buffering','off');
@ini_set('max_execution_time',0); 
@ini_set('memory_limit', '128M');
@error_reporting(E_ALL);
@ignore_user_abort(1);
@set_time_limit(0);
@ob_implicit_flush(TRUE);
$url=$url.'&k=2';
if($url<>'' && $url<>'http://www.youtube.com/' && $url<>'http://www.youtube.com'){
@preg_match_all("|v=?(.*)&|U",$url,$resulti, PREG_SET_ORDER);
$id=$resulti[0][0];
$id=str_replace('v=','',$id);
$id=str_replace('&','',$id);
}
if($this->useproxy<>0){
$opts = array('http' => array('proxy' => $this->proxy,'request_fulluri' => true,'method'=> 'GET' ));
}
if($this->useproxy<>1){
$opts = array('http' => 
array('request_fulluri' => true,
'method' => 'GET',
'header'=>'Referer:http://www.youtube.com/watch?v='.$id
));
}
$context2 = stream_context_create($opts);
$vidurl="http://www.youtube.com/watch?v=".$id;
$s = file_get_contents($vidurl);
$response=$s;
$dlink='http://www.youtube.com/get_video?';
@preg_match_all("|fs=1&(.*)';|U",$response,$out, PREG_SET_ORDER);
$plink=$out[0][1];
@preg_match_all("|sk=(.*)&|U",$plink,$out2, PREG_SET_ORDER);
$sk=$out2[0][1];
@preg_match_all("|t=(.*)&|U",$plink,$out2, PREG_SET_ORDER);
$token=$out2[0][1];
@preg_match_all("|plid=(.*)&|U",$plink,$out2, PREG_SET_ORDER);
$plid=$out2[0][1];
@preg_match_all("|video_id=(.*)&|U",$plink,$out2, PREG_SET_ORDER);
$videoid=$out2[0][1];
@preg_match_all("|<title>(.*)</title>|U",$response,$titel,PREG_SET_ORDER);
$titlem=$titel[0][1];
$dlink=$dlink.'video_id='.$videoid.'&t='.$token.'&sk='.$sk.'&plid='.$plid;
//echo $dlink; exit;
if($methodi=='downloadlink'){
header('Content-Disposition: attachment; filename="'.$titlem.'.flv"');
$file = $dlink;
    readfile($file);
    exit;
}
if($methodi=='flvplayer'){
	readfile($dlink);
	exit;
}
} 
}
?>
Return current item: YouTube video download