我想要做的就是使用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

php中脚本代码开始,从PHP代码中执行shell脚本相关推荐

  1. python中执行shell脚本之subprocess模块,python用subprocess执行shell脚本

    用subprocess中的Popen() 方法来得到shell脚本的一些运行结果,并且也可以指定不同的shell内核. 其构造函数为: class subprocess.Popen(args, buf ...

  2. flask执行python脚本_如何从Flask应用程序执行Shell脚本

    要在Python中显示命令输出,有两种常用方法:check_output():它使用参数运行命令并返回其输出.(official documentation) subprocess.communica ...

  3. linux执行shell过程日志,Android之在linux终端执行shell脚本直接打印当前运行app的日志...

    1.问题 我们一般很多时候会需要在ubuntu终端上打印当前运行app的日志,我们一般常见的做法是 1).获取包名 打开当前运行的app,然后输入如下命令,然后在第一行TASK后面的就可以看到包名 a ...

  4. aix shell脚本 运行java_Linux中执行shell脚本的4种方法总结

    Linux中执行shell脚本的4种方法总结,即在Linux中运行shell脚本的4种方法: 方法一:切换到shell脚本所在的目录(此时,称为工作目录)执行shell脚本: 复制代码 代码如下: c ...

  5. Linux中执行shell脚本的5种方法总结

    Linux中执行shell脚本的4种方法总结,即在Linux中运行shell脚本的4种方法: 方法一:切换到shell脚本所在的目录(此时,称为工作目录)执行shell脚本: 复制代码 代码如下: c ...

  6. Android启动过程中执行一个C语言的应用程序或者执行shell脚本

    Android启动过程中执行一个C语言的应用程序或者执行shell脚本 一.Android启动过程中去对系统做一些设置,如修改某些文件夹的属性和文件的权限,可在init.rc中增加service执行s ...

  7. Linux中执行shell脚本的4种方法

    这篇文章主要介绍了Linux中执行shell脚本的4种方法总结,即在Linux中运行shell脚本的4种方法,需要的朋友可以参考下. bash shell 脚本的方法有多种,现在作个小结.假设我们编写 ...

  8. crontab执行shell脚本日志中出现乱码

    使用nutch开源的搜索引擎抓取网页信息,通过计划任务crontab执行shell脚本,并将启动信息记录进日志文件,但是每次都会出现乱码,如图所示 经过反复测试,排除了java程序问题,文件权限问题, ...

  9. python中执行shell脚本之subprocess模块_如何使用Python中的subprocess模块检查shell脚本的状态?...

    我有一个简单的Python脚本,它将使用Python中的subprocessmdoule来执行shell脚本.在 下面是我的pythonshell脚本,它正在调用testing.shshell脚本,它 ...

最新文章

  1. 【Git】git 与远程库交互
  2. HTML5(WebSockets)的脆弱性?
  3. nagios学习手札
  4. 自学python可以找到好的工作吗-通过自学python能找到工作吗
  5. Fleecing the Raffle
  6. 工业交换机的单模和多模能否互相替代?
  7. python中调用C++函数
  8. 前端技巧之苹果官网效果分析
  9. 重构职场竞争力之测试跨界思维
  10. vue中使用scss
  11. tcp 四次挥手_TCP三次握手,四次挥手,你真的懂吗?
  12. c++按行读取txt文件中的内容,并按特定字符分割
  13. ESP32 LVGL8.1 ——Label 标签 (Style 14)
  14. 夯实Java基础系列8:深入理解Java内部类及其实现原理
  15. Java找不到对象的警告_程序猿的24个段子:程序员找不到对象 一般有三种情况...
  16. 用命令打开文件服务器资源管理器,Windows10使用命令参数打开文件资源管理器的方法...
  17. iis服务器安装帝国网站,安装帝国cms如何配置iis
  18. 查看docker应用信息
  19. 西门子KTP二代精简触摸屏点击无反应,触摸失效的处理对策
  20. linux下启动,关闭oracle数据库

热门文章

  1. 复数类n次方原理以及C#代码实现
  2. 16.0 vue3 Teleport---自定义dialog组件
  3. [ios版本]AR 现实增强之高通Vuforia
  4. 没事来冒个泡(java之冒泡)
  5. 安卓端功能强大的Gif工具箱 | 超好用的Gif图片编辑软件
  6. 目标检测:数据预处理——图像增广
  7. 树莓派智能小车python论文_基于树莓派的自动驾驶小车,利用树莓派和tensorflow实现小车在赛道的自动驾驶...
  8. HTML标签对应英文全称及简单描述
  9. LuckySheet设置单元格格式为千分符保存至后台再获取时格式失效
  10. 如何提高自我控制能力