Ass Core

class pyonfx.ass_core.Meta(wrap_style: int | None = None, scaled_border_and_shadow: bool | None = None, play_res_x: int | None = None, play_res_y: int | None = None, audio: str | None = None, video: str | None = None, timestamps: ABCTimestamps | None = None)[source]

Meta object contains informations about the Ass.

More info about each of them can be found on http://docs.aegisub.org/manual/Styles

wrap_style: int | None

Determines how line breaking is applied to the subtitle line.

scaled_border_and_shadow: bool | None

Determines if script resolution (True) or video resolution (False) should be used to scale border and shadow.

play_res_x: int | None

Video width resolution.

play_res_y: int | None

Video height resolution.

audio: str | None

Loaded audio file path (absolute).

video: str | None

Loaded video file path (absolute).

timestamps: ABCTimestamps | None

Timestamps associated to the video file.

parse_line(line: str, ass_path: str) str[source]

Parses a single ASS line and update the relevant fields.

Returns the updated line.

class pyonfx.ass_core.Style(name: str, fontname: str, fontsize: float, color1: str, alpha1: str, color2: str, alpha2: str, color3: str, alpha3: str, color4: str, alpha4: str, bold: bool, italic: bool, underline: bool, strikeout: bool, scale_x: float, scale_y: float, spacing: float, angle: float, border_style: bool, outline: float, shadow: float, alignment: int, margin_l: int, margin_r: int, margin_v: int, encoding: int)[source]

Style object contains a set of typographic formatting rules that is applied to dialogue lines.

name: str

Style name.

fontname: str

Font name.

fontsize: float

Font size in points.

color1: str

Primary color (fill).

alpha1: str

Transparency of color1.

color2: str

Secondary color (for karaoke effect).

alpha2: str

Transparency of color2.

color3: str

Outline (border) color.

alpha3: str

Transparency of color3.

color4: str

Shadow color.

alpha4: str

Transparency of color4.

bold: bool

Whether the font is bold.

italic: bool

Whether the font is italic.

underline: bool

Whether the font is underlined.

strikeout: bool

Whether the font is struck out.

scale_x: float

Horizontal text scaling (percentage).

scale_y: float

Vertical text scaling (percentage).

spacing: float

Horizontal spacing between letters.

angle: float

Text rotation angle (degrees).

border_style: bool

True for opaque box, False for standard outline.

outline: float

Border thickness.

shadow: float

Shadow offset distance.

alignment: int

Text alignment (ASS alignment code).

margin_l: int

Left margin (pixels).

margin_r: int

Right margin (pixels).

margin_v: int

Vertical margin (pixels).

encoding: int

Font encoding/codepage.

classmethod from_ass_line(line: str) Style[source]

Parses a single ASS line and returns the corresponding Style object.

serialize(style_name: str) str[source]

Serializes a Style object into an ASS style line.

class pyonfx.ass_core.Char(i: int, word_i: int, syl_i: int, syl_char_i: int, start_time: int, end_time: int, duration: int, styleref: Style, text: str, inline_fx: str, width: float, height: float, x: float, y: float, left: float, center: float, right: float, top: float, middle: float, bottom: float)[source]

Char object contains information about a single character in a line.

i: int

Character index in the line.

word_i: int

Index of the word this character belongs to.

syl_i: int

Index of the syllable this character belongs to.

syl_char_i: int

Index of the character within its syllable.

start_time: int

Start time (ms) of the character.

end_time: int

End time (ms) of the character.

duration: int

Duration (ms) of the character.

styleref: Style

Reference to the Style object for this character’s line.

text: str

The character itself as a string.

inline_fx: str

Inline effect for the character (from \-EFFECT tag).

width: float

Width of the character (pixels).

height: float

Height of the character (pixels).

x: float

Horizontal position of the character (pixels).

y: float

Vertical position of the character (pixels).

left: float

Left position of the character (pixels).

center: float

Center position of the character (pixels).

right: float

Right position of the character (pixels).

top: float

Top position of the character (pixels).

middle: float

Middle position of the character (pixels).

bottom: float

Bottom position of the character (pixels).

class pyonfx.ass_core.Syllable(i: int, word_i: int, start_time: int, end_time: int, duration: int, styleref: Style, text: str, tags: str, inline_fx: str, prespace: int, postspace: int, width: float, height: float, x: float, y: float, left: float, center: float, right: float, top: float, middle: float, bottom: float)[source]

Syllable object contains information about a single syllable in a line.

i: int

Syllable index in the line.

word_i: int

Index of the word this syllable belongs to.

start_time: int

Start time (ms) of the syllable.

end_time: int

End time (ms) of the syllable.

duration: int

Duration (ms) of the syllable.

styleref: Style

Reference to the Style object for this syllable’s line.

text: str

Text of the syllable.

tags: str

ASS override tags preceding the syllable text (excluding \k tags).

inline_fx: str

Inline effect for the syllable (from \-EFFECT tag).

prespace: int

Number of spaces before the syllable.

postspace: int

Number of spaces after the syllable.

width: float

Width of the syllable (pixels).

height: float

Height of the syllable (pixels).

x: float

Horizontal position of the syllable (pixels).

y: float

Vertical position of the syllable (pixels).

left: float

Left position of the syllable (pixels).

center: float

Center position of the syllable (pixels).

right: float

Right position of the syllable (pixels).

top: float

Top position of the syllable (pixels).

middle: float

Middle position of the syllable (pixels).

bottom: float

Bottom position of the syllable (pixels).

class pyonfx.ass_core.Word(i: int, start_time: int, end_time: int, duration: int, styleref: Style, text: str, prespace: int, postspace: int, width: float, height: float, x: float, y: float, left: float, center: float, right: float, top: float, middle: float, bottom: float)[source]

Word object contains information about a single word in a line.

i: int

Word index in the line.

start_time: int

Start time (ms) of the word (same as line start).

end_time: int

End time (ms) of the word (same as line end).

duration: int

Duration (ms) of the word (same as line duration).

styleref: Style

Reference to the Style object for this word’s line.

text: str

Text of the word.

prespace: int

Number of spaces before the word.

postspace: int

Number of spaces after the word.

width: float

Width of the word (pixels).

height: float

Height of the word (pixels).

x: float

Horizontal position of the word (pixels).

y: float

Vertical position of the word (pixels).

left: float

Left position of the word (pixels).

center: float

Center position of the word (pixels).

right: float

Right position of the word (pixels).

top: float

Top position of the word (pixels).

middle: float

Middle position of the word (pixels).

bottom: float

Bottom position of the word (pixels).

class pyonfx.ass_core.Line(comment: bool, layer: int, start_time: int, end_time: int, style: str, styleref: Style, actor: str, margin_l: int, margin_r: int, margin_v: int, effect: str, raw_text: str, text: str, i: int, duration: int, leadin: int, leadout: int, width: float, height: float, ascent: float, descent: float, internal_leading: float, external_leading: float, x: float, y: float, left: float, center: float, right: float, top: float, middle: float, bottom: float, words: list[Word], syls: list[Syllable], chars: list[Char])[source]

Line object contains information about a single subtitle line in the ASS file.

comment: bool

True if this line is a comment, False if it is a dialogue.

layer: int

Layer number for the line (higher layers are drawn above lower ones).

start_time: int

Start time (ms) of the line.

end_time: int

End time (ms) of the line.

style: str

Style name used for this line. Could be None in case of non-existing style name.

styleref: Style

Reference to the Style object for this line.

actor: str

Actor field.

margin_l: int

Left margin for this line (pixels).

margin_r: int

Right margin for this line (pixels).

margin_v: int

Vertical margin for this line (pixels).

effect: str

Effect field.

raw_text: str

Raw text of the line (including tags).

text: str

Stripped text of the line (no tags).

i: int

Line index in the file.

duration: int

Duration (ms) of the line.

leadin: int

Time (ms) between this line and the previous one.

leadout: int

Time (ms) between this line and the next one.

width: float

Width of the line (pixels).

height: float

Height of the line (pixels).

ascent: float

Font ascent for the line.

descent: float

Font descent for the line.

internal_leading: float

Font internal leading for the line.

external_leading: float

Font external leading for the line.

x: float

Horizontal position of the line (pixels).

y: float

Vertical position of the line (pixels).

left: float

Left position of the line (pixels).

center: float

Center position of the line (pixels).

right: float

Right position of the line (pixels).

top: float

Top position of the line (pixels).

middle: float

Middle position of the line (pixels).

bottom: float

Bottom position of the line (pixels).

words: list[Word]

List of Word objects in this line.

syls: list[Syllable]

List of Syllable objects in this line (if available).

chars: list[Char]

List of Char objects in this line.

copy() Line[source]
Returns:

A deep copy of this object (line)

classmethod from_ass_line(line: str, line_index: int, styles: dict[str, Style]) Line[source]

Parses a single ASS line and returns the corresponding Line object.

class pyonfx.ass_core.Ass(path_input: str, path_output: str = 'output.ass', keep_original: bool = True, extended: bool = True, vertical_kanji: bool = False)[source]

Contains all the informations about a file in the ASS format and the methods to work with it for both input and output.

Usually you will create an Ass object and use it for input and output (see example section).
PyonFX set automatically an absolute path for all the info in the output, so that wherever you will put your generated file, it should always load correctly video and audio.
Parameters:
  • path_input (str) – Path for the input file (either relative to your .py file or absolute).

  • path_output (str) – Path for the output file (either relative to your .py file or absolute) (DEFAULT: “Output.ass”).

  • keep_original (bool) – If True, you will find all the lines of the input file commented before the new lines generated.

  • extended (bool) – Calculate more informations from lines (usually you will not have to touch this).

  • vertical_kanji (bool) – If True, line text with alignment 4, 5 or 6 will be positioned vertically. Additionally, line fields will be re-calculated based on the re-positioned line.chars.

  • progress (bool) – If True, a progress bar will be displayed when iterating over the lines.

path_input

Path for input file (absolute).

Type:

str

path_output

Path for output file (absolute).

Type:

str

meta

Contains informations about the ASS given.

Type:

Meta

styles

Contains all the styles in the ASS given.

Type:

list of Style

lines

Contains all the lines (events) in the ASS given.

Type:

list of Line

PIXEL_STYLE

Constant lightweight style for pixels.

Type:

Style

Example

io = Ass("in.ass")
meta, styles, lines = io.get_data()
PIXEL_STYLE = Style(name='p', fontname='Arial', fontsize=20, color1='FFFFFF', alpha1='00', color2='FFFFFF', alpha2='00', color3='000000', alpha3='0000', color4='000000', alpha4='0000', bold=False, italic=False, underline=False, strikeout=False, scale_x=100, scale_y=100, spacing=0, angle=0, border_style=False, outline=0, shadow=0, alignment=7, margin_l=0, margin_r=0, margin_v=0, encoding=1)

Lightweight style for pixels.

get_data() tuple[Meta, dict[str, Style], list[Line]][source]

Utility function to retrieve easily meta, styles and lines.

Returns:

meta, styles and lines

add_style(style_name: str, style: Style) None[source]

Adds a given ASS style into the output if it doesn’t already exist.

The style is serialized and inserted into the [V4+ Styles] section.

write_line(line: Line) None[source]

Appends a line to the output list (which is private) that later on will be written to the output file when calling save().

Use it whenever you’ve prepared a line, it will not impact performance since you will not actually write anything until save() will be called.

Parameters:

line (Line) – A line object. If not valid, TypeError is raised.

save(quiet: bool = False) None[source]

Write everything inside the private output list to a file.

Parameters:

quiet (bool) – If True, you will not get printed any message.

open_aegisub() bool[source]

Attempts to open the subtitle output file in Aegisub.

Returns:

True if the file is successfully opened, False otherwise.

open_mpv(video_path: str | None = None, *, video_start: str | None = None, full_screen: bool = False, extra_mpv_options: list[str] = [], aegisub_fallback: bool = True) bool[source]

Opens the output subtitle file using MPV media player along with the associated video.

This method attempts to:
  • Use an already running MPV instance to hot-reload subtitles via an IPC socket if detected.

  • Launch a new MPV process with IPC enabled if no such instance exists.

  • Fall back to opening the output in Aegisub if MPV is not available and aegisub_fallback is True.

Parameters:
  • video_path (str | None) – The absolute path to the video file to be played. If None, the video path from meta.video is used.

  • video_start (str | None) – The starting time for video playback (e.g., “00:01:23”). If None, playback starts from the beginning.

  • full_screen (bool) – If True, launches MPV in full-screen mode; otherwise, in windowed mode.

  • extra_mpv_options (list[str]) – Additional command-line options to pass to MPV.

  • aegisub_fallback (bool) – If True, falls back to opening the output with Aegisub when MPV is not found in the system PATH.

Returns:

True if MPV is successfully launched or the subtitles are hot-reloaded in an existing MPV instance; False otherwise (e.g., if the output file has not been saved or MPV is unavailable).

track(func: Callable[[...], Any]) Callable[[...], Any][source]

Decorator to track function performance, gathering timing statistics and monitoring progress.

This decorator automatically measures execution time, counts function calls, and tracks the number of lines produced by the decorated function. All statistics are displayed in the final output when save() is called.

Usage:

@io.track
def my_function(...):
    ...
pyonfx.ass_core.resolve_path(base_path: str, input_path: str) str[source]

Resolve an input path relative to a base path or return absolute path if input is absolute.

pyonfx.ass_core.pretty_print(obj)[source]

Create a pretty string representation for dataclass objects.

Special handling for Style objects and list-based fields.