【问题标题】:youtube get_video not workingyoutube get_video 不工作
【发布时间】:2011-01-05 10:20:56
【问题描述】:

我用http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18替换了

具有正确值的 ID 和 SIGNATURE。但我没有看到任何保存或下载窗口,

而是一个空白窗口。

我在 Macintosh 平台上使用 Safari 浏览器。帮助表示赞赏。

【问题讨论】:

    标签: safari youtube


    【解决方案1】:

    获取 youtube 视频信息的最简单方法是从 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 用于节省带宽的最佳流媒体速度),因此下载速度不会像您想象的那么快。这让我相信这些链接最适合用于流式传输而不是下载,但我不知道还有其他选择。

    【讨论】:

      【解决方案2】:

      互联网上到处都是不工作的例子,所以这里有一个脚本供任何需要的人使用。 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文件版本?
      【解决方案3】:

      youtube 更改了用于获取 flv 文件的请求。 现在看起来像

      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

      您可以轻松获取除 oc 参数以外的所有参数,即 %2Coc%3AU0dYSVZMTl9FSkNNOF9ORlJF 从响应中,仍在寻找获取它的方法。

      youtube 会锁定浏览器的链接,因此您无法在服务器上使用它。 如果您查看 youtube 页面的源代码,您会发现类似上述地址但没有 oc 参数的内容,如果您从 firebug net 面板或 chrome 资源中复制它,它会将 flv 电影下载为“videoplayback”。

      【讨论】:

      • 感谢您的回复。一旦您得到任何解决方案,请在此处发布。
      【解决方案4】:

      你试试:

      $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>';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-21
        • 2013-09-25
        • 1970-01-01
        • 2022-11-21
        相关资源
        最近更新 更多