A library to read, manipulate, and write Advanced SubStation Alpha (.ass) files
Project description
pyass
A library to read, manipulate, and write Advanced SubStation Alpha (.ass) files
Installation
pip3 install pyass
Quickstart
import pyass
from datetime import timedelta
# subtitles.ass
'''
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: New subtitles
ScriptType: v4.00+
WrapStyle: 0
PlayResX: 640
PlayResY: 480
ScaledBorderAndShadow: 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, Encoding
Style: 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, Text
Dialogue: 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"
with open("subtitles.ass", encoding="utf_8_sig") as f:
script = pyass.load(f)
# Read styles
for style in script.styles:
# Style name: Default, Font name: Arial, Font size: 20, Primary color: &H00FFFFFF
print(f'Style name: {style.name}, Font name: {style.fontName}, Font size: {style.fontSize}, Primary color: {style.primaryColor}')
# Modify styles
script.styles[0].fontName = "Times New Roman"
# Add styles
script.styles.append(pyass.Style(name="New Style", primaryColor=pyass.Color(r=0xFF)))
for style in script.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: &H000000FF
print(f'Style name: {style.name}, Font name: {style.fontName}, Font size: {style.fontSize}, Primary color: {style.primaryColor}')
# Read events
for event in script.events:
# Style: Default, Start: 0:00:00.00, End: 0:00:05.00, Text: This is an event
print(f'Style: {event.style}, Start: {event.start}, End: {event.end}, Text: {event.text}')
# Modify events
script.events[0].text = "Some new text"
# Add events
script.events.append(pyass.Event(format=pyass.EventFormat.COMMENT, start=timedelta(seconds=0), end=timedelta(seconds=10), text="This is a comment"))
for event in script.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 comment
print(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"
with open("new_subtitles.ass", "w+", encoding="utf_8_sig") as f:
pyass.dump(script, f)
# new_subtitles.ass
'''
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: New subtitles
ScriptType: v4.00+
WrapStyle: 0
PlayResX: 640
PlayResY: 480
ScaledBorderAndShadow: 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, Encoding
Style: Default,Times New Roman,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
Style: 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, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Some new text
Comment: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,This is a comment
'''
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyass-0.1.2.tar.gz
(13.5 kB
view details)
Built Distribution
pyass-0.1.2-py3-none-any.whl
(16.3 kB
view details)
File details
Details for the file pyass-0.1.2.tar.gz
.
File metadata
- Download URL: pyass-0.1.2.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 226782d5885665bdbd33a4c0a7dcb4cc7455b594f58add57acf6f37311745280 |
|
MD5 | ab3ab2d5be9340870b8c448ce6e94fcf |
|
BLAKE2b-256 | 459a37c1576192e984cfde0966a4d64e6809277c2ad677f3ef36628d12bf0975 |
File details
Details for the file pyass-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: pyass-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 778c9aaa6b895b9248936d4696254b29f3bbfacd5c371e02021a0f12b5ec6a7c |
|
MD5 | 1c7db44e4325540fe5823ab0d543f3d2 |
|
BLAKE2b-256 | 2bb34454b2b46ca28ba74e3da2668a871b1cc3779213653e77b4be24ebea5550 |