doumanju2533 2015-06-05 13:56
浏览 187

youtube-dl正在下载php文件而不是视频

I've just started programming a few weeks ago so keep in mind I have no idea what exactly I'm doing.

I'm attempting to create an little website in which you input a youtube url and it'll download the video in an mp3 format and play it back to you with the audio visualizer. I've got almost everything working except the downloading part.

When I input a url and submit it instead of downloading the youtube video it downloads the php file in which the code resides.

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="main.css">
        <script src="prefixfree.min.js"></script>
    </head>
    <body>        
        <div id="main">
            <h1 id="header">Audio Visualizer</h1>
            <div id="form" class="container-center">
                <form action="download.php" method="get">
                    <input class="t-input" name="url" type="text" placeholder=" enter youtube video URL here">
                    <br>
                    <input  class="submit" type="submit" name="submit">
                </form>
            </div>
        </div>

        <script src="sketch/sketch.min.js"></script>
        <script src="animation.js"></script>
    </body>
</html>

PHP

<?php
$url = $_GET['url'];
try {
    new yt_downloader($url, TRUE, 'audio');
}
catch (Exception $e) {
    die($e->getMessage());
}

The downloader incase that's important: https://github.com/eyecatchup/php-yt_downloader/

So far I've only been messing around with javascript so, I have no idea how php works. I assume I've made some newbie mistake somewhere above which I can't fine.

Thank for the help!

EDIT: As Joel Hinz has pointed out I failed to download ffmpeg, unfortunately it still appears to not be working :(

SOURCE OF PROBLEM FOUND: It appears xampp doesn't want to run ffmpeg.

  • 写回答

1条回答 默认 最新

  • douping5015 2015-06-05 16:51
    关注

    Firstly, congrats for getting this far after a few weeks!

    For most programming problems, the best approach to debugging when you get beyond intuitive 'guesses', which are fine as a first pass, is to take the slow and thorough approach to step through and see exactly what is happening.

    For your problem:

    • As quick initial check, you do have the 'require('youtube-dl.class.php');' line in your code also? If so it would be easier if you post more of the PHP code (or all of it if it is short).
    • To check that your PHP server code is getting the url correctly you can get it to either write what it sees to logs or to 'echo' it to the screen. You can remove or tidy this up when you have solved the problem:
    <?php
    if (isset($_GET['url'])) {
        echo $_GET['url'];
    }else{
        echo "Error: url is not set";
    }
    .
    . (the rest of your PHP code here)
    .
    
    
    ?>
    
    • Another thing you can do to narrow the problem down is to substitute the url variable in your code for a known hardcoded YouTube URL (as in the examples for the php-yr-downloader). If this works then you know the issues is with your url getting mechanism and if not then the issue may well be with the downloader or how it is being used.

    Hopefully, this helps point you in the right directions (it is really more of a 'comment' than an answer but wouldn't fit in the comment section!).

    Good Luck...

    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答