Dean
05-11-2010, 08:51 PM
I've been attempting to get hold of a script for about 3 days now that will basically get the video ID and the token from a YouTube video, then echo it. Unfortunately, I've failed.
This is the coding that I'm using...
<?php
$youtube = $_GET['web'];
function getstring($string)
{
$pos = strrpos($string, "swfArgs")+11;
$texto = substr($string,$pos,strrpos(substr($string,$pos,st rlen($string)), "additionalStatsHonorsUrl")-10);
$replace = array(" ",'"',"_");
$adata = split(",",str_replace($replace,"",$texto));
$vid_id = split(":",$adata[2]);
$code = split(":",$adata[6]);
$vidn1 = strrpos($string, "<title>")+7;
$vidn2 = strrpos(substr($string,$vidn1,-1), "</title>");
$vidname = substr($string,$vidn1,$vidn2);
$web = 'http://www.youtube.com/get_video?fmt=18&video_id='.$vid_id[1].'&t='.$code[1];
echo $web.'|'.$vidname;
}
function getPage($opts) {
$ch = curl_init($opts);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$html = curl_exec($ch);
if(curl_errno($ch)) {
$html = "";
}
curl_close ($ch);
return getstring($html);
}
getPage($youtube);
?>
For example... this YouTube link...
http://www.youtube.com/watch?v=m2vWQFHP3D0
I should be able to get the video ID from the URL already which is m2vWQFHP3D0 but then I need the token.
The end product should look like this...
http://www.youtube.com/get_video?fmt=18&video_id=m2vWQFHP3D0&t=vjVQa1PpcFNL59klwGHWg7fOm6Haf1Ytrvgl9NPE32Q=&asv=
BUT... I get this :S I really don't understand!
http://www.youtube.com/get_video?fmt=18&video_id=//s.ytimg.com/yt/cssbin/www-feather-vfl54jP1d.css><!--[iflteIE7]><linkrel=stylesheethref=http&t=//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gifclass=opera-link></a><ahref=http
If anyone knows what's up, then please feel free to help. +rep for anyone that contributes well.
This is the coding that I'm using...
<?php
$youtube = $_GET['web'];
function getstring($string)
{
$pos = strrpos($string, "swfArgs")+11;
$texto = substr($string,$pos,strrpos(substr($string,$pos,st rlen($string)), "additionalStatsHonorsUrl")-10);
$replace = array(" ",'"',"_");
$adata = split(",",str_replace($replace,"",$texto));
$vid_id = split(":",$adata[2]);
$code = split(":",$adata[6]);
$vidn1 = strrpos($string, "<title>")+7;
$vidn2 = strrpos(substr($string,$vidn1,-1), "</title>");
$vidname = substr($string,$vidn1,$vidn2);
$web = 'http://www.youtube.com/get_video?fmt=18&video_id='.$vid_id[1].'&t='.$code[1];
echo $web.'|'.$vidname;
}
function getPage($opts) {
$ch = curl_init($opts);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$html = curl_exec($ch);
if(curl_errno($ch)) {
$html = "";
}
curl_close ($ch);
return getstring($html);
}
getPage($youtube);
?>
For example... this YouTube link...
http://www.youtube.com/watch?v=m2vWQFHP3D0
I should be able to get the video ID from the URL already which is m2vWQFHP3D0 but then I need the token.
The end product should look like this...
http://www.youtube.com/get_video?fmt=18&video_id=m2vWQFHP3D0&t=vjVQa1PpcFNL59klwGHWg7fOm6Haf1Ytrvgl9NPE32Q=&asv=
BUT... I get this :S I really don't understand!
http://www.youtube.com/get_video?fmt=18&video_id=//s.ytimg.com/yt/cssbin/www-feather-vfl54jP1d.css><!--[iflteIE7]><linkrel=stylesheethref=http&t=//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gifclass=opera-link></a><ahref=http
If anyone knows what's up, then please feel free to help. +rep for anyone that contributes well.