Platform independent binary installer of youtube-dl.
Fork of Kikobeats/youtube-dl-installer which has gone unmaintained for some time.
$ npm install youtube-dl-installer-ng --save
Require this module in your js application. Doing so will ensure that the latest version of youtube-dl is installed on your system. @todo add where it gets installed
require('youtube-dl-installer')
Following that, you can directly invoke the youtube-dl binary using child_process, or indirectly using a module such as youtube-dl or ytdl-run.
'use strict'
require('youtube-dl-installer')
const { promisify } = require('util')
const execFile = promisify(require('child_process').execFile)
const getInfo = async url => {
const args = [ '--dump-json', '-f', 'best', url ]
const {stdout, stderr} = await execFile(youtubeDlPath, args)
return stderr === '' ? JSON.parse(stdout) : {}
}
;(async () => {
const payload = await getInfo('https://www.youtube.com/watch?v=hwMkbaS_M_c')
console.log(payload)
})()
'use strict'
require('youtube-dl-installer');
var ytdl2 = require('ytdl-run');
const opts = [
'-f', 'bestaudio', 'https://www.youtube.com/watch?v=IgbO5pilG5I'
];
ytdl.stream(opts)
.stdout
.pipe(fs.createWriteStream('video.mp4'))