我使用下面的脚本来下载youtube视频,它在localhost中的xamp工作正常,但是当我把它放在我的live wev服务器中它不工作时,我从 https://github.com/jeckman/YouTube-Downloader/blob/master/getvideo.php获得此代码
<?PHP
    // YouTube Downloader PHP
    // based on youtube-dl in Python http://rg3.github.com/youtube-dl/
    // by Ricardo Garcia Gonzalez and others (details at url above)
    //
    // Takes a VideoID and outputs a list of formats in which the video can be
    // downloaded

    include_once('curl.PHP');

    if(isset($_REQUEST['videoid'])) {
        $my_id = $_REQUEST['videoid'];
    } else {
        echo '<p>No video id passed in</p>';
        exit;
    }

    if(isset($_REQUEST['type'])) {
        $my_type =  $_REQUEST['type'];
    } else {
        $my_type = 'redirect';
    }

    if(isset($_REQUEST['debug'])) {
        $debug = TRUE;
    } else {
        $debug = FALSE;
    }

    if ($my_type == 'Download') {
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Youtube Downloader</title>
        <Meta name="keywords" content="Video downloader,download youtube,video download,youtube video,youtube downloader,download youtube FLV,download youtube MP4,download youtube 3GP,PHP video downloader" />
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
         <style type="text/css">
          body {
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }

          .download {
            max-width: 300px;
            padding: 19px 29px 29px;
            margin: 0 auto 20px;
            background-color: #fff;
            border: 1px solid #e5e5e5;
            -webkit-border-radius: 5px;
               -moz-border-radius: 5px;
                    border-radius: 5px;
            -webkit-Box-shadow: 0 1px 2px rgba(0,.05);
               -moz-Box-shadow: 0 1px 2px rgba(0,.05);
                    Box-shadow: 0 1px 2px rgba(0,.05);
          }

          .download .download-heading {
            margin-bottom: 10px;
          }

          .mime,.itag {
            width: 75px;
            display: inline-block;
          }

          .itag {
            width: 15px;
          }

          .userscript {
            float: right;
            margin-top: 5px
          }
        </style>
        </head>
    <body>
        <div class="download">
        <h1 class="download-heading">Youtube Downloader Results</h1>
    <?PHP
    } // end of if for type=Download

    /* First get the video info page for this video id */
    $my_video_info = 'http://www.youtube.com/get_video_info?&video_id='. $my_id;
    $my_video_info = curlGet($my_video_info);

    /* Todo: Check return from curl for status code */

    parse_str($my_video_info);
    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);
        //if($debug) {
        //  echo '<pre>';
        //  print_r($my_formats_array);
        //  echo '</pre>';
        //}
    } else {
        echo '<p>No encoded format stream found.</p>';
        echo '<p>Here is what we got from YouTube:</p>';
        echo $my_video_info;
    }
    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;

    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]['expires'] = date("G:i:s T",$expire);
        $avail_formats[$i]['ipbits'] = $ipbits;
        $avail_formats[$i]['ip'] = $ip;
        $i++;
    }

    if ($debug) {
        echo '<p>These links will expire at '. $avail_formats[0]['expires'] .'</p>';
        echo '<p>The server was at IP address '. $avail_formats[0]['ip'] .' which is an '. $avail_formats[0]['ipbits'] .' bit IP address. ';
        echo 'Note that when 8 bit IP addresses are used,the download links may fail.</p>';
    }
    if ($my_type == 'Download') {
        echo '<ul>
                List of available formats for download:<br>
                <small>Right-click and choose "save as" or click "download" to use this server as proxy.</small>
            </ul>';

        /* Now that we have the array,print the options */
        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 href="download.PHP?mime=' . $avail_formats[$i]['type'] .'&title='. urlencode($my_title) .'&token=' . base64_encode($avail_formats[$i]['url']) . '" class="dl">download</a>' .
                    ')</small></li>';
        }
        echo '</ul>';
    ?>

    <!-- @Todo: Prepend the base URI -->
    <a href="ytdl.user.js" class="userscript btn btn-mini" title="Install chrome extension to view a 'Download' link to this application on Youtube video pages.">
      Install Chrome Extension
    </a>

    </body>
    </html>

    <?PHP

    } else {

    /* In this else,the request didn't come from a form but from something else
     * like an RSS Feed.
     * As a result,we just want to return the best format,which depends on what
     * the user provided in the url.
     * If they provided "format=best" we just use the largest.
     * If they provided "format=free" we provide the best non-flash version
     * If they provided "format=ipad" we pull the best MP4 version
     *
     * Thanks to the python based youtube-dl for info on the formats
     *                              http://rg3.github.com/youtube-dl/
     */

    $format =  $_REQUEST['format'];
    $target_formats = '';
    switch ($format) {
        case "best":
            /* largest formats first */
            $target_formats = array('38','37','46','22','45','35','44','34','18','43','6','5','17','13');
            break;
        case "free":
            /* Here we include WebM but prefer it over FLV */
            $target_formats = array('38','13');
            break;
        case "ipad":
            /* here we leave out WebM video and FLV - looking for MP4 */
            $target_formats = array('37','17');
            break;
        default:
            /* If they passed in a number use it */
            if (is_numeric($format)) {
                $target_formats[] = $format;
            } else {
                $target_formats = array('38','13');
            }
        break;
    }

    /* Now we need to find our best format in the list of available formats */
    $best_format = '';
    for ($i=0; $i < count($target_formats); $i++) {
        for ($j=0; $j < count ($avail_formats); $j++) {
            if($target_formats[$i] == $avail_formats[$j]['itag']) {
                //echo '<p>Target format found,it is '. $avail_formats[$j]['itag'] .'</p>';
                $best_format = $j;
                break 2;
            }
        }
    }

    //echo '<p>Out of loop,best_format is '. $best_format .'</p>';
    $redirect_url = $avail_formats[$best_format]['url'];
    $content_type = $avail_formats[$best_format]['type'];
    header("Location: $redirect_url");
    } // end of else for type not being Download
    ?>
尝试在路由器上打开一个端口,该端口重定向到计算机的本地主机.您的ISP可能阻止端口80,因此将Apache的广播端口更改为8080.尝试通过互联网从外部访问您的计算机并下载YouTube视频.如果这不会给您带来问题,那么您的网络主机可能会阻止它.

我在我的网络主机上试过它,它运行正常,你有任何错误吗?

php youtube视频下载的更多相关文章

  1. 从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

    我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码:这里是PHP的一大块,POST变量不在正确的位置?我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!解决方法$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:

  2. swift学习2 元组 tuples

    swift中出现了一种新的数据结构,非常牛掰的元组tuples如果懂PHP的猿,会发现这个元组和PHP的数组非常类似,同样是可以默认不指定key,也可以指定key目前的学习疑问是,如何进行元组的遍历?

  3. 尝试使用swift mailer,gmail smtp,php发送邮件

    这里是我的代码:在运行时出现此错误…

  4. 离子运行android似乎工作,但该应用程序没有在手机上启动,为什么?

    我的手机处于打开状态,处于调试模式,我已通过adbdevices-l确认了这一点.当我运行离子运行android时,我得到Ionic声称应用程序启动时的输出,但手机上没有任何反应.我使用Android4.4.4的Nexus5.androidapp中的index.html:解决方法键入离子信息并检查已安装的Cordova版本.如果你有v5.0.0现在需要一个新的插件,否则所有的http请求都被阻止.

  5. PHP使用JpGraph绘制折线图操作示例【附源码下载】

    这篇文章主要介绍了PHP使用JpGraph绘制折线图操作,结合实例形式分析了php使用JpGraph的相关操作技巧与注意事项,并附带源码供读者下载参考,需要的朋友可以参考下

  6. jQuery的Cookie封装,与PHP交互的简单实现

    下面小编就为大家带来一篇jQuery的Cookie封装,与PHP交互的简单实现。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  7. PHP+jquery+CSS制作头像登录窗(仿QQ登陆)

    本篇文章介绍了PHP结合jQ和CSS制作头像登录窗(仿QQ登陆),实现了类似QQ的登陆界面,很有参考价值,有需要的朋友可以了解一下。

  8. 如何在PHP环境中使用ProtoBuf数据格式

    这篇文章主要介绍了如何在PHP环境中使用ProtoBuf数据格式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

  9. PHP rsa加密解密算法原理解析

    这篇文章主要介绍了PHP rsa加密解密算法原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

  10. PHP cookie与session会话基本用法实例分析

    这篇文章主要介绍了PHP cookie与session会话基本用法,结合实例形式分析了PHP cookie与session会话基本存储、设置、删除等相关使用方式,需要的朋友可以参考下

随机推荐

  1. PHP个人网站架设连环讲(一)

    先下一个OmnihttpdProffesinalV2.06,装上就有PHP4beta3可以用了。PHP4给我们带来一个简单的方法,就是使用SESSION(会话)级变量。但是如果不是PHP4又该怎么办?我们可以假设某人在15分钟以内对你的网页的请求都不属于一个新的人次,这样你可以做个计数的过程存在INC里,在每一个页面引用,访客第一次进入时将访问时间送到cookie里。以后每个页面被访问时都检查cookie上次访问时间值。

  2. PHP函数学习之PHP函数点评

    PHP函数使用说明,应用举例,精简点评,希望对您学习php有所帮助

  3. ecshop2.7.3 在php5.4下的各种错误问题处理

    将方法内的函数,分拆为2个部分。这个和gd库没有一点关系,是ecshop程序的问题。会出现这种问题,不外乎就是当前会员的session或者程序对cookie的处理存在漏洞。进过本地测试,includes\modules\integrates\ecshop.php这个整合自身会员的类中没有重写integrate.php中的check_cookie()方法导致,验证cookie时返回的username为空,丢失了登录状态,在ecshop.php中重写了此方法就可以了。把他加到ecshop.php的最后面去就可

  4. NT IIS下用ODBC连接数据库

    $connection=intodbc_connect建立数据库连接,$query_string="查询记录的条件"如:$query_string="select*fromtable"用$cur=intodbc_exec检索数据库,将记录集放入$cur变量中。再用while{$var1=odbc_result;$var2=odbc_result;...}读取odbc_exec()返回的数据集$cur。最后是odbc_close关闭数据库的连接。odbc_result()函数是取当前记录的指定字段值。

  5. PHP使用JpGraph绘制折线图操作示例【附源码下载】

    这篇文章主要介绍了PHP使用JpGraph绘制折线图操作,结合实例形式分析了php使用JpGraph的相关操作技巧与注意事项,并附带源码供读者下载参考,需要的朋友可以参考下

  6. zen_cart实现支付前生成订单的方法

    这篇文章主要介绍了zen_cart实现支付前生成订单的方法,结合实例形式详细分析了zen_cart支付前生成订单的具体步骤与相关实现技巧,需要的朋友可以参考下

  7. Thinkphp5框架实现获取数据库数据到视图的方法

    这篇文章主要介绍了Thinkphp5框架实现获取数据库数据到视图的方法,涉及thinkPHP5数据库配置、读取、模型操作及视图调用相关操作技巧,需要的朋友可以参考下

  8. PHP+jquery+CSS制作头像登录窗(仿QQ登陆)

    本篇文章介绍了PHP结合jQ和CSS制作头像登录窗(仿QQ登陆),实现了类似QQ的登陆界面,很有参考价值,有需要的朋友可以了解一下。

  9. 基于win2003虚拟机中apache服务器的访问

    下面小编就为大家带来一篇基于win2003虚拟机中apache服务器的访问。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  10. Yii2中组件的注册与创建方法

    这篇文章主要介绍了Yii2之组件的注册与创建的实现方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下

返回
顶部