7

CentOS 6 / Plesk 10専用サーバーにyoutube-dlをインストールしましたが、SSH経由ですべてが魅力のように機能します。

サーバーにコピーしたいビデオのURLを含むPOSTパラメーターを取り、それをコピーしてからffmpegで処理するphpスクリプトを作成しようとしています。

exec()関数を使うと思いました。

の結果をエコーすると出力を取得できますが、youtube-dl --helpphpにビデオで実際に何かを実行するコマンドを実行するように要求するたびに、ステータス「1」が返され、何も出力されません。

私が間違っていることについて何か考えはありますか?

これが私のphpコードです:

<?php 
    $result = array();
    $status;
    $url = $_POST['src'];
    $string = 'youtube-dl "'.$url.'" -f 18 -o "/var/www/vhosts/my.virtual.host.net/httpdocs/downloader/downloads/%(id)s.%(ext)s"';
    $string2 = 'youtube-dl --help';
    exec($string, $result, $status);
    echo json_encode(array('status' => $status, 'url_orginal'=>$url, 'url' => $result));
?>

$ string2を実行すると、ステータスが「0」と「url」になります。[youtube-dlヘルプテキスト行]

しかし、$ stringを実行しても何も起こらず、「status」:「1」が表示され、それ以外は何もダウンロードされません。「-g」パラメータとバリアントを使用したシミュレーションも試しましたが、youtube-dlがビデオをフェッチする必要があるとすぐに、壊れます。

前もって感謝します !

編集

コードを編集したので、次のようになります。

<?php 
    $result = array();
    $status;
    $url = $_POST['src'];
    $string = 'youtube-dl "'.$url.'" -f 18 -o "/var/www/vhosts/my.virtual.host.net/httpdocs/downloader/downloads/%(id)s.%(ext)s"';
    $string2 = 'youtube-dl --help';
    exec($string, $result, $status);
    echo json_encode(array('status' => $status, 'url_orginal'=>$url, 'url' => $result, 'command' => $string));
?>

昨日得られなかった結果は次のとおりです。

command: "youtube-dl "http://www.youtube.com/watch?v=coq9klG41R8" -f 18 -o "/var/www/vhosts/my.virtual.host.net/httpdocs/downloader/downloads/%(id)s.%(ext)s""
status: 1
url: 
    0: "[youtube] Setting language"
    1: "[youtube] coq9klG41R8: Downloading video info webpage"
    2: "[youtube] coq9klG41R8: Extracting video information"
url_orginal: "http://www.youtube.com/watch?v=coq9klG41R8"

これは奇妙なことです。a)昨日空のurl []を取得し、b)通常のyoutube-dlリターンのように見えるものを取得したとしても、最初の3行しか含まれておらず、何も表示されません。指定されたパスのビデオファイル...何かアイデアはありますか?

4

1 に答える 1

10

execstdoutのみを読み取るため、stderrのエラーメッセージが表示されません。

次のコードを使用して、stderrも取得します。

$url = 'http://www.youtube.com/watch?v=coq9klG41R8';
$template = '/var/www/vhosts/my.virtual.host.net/httpdocs/downloader/' .
            'downloads/%(id)s.%(ext)s';
$string = ('youtube-dl ' . escapeshellarg($url) . ' -f 18 -o ' .
          escapeshellarg($template));

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin
   1 => array("pipe", "w"),  // stdout
   2 => array("pipe", "w"),  // stderr
);
$process = proc_open($string, $descriptorspec, $pipes);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$ret = proc_close($process);
echo json_encode(array('status' => $ret, 'errors' => $stderr,
                       'url_orginal'=>$url, 'output' => $stdout,
                       'command' => $string));

ほとんどの場合、そのディレクトリに書き込む権限がありません。その理論をテストするには、

touch /var/www/vhosts/my.virtual.host.net/httpdocs/downloader/downloads/test

動作します。chmodおよびを使用しchownて権限を変更できます。

于 2013-03-01T11:17:51.967 に答える