Last active
July 28, 2021 17:10
-
-
Save qgustavor/1ad422eb9acc91192c39d7d164425181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
async function main () { | |
const files = await fs.promises.readdir('.') | |
for (const file of files) { | |
if (!file.endsWith('.ass')) continue | |
const data = await fs.promises.readFile(file, 'utf-8') | |
const lines = data.split(/\r?\n/g) | |
const timeCounts = {} | |
for (let i = 0; i < lines.length; i++) { | |
const line = lines[i] | |
if (!line.startsWith('Dialogue:')) continue | |
const parts = line.split(',') | |
const count = timeCounts[parts[1]] = (timeCounts[parts[1]] || 0) + 1 | |
parts[0] = 'Dialogue: ' + (timeCounts[parts[1]] - 1) | |
lines[i] = parts.join(',').replace(/\\pos\(640,[^)]+\)/g, '') | |
} | |
await fs.promises.writeFile(file, lines.join('\r\n')) | |
} | |
} | |
main().catch(e => { | |
console.error(e) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment