forked from algolia/youtube-captions-scraper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
34 lines (29 loc) · 809 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const getSubtitles = require('./dist').getSubtitles
// import ytttjs from "./index.mjs"
// const getSubtitles = require('./dist').getSubtitles
const fs = require('fs')
// import path from 'path'
let arg = process.argv[2] // should include path
console.log(arg)
if (!arg) throw "Needs input data!"
switch (arg){
case '-h':
case '--help':
console.log(`First arg: YouTube video ID number
Output will be 'ARG.captions.json'
`)
break
default:
console.log(`Attempting to grab captions for `+ arg)
let res = {}
getSubtitles({
videoID: arg,
lang: 'en' // default: `en`
}).then(captions => {
res = captions
console.log(res)
const outputPath = __dirname +'/'+ arg +'.captions.json'
console.log(`saving to: `+ outputPath)
fs.writeFileSync(outputPath, JSON.stringify(res))
})
}