我用http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18替换youtube get_video not working
ID和SIGNATURE与正确的值。但我没有看到任何保存或下载窗口,
改为空白窗口。
我在使用Safari浏览器的Macintosh平台上。帮助赞赏。
我用http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18替换youtube get_video not working
ID和SIGNATURE与正确的值。但我没有看到任何保存或下载窗口,
改为空白窗口。
我在使用Safari浏览器的Macintosh平台上。帮助赞赏。
最简单的方法是从http://youtube.com/get_video_info?video_id=XXXXXXXX
我将使用PHP作为处理这个数据的例子得到源。使用PHP的parse_str()您可以将字符串的所有变量分配到的视频信息一个很好的数组:
$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$id);
parse_str($content, $ytarr);
然后将所有信息存储到$ ytarr。感兴趣的变量将是“fmt_list”和“fmt_map”(它似乎包含相同的事物afaik)。此变量包含可用的视频格式,根据该图在这里的列表:http://en.wikipedia.org/wiki/Youtube#Quality_and_codecs
假设你知道那些你想下载的格式,然后你可以使用“fmt_url_map”变量(或$ ytarr ['fmt_url_map ']在这个例子中)来访问所需格式的链接列表。
您可以使用这些链接下载任何格式的视频,但它们受限于YouTube的有限带宽(youtube用于节省带宽的最佳流媒体速度),因此下载速度不会像您想象的那么快。这使我相信这些链接最好用于流式传输而不是下载,但我不知道有其他选择。
youtube更改了用于获取flv文件的请求。 现在看起来
你可以轻松抓取除了超频参数的所有参数即从响应%2Coc%3AU0dYSVZMTl9FSkNNOF9ORlJF ,仍然在寻找一种方式来获得它。
youtube锁定浏览器的链接,所以你不能在服务器上使用它。 如果你看看youtube页面的源代码,你会发现像上面的地址,但没有oc参数,如果你从Firebug网络面板或铬资源中复制它,它会下载flv电影作为“videoplayback”。抢在YouTube视频信息
互联网充满了没有工作的例子,所以这里是一个脚本,任何需要的人。 FLV文件有问题。他们的链接提供的.txt文件,但它与webm和mp4很好。我需要为pr0n网站太呵呵呵
<?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;
}
}
}
?>
如何使用此仅获取使用视频ID的mp4文件版本? – m3tsys 2012-03-03 21:34:29
尝试:
$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>';
感谢您的答复。只要你得到任何解决方案,请把它发布在这里。 – 2011-01-12 12:09:50