Get captions as json from youtube by youtube-dl
> npm install youtube-subs-json
const getSubtitles = require('youtube-subs-json').getSubtitles;
getSubtitles({
videoID: 'XXXXX', // youtube video id or url
lang: 'ru' // default: `en`
}).then( captions => {
console.log(captions)
}).catch( err => {
console.error(err)
})
Captions will be an array of object of this format:
{
"begin": String, // 00:00:03.419
"end": String, // 00:00:10.320
"start": Number, // 3.419
"dur": Number, // 6.901
"text": String // some phrase
}