Urls for downloading youtube video`s are on the youtube page eg:
goto YouTube - Funny Animation
and right click and view source
Press Ctrl F and search for: &fmt_url_map=
you will then find a long string of urls .....
this string is the video download links but:
&title=name
needs adding on end of 1 url.
(you can try the above and download any youtube video) ^^
Grabbing this information is where the problem begins....
here was a quick attempt at grabbing and parsing each url to a link:
^ The Above Code Grabbed all Urls And Split them equally.....
How ever when you grab the page by cURL part of the link is removed by youtube
part removed will look something like this:
%252Coc%253AG0hPSFJQUl9FSkNOOV7KSlZB
or like this when url decoded:
,oc:253AG0hPSFJQUl9FSkNOOV7KSlZB
Which stops you from downloading the video .....
This string is also missing when you turn cookies off on your browser and goto the page and view source...
So im guessing one or more of the 5 Cookies is required to get this missing string..
Cookie names are:
GEO
PREF
VISITOR_INFO1_LIVE
recently_watched_video_id_list
use_hitbox
At a guess i would say it was either GEO or VISITOR_INFO1_LIVE that is required as you will also notice that the first digits of your ip address is in the download link ip=(first digits).0.0.0
eg:
Would be good to get this working for mobiles again as my web version doesn't work on mobiles
goto YouTube - Funny Animation
and right click and view source
Press Ctrl F and search for: &fmt_url_map=
you will then find a long string of urls .....
this string is the video download links but:
&title=name
needs adding on end of 1 url.
(you can try the above and download any youtube video) ^^
Grabbing this information is where the problem begins....
here was a quick attempt at grabbing and parsing each url to a link:
PHP Code:
<?php
//error_reporting (E_ALL);
//ini_set ('display_errors', true);
$url = $_GET['url'];
if($url=='')
$url = 'http://www.youtube.com/watch?v=0_fPV13lKm4&fmt=18';
else
$url = $url.'&fmt=18';
$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9' ;
$language = 'en-us,en;q=0.7,de-de;q=0.3';
$accept = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,;q=0.5';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: '.$language));
$page = curl_exec($ch);
curl_close($ch);
$start = strpos($page,'&fmt_url_map=');
$finish = strpos($page,'&csi_page_type=watch');
$length = $finish-$start;
$page = substr($page,$start,$length);
$page = urldecode($page);
$page = preg_replace('/&fmt_url_map=(.*?)http/','http',$page);
$page = str_replace('%2C',',',$page);
$page = explode('|', $page);
$num = count($page);
for ($i = 0; $i <$num; $i++) {
if(substr($page[$i],-2)=='13'){ $format = '3GP Low Quality - 176×144'; $n=3; }
else if(substr($page[$i],-2)=='17'){ $format = '3GP Medium Quality - 176×144'; $n=3; }
else if(substr($page[$i],-2)=='36'){ $format = '3GP High Quality - 320×240'; $n=3; }
else if(substr($page[$i],-2)=='34'){ $format = 'FLV Medium Quality - 480×360'; $n=3; }
else if(substr($page[$i],-2)=='35'){ $format = 'FLV High Quality - 854×480'; $n=3; }
else if(substr($page[$i],-2)=='18'){ $format = 'MP4 High Quality - 480×360'; $n=3; }
else if(substr($page[$i],-2)=='22'){ $format = 'MP4 High Definition - 1280×720'; $n=3; }
else if(substr($page[$i],-2)=='37'){ $format = 'MP4 High Definition - 1920×1080'; $n=3; }
else if(substr($page[$i],-2)=='38'){ $format = 'MP4 Epic Definition - 4096×2304'; $n=3; }
else if(substr($page[$i],-2)=='43'){ $format = 'WebM High Definition - 854×480'; $n=3; }
else if(substr($page[$i],-2)=='45'){ $format = 'WebM High Definition - 1280×720'; $n=3; }
else if(substr($page[$i],-1)=='5'){ $format = 'FLV Low Quality - 400×226'; $n=2; }
else if(substr($page[$i],-1)=='6'){ $format = 'FLV Medium Quality - 640×360'; $n=2; }
else $format = 'Unknown Format';
echo '<a href="'.substr($page[$i],0,-$n).'&title=Something_Else">Download '.$format.'</a><br/><br/>';
}
?>
How ever when you grab the page by cURL part of the link is removed by youtube
part removed will look something like this:
%252Coc%253AG0hPSFJQUl9FSkNOOV7KSlZB
or like this when url decoded:
,oc:253AG0hPSFJQUl9FSkNOOV7KSlZB
Which stops you from downloading the video .....
This string is also missing when you turn cookies off on your browser and goto the page and view source...
So im guessing one or more of the 5 Cookies is required to get this missing string..
Cookie names are:
GEO
PREF
VISITOR_INFO1_LIVE
recently_watched_video_id_list
use_hitbox
At a guess i would say it was either GEO or VISITOR_INFO1_LIVE that is required as you will also notice that the first digits of your ip address is in the download link ip=(first digits).0.0.0
eg:
PHP Code:
curl_setopt($ch,CURLOPT_COOKIE,"GEO=geo cookie here; domain=.youtube.com; path=/");
curl_setopt($ch,CURLOPT_COOKIE,"PREF=pref cookie here; domain=.youtube.com; path=/");
curl_setopt($ch,CURLOPT_COOKIE,"VISITOR_INFO1_LIVE=live cookie here; domain=.youtube.com; path=/");
curl_setopt($ch,CURLOPT_COOKIE,"recently_watched_video_id_list=recently watched cookie here; domain=.youtube.com; path=/");
curl_setopt($ch,CURLOPT_COOKIE,"use_hitbox=use hitbox cookie here; domain=.youtube.com; path=/");
Would be good to get this working for mobiles again as my web version doesn't work on mobiles
Comment