小编ome*_*lev的帖子

使用 Express API 和 ytdl 下载音频文件

我正在尝试使用该模块下载 Youtube 视频音频ytdl-corehttps://github.com/fent/node-ytdl-core)。

我使用 Express 编写了一个 API,它可以让我通过 URL 下载音频:

app.get('/api/downloadYoutubeVideo', function (req, res) {
   res.set('Content-Type', 'audio/mpeg');       

   var videoUrl = req.query.videoUrl;   
   var videoName;

   ytdl.getInfo(videoUrl, function(err, info){
        videoName = info.title.replace('|','').toString('ascii');
        res.set('Content-Disposition', 'attachment; filename=' +    videoName + '.mp3');    
   });  

   var videoWritableStream = fs.createWriteStream('C:\\test' + '\\' +   videoName); // some path on my computer (exists!)
   var videoReadableStream = ytdl(videoUrl, { filter: 'audioonly'});

   var stream = videoReadableStream.pipe(videoWritableStream);

});
Run Code Online (Sandbox Code Playgroud)

问题是,当我调用此 API 时,我从服务器收到 504 错误。

我希望能够将此下载的音频保存在本地磁盘上。

如有帮助,将不胜感激。谢谢

api node.js http-status-code-504 express

5
推荐指数
1
解决办法
6854
查看次数

标签 统计

api ×1

express ×1

http-status-code-504 ×1

node.js ×1