Skip to content

Instantly share code, notes, and snippets.

@gnehs
Created August 3, 2023 07:06
Show Gist options
  • Save gnehs/d75952e4f94be89975109a67e5f54d13 to your computer and use it in GitHub Desktop.
Save gnehs/d75952e4f94be89975109a67e5f54d13 to your computer and use it in GitHub Desktop.
Remove [Fonts] section from ass file
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