Created
January 23, 2022 13:54
-
-
Save carlozamagni/7311f8f182a70e716d3c32db3f3d6bf0 to your computer and use it in GitHub Desktop.
Fix SRT file translated by Google Translate API batch
This file contains hidden or 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
| 'use strict' | |
| const fs = require("fs") | |
| const buffer = fs.readFileSync("./source.txt") | |
| const fullText = buffer.toString() | |
| // const REGEX_MATCHES_BAD_MARKER = /(?<!\n{2})^[0-9]+\n/ | |
| const REGEX_MATCHES_NEWLINE_WHEN_ONE_MORE_IS_NEEDED = /(?<!\n)\n(?=^[0-9]+\n)/gm | |
| const fixed = fullText.replace(REGEX_MATCHES_NEWLINE_WHEN_ONE_MORE_IS_NEEDED, '\n\n') | |
| fs.writeFileSync("./dest.srt", fixed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment