Package: pyass
pyassA library to read, manipulate, and write Advanced SubStation Alpha (.ass) filesInstallationpip3installpyassQuickstartimportpyassfromdatetimeimporttimedelta# subtitles.ass'''[Script Info]; Script generated by Aegisub 3.2.2; http://www.aegisub.org/Title: New subtitlesScriptType: v4.00+WrapStyle: 0PlayResX: 640PlayResY: 480ScaledBorderAndShadow: yes[Aegisub Project Garbage][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, EncodingStyle: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1[Events]Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, TextDialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,This is an event'''# Read an .ass file# .ass files are typically encoded using "utf_8_sig"withopen("subtitles.ass",encoding="utf_8_sig")asf:script=pyass.load(f)# Read stylesforstyleinscript.styles:# Style name: Default, Font name: Arial, Font size: 20, Primary color: &H00FFFFFFprint(f'Style name:{style.name}, Font name:{style.fontName}, Font size:{style.fontSize}, Primary color:{style.primaryColor}')# Modify stylesscript.styles[0].fontName="Times New Roman"# Add stylesscript.styles.append(pyass.Style(name="New Style",primaryColor=pyass.Color(r=0xFF)))forstyleinscript.styles:# Style name: Default, Font name: Times New Roman, Font size: 20, Primary color: &H00FFFFFF# Style name: New Style, Font name: Arial, Font size: 48, Primary color: &H000000FFprint(f'Style name:{style.name}, Font name:{style.fontName}, Font size:{style.fontSize}, Primary color:{style.primaryColor}')# Read eventsforeventinscript.events:# Style: Default, Start: 0:00:00.00, End: 0:00:05.00, Text: This is an eventprint(f'Style:{event.style}, Start:{event.start}, End:{event.end}, Text:{event.text}')# Modify eventsscript.events[0].text="Some new text"# Add eventsscript.events.append(pyass.Event(format=pyass.EventFormat.COMMENT,start=timedelta(seconds=0),end=timedelta(seconds=10),text="This is a comment"))foreventinscript.events:# Style: Default, Start: 0:00:00.00, End: 0:00:05.00, Text: Some new text# Style: Default, Start: 0:00:00, End: 0:00:10, Text: This is a commentprint(f'Style:{event.style}, Start:{event.start}, End:{event.end}, Text:{event.text}')# Write an .ass file# .ass files are typically encoded using "utf_8_sig"withopen("new_subtitles.ass","w+",encoding="utf_8_sig")asf:pyass.dump(script,f)# new_subtitles.ass'''[Script Info]; Script generated by Aegisub 3.2.2; http://www.aegisub.org/Title: New subtitlesScriptType: v4.00+WrapStyle: 0PlayResX: 640PlayResY: 480ScaledBorderAndShadow: yes[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, EncodingStyle: Default,Times New Roman,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1Style: New Style,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1[Events]Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, TextDialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Some new textComment: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,This is a comment'''