My code in nodejs is like this :-
var fs = require('fs');
var youtubedl = require('youtube-dl');
var video = youtubedl('http://www.youtube.com/watch?v=90AiXO1pAiA',
// Optional arguments passed to youtube-dl.
// Additional options can be given for calling `child_process.execFile()`.
);
// Will be called when the download starts.
video.on('info', function(info) {
console.log('Download started');
console.log('filename: ' + info.filename);
console.log('size: ' + info.size);
});
video.pipe(fs.createWriteStream('myvideo.mp4'));
I get this error:-
SPAWN unknown
You can also suggest an alternative way of making youtube downloader.
I have same problem on Windows, I fixed it as:
Step 1: Goto this link: https://rg3.github.io/youtube-dl/download.html
Step 2: Download Windows exe (sig - SHA256 7071c7a2.....................)
Step 3:
Replace it at \node_modules\youtube-dl\bin
Step 4: Run your code:
const fs = require('fs');
const youTube = require('youtube-dl');
const video = youTube('http://www.youtube.com/watch?v=90AiXO1pAiA');
// called when the download starts.
video.on('info', function(info) {
console.log('Download started');
console.log('filename: ' + info.filename);
console.log('size: ' + info.size);
});
video.pipe(fs.createWriteStream('downloads/downloaded_video.mp4'));
Step 5: Expected console output:
/* Sample Output */
/*
Download started
filename: lol-90AiXO1pAiA.webm
size: 1029843
NOTE: File will be downloaded in downloads folder
*/
for complete files and running project:
Clone node-cheat youtube_download_videos, run node download_script.js
followed by npm i youtube-dl
.