Last active
July 30, 2022 09:42
-
-
Save segfault-bilibili/5e52bde2b63035e6c7f9ed08edac6ffb to your computer and use it in GitHub Desktop.
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
var fs = require('fs') | |
function convertSub(jsonobj) { | |
//let result = fs.readFileSync("head.ass"); | |
let result = "[Script Info]\n"; | |
result += "; Script generated by Aegisub 3.2.2\n"; | |
result += "; http://www.aegisub.org/\n"; | |
result += "Title: Default Aegisub file\n"; | |
result += "ScriptType: v4.00+\n"; | |
result += "WrapStyle: 0\n"; | |
result += "ScaledBorderAndShadow: yes\n"; | |
result += "YCbCr Matrix: None\n"; | |
result += "\n"; | |
result += "[V4+ Styles]\n"; | |
result += "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n"; | |
result += "Style: 1080p,Arial,75,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1\n"; | |
result += "Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1\n"; | |
result += "\n"; | |
result += "[Events]\n"; | |
function fillZero(num) { | |
if (num > 10) return "" + num; | |
else if (num > 0) return "0" + num; | |
else if (num == 0) return "00"; | |
else throw new Error(); | |
} | |
function secToTime(sec) { | |
let secstr = "" + sec; | |
let secsplitted = secstr.split("."); | |
let secint = secsplitted[0]; | |
let secrem = secint % 60 | |
secint -= secrem; | |
let min = secint / 60; | |
secint -= min * 60; | |
let decimals = secsplitted[1]; | |
if (decimals == undefined) decimals = "00"; | |
else { | |
decimals = (decimals + "00").substring(0, 2); | |
} | |
return "0:" + fillZero(min) + ":" + fillZero(secrem) + "." + decimals; | |
} | |
jsonobj.body.forEach((ev) => { | |
let line = "Dialogue: 0," + secToTime(ev.from) + "," + secToTime(ev.to) + ",*Default,NTP,0,0,0,," + ev.content.replaceAll("\n", "\\n"); | |
result += line + "\n"; | |
}); | |
return result; | |
} | |
for (let i = 9; i<= 12; i++) { | |
let jsontext = fs.readFileSync("" + i + ".json"); | |
let jsonobj = JSON.parse(jsontext); | |
let episodeNum = i < 10 ? "0" + i : i; | |
let fileName = "BANGUMI_NAME " + episodeNum + " .ass" | |
fs.writeFileSync(fileName, convertSub(jsonobj)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment