PHP Code:
<?
$token_code = get_video_token($_REQUEST['vid']);
if($token_code == false)exit(0);
else echo $token_code;
function get_video_token($youtube_id,$extra='')
{
/* STEP 2. visit the homepage to set the cookie properly */
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11';
$url = 'http://www.youtube.com/';
$ckfile = tempnam ("/tmp", "CURLCOO".rand(1,99)."KIE");
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$info_url = 'http://www.youtube.com/get_video_info?video_id='.$youtube_id.'';
/* STEP 3. visit cookiepage */
$ch = curl_init ($info_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$vars = explode('&', $output);
foreach($vars as $var){ //search the headers for the location url of youtube video
$variable = explode('=', $var, 2);
$$variable[0] = $variable[1];
}
if($token!="")
{
return $token;
} else return false;
}
?>
if someone knows other ways please let me know
Comment