用php动态下载Youtube视频

用php动态下载Youtube视频,php,youtube,Php,Youtube,我用下面的代码用php下载了youtube视频,效果不错 当我们分配静态视频id时可以,但当我分配动态id时可以 $\u请求['id']它给我的错误如下 ytube\u video.php <?php // The YouTube ID $key = isset($_REQUEST['id']) ? $_REQUEST['id'] : "juZN67BA_5w"; // Get all info for video $output = file_get_contents('htt

我用下面的代码用php下载了youtube视频,效果不错 当我们分配静态视频id时可以,但当我分配动态id时可以
$\u请求['id']
它给我的错误如下

ytube\u video.php

<?php
 // The YouTube ID
 $key = isset($_REQUEST['id']) ? $_REQUEST['id'] : "juZN67BA_5w";

 // Get all info for video
 $output = file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$key);
 // Parse data to eg.(&id=var)
 parse_str($output);
 // Get Quality map of video an set array

if(isset($url_encoded_fmt_stream_map)) {
 $my_formats_array = explode(',',$url_encoded_fmt_stream_map);
} 
 // Set Array & Vars
 $avail_formats[] = '';
 $i = 0;
 // Break up array to create download links to quality
 foreach($my_formats_array as $format) {
 parse_str($format);
echo "<pre>";
print_r($format);
echo "</pre>";
echo "<a download='". $title .".mp4' href=".$avail_formats[$i]['url'] = urldecode($url).">". $title .".mp4</a> Quality - ".$quality."<br>"; $i++; 
} 
?>

我得到了我的答案,这里是新的更新代码动态工作


为什么我可以使用此脚本从vevo下载youtube视频?你和我有同样的问题吗?
<?php
 // The YouTube ID
 $key = isset($_REQUEST['id']) ? $_REQUEST['id'] : "juZN67BA_5w";

 // Get all info for video
 $output = file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$key);
 // Parse data to eg.(&id=var)
 parse_str($output);
 // Get Quality map of video an set array

if(isset($url_encoded_fmt_stream_map)) {
 $my_formats_array = explode(',',$url_encoded_fmt_stream_map);
} 
 // Set Array & Vars
 $avail_formats[] = '';
 $i = 0;
 // Break up array to create download links to quality
 foreach($my_formats_array as $format) {
 parse_str($format);
echo "<pre>";
print_r($format);
echo "</pre>";
echo "<a download='". $title .".mp4' href=".$avail_formats[$i]['url'] = urldecode($url).">". $title .".mp4</a> Quality - ".$quality."<br>"; $i++; 
} 
?>
<?php
 // The YouTube ID
 $key = isset($_REQUEST['id']) ? $_REQUEST['id'] : "juZN67BA_5w";
 // Get all info for video
 $output = file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$key);
 // Parse data to eg.(&id=var)
 parse_str($output);
 echo '<p><img src="'. $thumbnail_url .'" border="0" hspace="2" vspace="2"></p>';
 $my_title = $title;

 if(isset($url_encoded_fmt_stream_map)) {
    /* Now get the url_encoded_fmt_stream_map, and explode on comma */
    $my_formats_array = explode(',',$url_encoded_fmt_stream_map);
 } else {
    echo '<p>No encoded format stream found.</p>';
    echo '<p>Here is what we got from YouTube:</p>';
    echo $output;
 }

 if (count($my_formats_array) == 0) {
    echo '<p>No format stream map found - was the video id correct?</p>';
    exit;
 }

/* create an array of available download formats */
 $avail_formats[] = '';
 $i = 0;
 $ipbits = $ip = $itag = $sig = $quality = '';
 $expire = time(); 

 foreach($my_formats_array as $format) {
    parse_str($format);
    $avail_formats[$i]['itag'] = $itag;
    $avail_formats[$i]['quality'] = $quality;
    $type = explode(';',$type);
    $avail_formats[$i]['type'] = $type[0];
    $avail_formats[$i]['url'] = urldecode($url) . '&signature=' .$sig;
    parse_str(urldecode($url));
    $avail_formats[$i]['expire'] = date("G:i:s T", $expire);
    $avail_formats[$i]['ipbits'] = $ipbits;
    $avail_formats[$i]['ip'] = $ip;
    $i++;
 }
 for ($i = 0; $i < count($avail_formats); $i++) {
    echo '<li>' .
            '<span class="itag">' . $avail_formats[$i]['itag'] . '</span> '.
            '<a href="' . $avail_formats[$i]['url'] . '" class="mime">' . $avail_formats[$i]['type'] . '</a> ' .
            '<small>(' .  $avail_formats[$i]['quality'].'</a>' .
            ')</small>
          </li>';
 }
?>