我尝试从
获取youtube视频链接http://www.youtube.com/get_video_info?video_id=XXXXXXXX
但1080 px和4k不在列表中所以我如何获得此分辨率的链接
api v3不允许获取网址
答案 0 :(得分:4)
此功能可以完成工作
<?php
function get_youtube($id)
{
$data = file_get_contents('http://youtube.com/get_video_info?video_id=' . $id . '&el=vevo&fmt=18&asv=2&hd=1');
parse_str($data , $details);
$my_formats_array = explode(',' , $details['adaptive_fmts']);
$avail_formats[] = '';
$i = 0;
$ipbits = $ip = $itag = $sig = $quality_label = '';
$expire = time();
foreach ($my_formats_array as $format) {
parse_str($format);
$avail_formats[$i]['itag'] = $itag;
$avail_formats[$i]['quality'] = $quality_label;
$type = explode(';', $type);
$avail_formats[$i]['type'] = $type[0];
$avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig;
parse_str(urldecode($url));
$avail_formats[$i]['expires'] = date("G:i:s T", $expire);
$avail_formats[$i]['ipbits'] = $ipbits;
$avail_formats[$i]['ip'] = $ip;
$i++;
}
return $avail_formats;
}
$qualitys = get_youtube($_GET['id']);
foreach($qualitys as $video)
{
//echo "<a href='" . $video['url'] . "'>" . $video['quality'] . "-" . $video['type'] . "</a></br>"; //print all resolution
// for getting 1080p only
if($video['quality']=='1080p' && $video['type']=='video/mp4'){
echo "<a href='" . $video['url'] . "'>" . $video['quality'] . "-" . $video['type'] . "</a></br>";
}
}