我正在尝试使用该模块下载 Youtube 视频音频ytdl-core(https://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 错误。
我希望能够将此下载的音频保存在本地磁盘上。
如有帮助,将不胜感激。谢谢