【发布时间】:2017-04-26 19:31:42
【问题描述】:
我正在尝试使用 ytdl-core 模块 (https://github.com/fent/node-ytdl-core) 下载 Youtube 视频音频。
我使用 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);
});
问题是,当我调用此 API 时,我的服务器收到 504 错误。
我希望能够将此下载的音频保存在我的本地磁盘上。
我们将不胜感激。谢谢
【问题讨论】:
标签: node.js api express http-status-code-504