ytdl-core
モジュール ( https://github.com/fent/node-ytdl-core )を使用して Youtube ビデオ オーディオをダウンロードしようとしています。
Express を使用して、URL でオーディオをダウンロードできる API を作成しました。
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 エラーが発生することです。
このダウンロードしたオーディオをローカル ディスクに保存できるようにしたいと考えています。
助けていただければ幸いです。ありがとうございました