-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathccsub2ass.py
More file actions
45 lines (34 loc) · 1.43 KB
/
ccsub2ass.py
File metadata and controls
45 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
import sys
import json
head_str = """[Script Info]
; Script generated by Aegisub
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: TV.709
PlayResX: 1920
PlayResY: 1080
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Microsoft YaHei,58,&H00FFFFFF,&H000000FF,&HFF000000,&H80000000,0,0,0,0,100,100,0,0,3,8,1,2,10,10,35,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
"""
def SectoTime(second):
return f"{int(second) // 3600}:{int(second) // 60 % 60}:{int(second % 60)}.{int(second * 1000) % 1000 // 10}"
def toASS(filename):
subdata = json.load(open(f"{filename}.json", "r", encoding="utf-8"))
assdata = [head_str]
for line in subdata["body"]:
linecount = len(line["content"].split("\n")) - 1
for n, content in enumerate(line["content"].split("\n")):
assdata.append(
f"Dialogue: 0,{SectoTime(line['from'])},{SectoTime(line['to'])},Default,,0,0,{(linecount - n) * 75 + 35},,{content}\n"
)
return assdata
def main(filename):
with open(f"{filename}.ass", "w", encoding="utf-8") as f:
f.writelines(toASS(filename))
if __name__ == "__main__":
main(sys.argv[-1])