I used http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18 replaced
ID and SIGNATURE with the proper values. But I don't get see any save or download window,
instead A blank window.
I am in Macintosh platform with Safari browser. Help Appreciated.
Easiest way to grab information on a youtube video is to get the source from http://youtube.com/get_video_info?video_id=XXXXXXXX
I will use PHP as an example of handling this data. Using PHP's parse_str() you can assign all variable of the string to a nice array of video info:
$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$id);
parse_str($content, $ytarr);
Then all the info is stored into $ytarr. Variables of interest would be "fmt_list" and "fmt_map" (which appear to contain the same thing afaik). This variable contains a list of available video formats in accordance to the chart here: http://en.wikipedia.org/wiki/Youtube#Quality_and_codecs
Assuming you know which of those formats you wish to download, you can then use the "fmt_url_map" variable (or $ytarr['fmt_url_map'] in this example) to access the list of links to the desired format.
You can download videos of any format using those links, but they are subject to youtube's limited bandwidth (the optimal streaming speed youtube uses to save on bandwidth) so therefore the downloads won't be quite as fast as you would imagine. This leads me to believe that these links are best used for streaming rather than downloading, but I'm not aware of any alternative.
The internet is full of not working examples so here's a script for anyone who needs. Something is wrong with the flv files. Their links deliver .txt files but it's good with webm and mp4. I need that for the pr0n sites too hehehe
<?php
//$debug = true;
if(empty($debug))
$debug = false;
if(empty($_GET['id']))
die('no id');
if(!preg_match('/^[A-Z0-9-_]+$/i', $_GET['id']))
die('invalid character in id');
else
$id = $_GET['id'];
if(empty($_GET['type']))
$type = 'mp4';
else
if(!preg_match('/^[A-Z]+$/i', $_GET['type']))
die('invalid character in type');
else
$type = strtolower($_GET['type']);
$url = 'http://youtube.com/get_video_info?video_id=';
$key = 'url_encoded_fmt_stream_map';
$content = file_get_contents($url.$id);
parse_str($content, $result);
if($debug)
{
echo $url.$id.'<br/>';
echo $key.'<br/>';
echo $type.'<br/>';
echo '<pre>';
print_r($result);
echo '</pre>';
}
else
{
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="videofile.'.$type.'"');
}
$type = 'type=video/'.$type;
$files = explode(',url=', $result[$key]);
$files[0] = substr($files[0], 4);
for($i=0; $i<count($files); $i++)
{
$file = urldecode($files[$i]);
$found = strpos($file, $type) > -1;
if ($debug)
{
if ($found)
echo '[THIS]';
echo '<a href="'.$file.'">'.$file.'</a><br/><br/>';
}
else
{
if ($found)
{
$file = explode('; codecs=', $file);
@readfile($file[0]);
break;
}
}
}
?>
youtube changed the request used to get the flv file.
Now it looks like
http://v2.lscache3.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dYSVZMTl9FSkNNOF9ORlJF&fexp=903816&fexp=903813%2C908400&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&expire=1294610400&key=yt1&signature=9C4D194A7F85F0171771486714D3F061ED2924F6.98D10BB190123CADCA3CDF993174D47F8932895F&factor=1.25&id=10af5a6280e42a28
you can grab easily all the parameters except oc parameter i.e %2Coc%3AU0dYSVZMTl9FSkNNOF9ORlJF
from the response, still searching a way to get it.
youtube locks the link to the browser, so you cannot use it on the server.
if you look in the source code of the youtube page you will find something like the above address but without the oc parameter, if you copy it from firebug net panel or chrome resources it will download the flv movie as "videoplayback".
you try:
$id = "111_fGEdIvs"; //the youtube video ID
//$id = $_GET['id'];
//$format = $_GET['fmt']; //the MIME type of the video. e.g. video/mp4, video/webm, etc.
parse_str(file_get_contents("http://youtube.com/get_video_info?video_id=".$id),$info); //decode the data
$streams = $info['url_encoded_fmt_stream_map']; //the video's location info
$streams = explode(',',$streams);
parse_str(urldecode($streams[0]),$data); //In this example I am downloading only the first video
$url=$data['url'];
$sig=$data['signature'];
unset($data['type']);
unset($data['url']);
unset($data['sig']);
$urlPlay= str_replace('%2C', ',' ,$url.'&'.http_build_query($data).'&signature='.$sig);
echo '<iframe class="youtube-player" type="text/html" width="640" height="385" src="'.$urlPlay.'" allowfullscreen frameborder="0" ></iframe>';