【问题标题】:Youtube-dl on Heroku empty download sometimes \ Works fine on restarting dyno?Heroku 上的 Youtube-dl 有时空下载\在重新启动测功机时可以正常工作吗?
【发布时间】:2020-01-17 19:13:51
【问题描述】:

我在 NodeJS 中使用 Youtube-dl,使用子进程生成并将输出视频作为下载内容传送到浏览器。 代码按预期工作,但有时会发送一个空文件。现在,如果我重新启动测功机,该应用程序可以正常工作吗? 该应用程序托管在 Heroku 免费层上。不会抛出任何错误。


            /*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
Log for same file on correct download :

2020-01-17T19:09:32.400885+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=f72a8672-6031-4b7d-9f93-e1eaf50be0d9 fwd="150.242.75.17" dyno=web.1 connect=0ms service=4922ms status=200 bytes=15774017 protocol=https
2020-01-17T19:09:32.400201+00:00 app[web.1]: GET /youtube/download/video/KBtk5FUeJbk/Sub%20Urban%20-%20Cradles%20%5BOFFICIAL%20MUSIC%20VIDEO%5D 200 3609.879 ms - -
2020-01-17T19:09:32.400722+00:00 app[web.1]: Ytdl exited with code 1

【问题讨论】:

    标签: node.js heroku pipe video-streaming youtube-dl


    【解决方案1】:

    好的,所以我想出了解决方案。问题是 youtube 经常更新其网站,因此我们需要在 Dynos 中安装最新的 youtube-dl。但是要在 heroku 上重新安装 buildpack,我们需要重新部署应用程序。

    git commit --allow-empty -m"Updating BuildPacks And Redeploy To Heroku"
    git push heroku master
    

    最新版本的 buildpack 已安装且应用正常运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-27
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 2021-07-04
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多