Created
August 3, 2023 07:06
-
-
Save gnehs/d75952e4f94be89975109a67e5f54d13 to your computer and use it in GitHub Desktop.
Remove [Fonts] section from ass file
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
import fs from "fs"; | |
fs.readdirSync(".").forEach((file) => { | |
if (file.split(".").at(-1) === "ass") { | |
let fileData = fs.readFileSync(file, { encoding: "utf-8" }).split("\n"); | |
let isFont = false; | |
let newFile = []; | |
for (let line of fileData) { | |
let matchSectionName = line.match(/\[(.+)\]/); | |
if (matchSectionName) { | |
if (matchSectionName[1] === "Fonts") isFont = true; | |
if (matchSectionName[1] === "Events") isFont = false; | |
} | |
if (!isFont) newFile.push(line); | |
} | |
let fileName = file.split("."); | |
fileName.pop(); | |
fileName = `${fileName.join(".")}.fontRemoved.ass`; | |
fs.writeFileSync(fileName, newFile.join("\n")); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment