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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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,
linefields will be re-calculated based on the re-positionedline.chars.progress (bool) – If True, a progress bar will be displayed when iterating over the lines.
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.
- 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(...): ...