Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created October 18, 2022 06:00
Show Gist options
  • Select an option

  • Save tayiorbeii/e60d33d8ca1f6508f800675c1dbd43e3 to your computer and use it in GitHub Desktop.

Select an option

Save tayiorbeii/e60d33d8ca1f6508f800675c1dbd43e3 to your computer and use it in GitHub Desktop.
import "@johnlindquist/kit"
// Name:
let replaceAll = await npm('just-replace-all')
let srtParser2 = await npm('srt-parser-2')
let takeWhile = await npm('lodash.takewhile')
let slice = await npm('lodash.slice')
let parser = new srtParser2()
let srtFiles = await drop()
for (let f of srtFiles) {
let text = await readFile(`${f.path}`, 'utf-8')
let result = parser.fromSrt(text)
let withTimes = result.map(line => {return {...line, totalSeconds: line.endSeconds - line.startSeconds}})
let timeLimitInSeconds = 65
let currentTimeInSeconds = 0
let arrayByTimes = []
let tempArray = []
withTimes.forEach((x, i) => {
if (currentTimeInSeconds + x.totalSeconds >= timeLimitInSeconds) {
arrayByTimes.push(tempArray)
tempArray = []
currentTimeInSeconds = 0
}
currentTimeInSeconds += x.totalSeconds
tempArray.push(x.text)
})
let transcript = arrayByTimes.map(x => x.join(' ')).flat().join('\n\n')
await writeFile(`${f.path}-transcript.txt`, transcript)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment