Node.js Heroku上的Youtube dl空下载有时\在重新启动dyno时效果良好?
我正在NodeJS中使用Youtube-dl,使用子进程spawn,并将输出视频作为下载传输到浏览器。 代码按预期工作,但有时会发送一个空文件。现在,如果我重新启动dyno,应用程序运行得很好? 该应用程序托管在Heroku免费层上。不会抛出任何错误Node.js Heroku上的Youtube dl空下载有时\在重新启动dyno时效果良好?,node.js,heroku,pipe,video-streaming,youtube-dl,Node.js,Heroku,Pipe,Video Streaming,Youtube Dl,我正在NodeJS中使用Youtube-dl,使用子进程spawn,并将输出视频作为下载传输到浏览器。 代码按预期工作,但有时会发送一个空文件。现在,如果我重新启动dyno,应用程序运行得很好? 该应用程序托管在Heroku免费层上。不会抛出任何错误 /*Downloading ,Converting mp4 youtube video using video_id */ const ytdl = spawn('youtube-dl', [
/*Downloading ,Converting mp4 youtube video using video_id */
const ytdl = spawn('youtube-dl', [
'-o',//output
'-',//stdout
'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',//best mp4 extension , else best
'--recode-video',//recode video
'mp4',//to mp4 if not mp4
'-a',//input stream
'-'//stdin
])
.on('error',(err)=>next(err))
.on('exit',(code)=>console.log(`Ytdl exited with code ${code}`));
/* Setting output pipe first so that we dont lose any bits */
ytdl.stdout.pipe(res).on('error',(err)=>next(err));
/*Catching error on stdin */
ytdl.stdin.on('error',(err)=>next(err));
/* Writing video url to stdin for youtube-dl */
ytdl.stdin.write(`http://www.youtube.com/watch?v=${vid}`)
/*Closing the input stream*/
ytdl.stdin.end();
大约70%的时间正确下载视频,但其他时间为同一视频下载空文件
我想知道它是否与杀死孩子进程或关闭流或Heroku dynos睡眠有关
Log during Empty Download:
2020-01-17T17:36:36.704915+00:00 heroku[router]: at=info method=GET path="/youtube/download/video/KBtk5FUeJbk/Sub%20Urban%20-%20Cradles%20%5BOFFICIAL%20MUSIC%20VIDEO%5D" host=youtube-plus.herokuapp.com request_id=5ec18598-f702-421d-aec9-52d4e8a8fc33 fwd="150.242.75.17" dyno=web.1 connect=0ms service=1953ms status=200 bytes=234 protocol=https
2020-01-17T17:36:36.704195+00:00 app[web.1]: GET /youtube/download/video/KBtk5FUeJbk/Sub%20Urban%20-%20Cradles%20%5BOFFICIAL%20MUSIC%20VIDEO%5D 200 1952.343 ms - -
2020-01-17T17:36:36.704561+00:00 app[web.1]: Ytdl exited with code 1
好吧,我想出了解决办法。问题是youtube经常更新其网站,因此我们需要在Dynos中安装最新的youtube dl。但要在heroku上重新安装buildpack,我们需要重新部署该应用程序
git commit --allow-empty -m"Updating BuildPacks And Redeploy To Heroku"
git push heroku master
已安装buildpack的最新版本,且应用程序工作正常
git commit --allow-empty -m"Updating BuildPacks And Redeploy To Heroku"
git push heroku master