-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (55 loc) · 1.59 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs')
const timecodes = require('node-timecodes')
const events = []
let count = 0
let sub = 0
let start = null
let end = null
let evtc = null
let evstr = null
const newX = /\[ \d+\.\d+\,/g
const afterMe = /\"\w.*\"/g
fs.readFileSync('log.scd').toString().split('\n').forEach(line => {
console.log(count, line)
if (line==='[') {
console.log('THIS IS OUR START')
}
if (line.includes('[ ')) {
console.log('NEW EXECUTION!')
start = count
const regMatch = line.match(newX)
if (regMatch) {
console.log('FUCKKKKKKKKKKKKKKKYAAAAAAAAAAAAAAAAAAAAA')
const after = line.match(afterMe)
evtc = parseFloat(regMatch[0].replace('[ ', '').replace(',', ''))
if (after != null) {
evstr = after[0].replace('"', '').replace('"', '')
}
}
}
const splLine = line.split('')
if (splLine.pop() === ',' && splLine[splLine.length-1] === ']') {
console.log('END EXECUTION!')
end = count
}
if (start != null && end != null) {
if (evstr) {
events.push([parseFloat(parseFloat(evtc).toFixed(3)), evstr])
// events.push([start, end, evtc, evstr])
}
start = null
end = null
evtc = null
evstr = null
}
count += 1
})
console.log(events)
let outString = ''
events.forEach(ev => {
const fixSt = `${timecodes.fromSeconds(ev[0]).split(':').splice(0,3).join(':') + '.000'}`
const fixEn = `${timecodes.fromSeconds(ev[0] + 2.0).split(':').splice(0,3).join(':') + '.000'}`
outString = outString + `\n${sub++}\n${fixSt} --> ${fixEn}\n${ev[1]}\n`
})
console.log(outString)
fs.writeFileSync('test.srt', outString)