php中脚本代码开始,从PHP代码中执行shell脚本

我想要做的就是使用PHP来执行youtube-dl -x --audio-format mp3 "token"并获得以下参数JSON:从PHP代码中执行shell脚本

状态(错误= 0 /成功= 1)

保存的文件URL (您将在控制台结果示例中看到它:[avconv] Destination: Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.mp3)

这是我写的PHP代码。

if ($_GET["token"]) {

$url = $_GET["token"];

$template = '/home/website/public_html/%(id)s.%(ext)s';

$string = ('youtube-dl -x --audio-format mp3 ' . escapeshellarg($url) . ' ' . 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));

}

?>

基本上它执行

youtube-dl -x --audio-format mp3 "token"

当我在控制台执行相同的命令(通过SSH),我得到这样的

[youtube] Setting language

[youtube] Confirming age

[youtube] nxtIRArhVD4: Downloading webpage

[youtube] nxtIRArhVD4: Downloading video info webpage

[youtube] nxtIRArhVD4: Extracting video information

[youtube] nxtIRArhVD4: Encrypted signatures detected.

[youtube] nxtIRArhVD4: Downloading js player vflE7vgXe

[download] Destination: Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.m4a

[download] 100% of 3.93MiB in 00:00

[avconv] Destination: Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.mp3

Deleting original file Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.m4a (pass -k to keep)

结果当我在PHP环境中执行相同的命令越来越关注json结果

{

"status":1,

"errors":"WARNING: The url doesn't specify the protocol, trying with http\nWARNING: Could not send HEAD request to http:\/\/\/home\/website\/public_html\/%(id)s.%(ext)s: \nWARNING: Falling back on generic information extractor.\nERROR: Unable to download webpage: \n",

"url_orginal":"nxtIRArhVD4",

"output":"[youtube] Setting language\n[youtube] Confirming age\n[youtube] nxtIRArhVD4: Downloading webpage\n[youtube] nxtIRArhVD4: Downloading video info webpage\n[youtube] nxtIRArhVD4: Extracting video information\n[youtube] nxtIRArhVD4: Encrypted signatures detected.\n[youtube] nxtIRArhVD4: Downloading js player vflE7vgXe\n[download] Destination: Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.m4a\n\r[download] 0.0% of 3.93MiB at 729.44KiB\/s ETA 00:05\r[download] 0.1% of 3.93MiB at 1.86MiB\/s ETA 00:02\r[download] 0.2% of 3.93MiB at 3.86MiB\/s ETA 00:01\r[download] 0.4% of 3.93MiB at 7.69MiB\/s ETA 00:00\r[download] 0.8% of 3.93MiB at 13.79MiB\/s ETA 00:00\r[download] 1.6% of 3.93MiB at 17.80MiB\/s ETA 00:00\r[download] 3.2% of 3.93MiB at 17.64MiB\/s ETA 00:00\r[download] 6.3% of 3.93MiB at 17.79MiB\/s ETA 00:00\r[download] 12.7% of 3.93MiB at 20.88MiB\/s ETA 00:00\r[download] 25.4% of 3.93MiB at 25.21MiB\/s ETA 00:00\r[download] 50.8% of 3.93MiB at 28.47MiB\/s ETA 00:00\r[download] 100.0% of 3.93MiB at 41.23MiB\/s ETA 00:00\r[download] 100% of 3.93MiB in 00:00\n[avconv] Destination: Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.mp3\nDeleting original file Jennifer Lopez - Booty ft. Iggy Azalea-nxtIRArhVD4.m4a (pass -k to keep)\n[generic] %(id)s: Requesting header\n[generic] %(id)s: Downloading webpage\n",

"command":"youtube-dl --extract-audio --audio-format mp3 'nxtIRArhVD4' '\/home\/website\/public_html\/%(id)s.%(ext)s'"

}

事实上,PHP做的工作和保存文件,但输出不相同,我无法获得目标文件的网址。

我在做什么错?有什么建议么?

2014-09-21

heron

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值