【问题标题】:get youtube download link [ 4k , 1080px ] use API v3获取 youtube 下载链接 [ 4k , 1080px ] 使用 API v3
【发布时间】:2017-08-28 21:10:14
【问题描述】:

我尝试从

获取 youtube 视频链接

http://www.youtube.com/get_video_info?video_id=XXXXXXXX

但是 1080 像素和 4k 不在列表中所以我如何获取此分辨率的链接

api v3 不允许获取 url

【问题讨论】:

  • 任何答案acn帮助?

标签: youtube


【解决方案1】:

这个功能可以完成这项工作

<?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>";
    }
}

【讨论】:

  • 谢谢 ...我尝试了 get_video_info 但即使这样也无法获得链接,所以我如何使用 preg_match 来获得正确的 itag?
  • 我已经添加了上面的功能
  • 哇,它的工作,但告诉我这些参数 &el=vevo&fmt=18&asv=2&hd=1 和 4k 这样我可以得到 4k 链接吗???
  • 函数已经获得所有分辨率,取消注释这一行 //echo "" 。 $video['质量'] 。 “-”。 $video['type'] 。 ""; //打印所有分辨率
  • 是的,我知道,但我需要一种方法来获取视频中的音频和视频 > 720p
猜你喜欢
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 2015-11-20
  • 1970-01-01
  • 1970-01-01
  • 2018-02-25
  • 2014-04-10
  • 1970-01-01
相关资源
最近更新 更多