-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-transcript-json.js
More file actions
41 lines (34 loc) · 1 KB
/
parse-transcript-json.js
File metadata and controls
41 lines (34 loc) · 1 KB
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
35
36
37
38
39
40
41
const data = require('./data.json')
console.log(data.timedtext.body.p.length)
const datapoint = {
ts: null,
text: '',
}
const records = []
// Parse data
data.timedtext.body.p.forEach((part, i) => {
if (part.s) {
let beginningTS = +part['_t']
if (part.s.forEach) {
part['s'].forEach(string => {
records.push({ ...datapoint, ts: string['_t'] ? beginningTS + Number(string['_t']) : beginningTS, text: string['__text'] })
})
} else {
records.push({ ...datapoint, ts: part.s['_t'] ? beginningTS + Number(part.s['_t']) : beginningTS, text: part.s['__text'] })
}
}
})
module.export = records
// Write to csv
// const createCsvWriter = require('csv-writer').createObjectCsvWriter;
// const csvWriter = createCsvWriter({
// path: './transcript.csv',
// header: [
// { id: 'ts', title: 'Timestamp' },
// { id: 'text', title: 'Word' }
// ]
// });
// csvWriter.writeRecords(records) // returns a promise
// .then(() => {
// console.log('...Done');
// });