Skip to content

Instantly share code, notes, and snippets.

@8mist
Created October 7, 2023 12:21
Show Gist options
  • Save 8mist/9ddc36969e409395578b94bed78876de to your computer and use it in GitHub Desktop.
Save 8mist/9ddc36969e409395578b94bed78876de to your computer and use it in GitHub Desktop.
const fs = require('node:fs')
const path = require('node:path')
const BUFFER_ENCODING = 'utf8'
const getFilePath = (filename) => path.resolve(__dirname, filename)
const format = (filename) => {
return fs
.readFileSync(getFilePath(filename), BUFFER_ENCODING)
.replace(/\r/g, '')
.trim()
.replace(/(\d+\n)?\d{2}:\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}:\d{2}\.\d{3}\n/g, '')
.replace(/^\s*[\r\n]/gm, '')
}
const writeFile = (filename, content) => fs.writeFileSync(getFilePath(filename), content, BUFFER_ENCODING)
const outputContent = format('input.vtt')
writeFile('output.vtt', outputContent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment