Ass Core

class pyonfx.ass_core.Meta[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

Determines how line breaking is applied to the subtitle line

Type

int

scaled_border_and_shadow

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

Type

bool

play_res_x

Video Width

Type

int

play_res_y

Video Height

Type

int

audio

Loaded audio path (absolute)

Type

str

video

Loaded video path (absolute)

Type

str

class pyonfx.ass_core.Style[source]

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

More info about styles can be found on http://docs.aegisub.org/3.2/ASS_Tags/.

fontname

Font name

Type

str

fontsize

Font size in points

Type

float

color1

Primary color (fill)

Type

str

alpha1

Transparency of color1

Type

str

color2

Secondary color (secondary fill, for karaoke effect)

Type

str

alpha2

Transparency of color2

Type

str

color3

Outline (border) color

Type

str

alpha3

Transparency of color3

Type

str

color4

Shadow color

Type

str

alpha4

Transparency of color4

Type

str

bold

Font with bold

Type

bool

italic

Font with italic

Type

bool

underline

Font with underline

Type

bool

strikeout

Font with strikeout

Type

bool

scale_x

Text stretching in the horizontal direction

Type

float

scale_y

Text stretching in the vertical direction

Type

float

spacing

Horizontal spacing between letters

Type

float

angle

Rotation of the text

Type

float

border_style

True for opaque box, False for standard outline

Type

bool

outline

Border thickness value

Type

float

shadow

How far downwards and to the right a shadow is drawn

Type

float

alignment

Alignment of the text

Type

int

margin_l

Distance from the left of the video frame

Type

int

margin_r

Distance from the right of the video frame

Type

int

margin_v

Distance from the bottom (or top if alignment >= 7) of the video frame

Type

int

encoding

Codepage used to map codepoints to glyphs

Type

int

class pyonfx.ass_core.Char[source]

Char object contains informations about a single char of a line in the Ass.

A char is defined by some text between two karaoke tags (k, ko, kf).

i

Char index number

Type

int

word_i

Char word index (e.g.: In line text Hello PyonFX users!, letter “u” will have word_i=2).

Type

int

syl_i

Char syl index (e.g.: In line text {\k0}Hel{\k0}lo {\k0}Pyon{\k0}FX {\k0}users!, letter “F” will have syl_i=3).

Type

int

syl_char_i

Char invidual syl index (e.g.: In line text {\k0}Hel{\k0}lo {\k0}Pyon{\k0}FX {\k0}users!, letter “e” of “users” will have syl_char_i=2).

Type

int

start_time

Char start time (in milliseconds).

Type

int

end_time

Char end time (in milliseconds).

Type

int

duration

Char duration (in milliseconds).

Type

int

styleref

Reference to the Style object of this object original line.

Type

obj

text

Char text.

Type

str

inline_fx

Char inline effect (marked as -EFFECT in karaoke-time).

Type

str

prespace

Char free space before text.

Type

int

postspace

Char free space after text.

Type

int

width

Char text width.

Type

float

height

Char text height.

Type

float

x

Char text position horizontal (depends on alignment).

Type

float

y

Char text position vertical (depends on alignment).

Type

float

left

Char text position left.

Type

float

center

Char text position center.

Type

float

right

Char text position right.

Type

float

top

Char text position top.

Type

float

middle

Char text position middle.

Type

float

bottom

Char text position bottom.

Type

float

class pyonfx.ass_core.Syllable[source]

Syllable object contains informations about a single syl of a line in the Ass.

A syl can be defined as some text after a karaoke tag (k, ko, kf) (e.g.: In {\k0}Hel{\k0}lo {\k0}Pyon{\k0}FX {\k0}users!, “Pyon” and “FX” are distinct syllables),

i

Syllable index number

Type

int

word_i

Syllable word index (e.g.: In line text {\k0}Hel{\k0}lo {\k0}Pyon{\k0}FX {\k0}users!, syl “Pyon” will have word_i=1).

Type

int

start_time

Syllable start time (in milliseconds).

Type

int

end_time

Syllable end time (in milliseconds).

Type

int

duration

Syllable duration (in milliseconds).

Type

int

styleref

Reference to the Style object of this object original line.

Type

obj

text

Syllable text.

Type

str

tags

All the remaining tags before syl text apart k ones.

Type

str

inline_fx

Syllable inline effect (marked as -EFFECT in karaoke-time).

Type

str

prespace

Syllable free space before text.

Type

int

postspace

Syllable free space after text.

Type

int

width

Syllable text width.

Type

float

height

Syllable text height.

Type

float

x

Syllable text position horizontal (depends on alignment).

Type

float

y

Syllable text position vertical (depends on alignment).

Type

float

left

Syllable text position left.

Type

float

center

Syllable text position center.

Type

float

right

Syllable text position right.

Type

float

top

Syllable text position top.

Type

float

middle

Syllable text position middle.

Type

float

bottom

Syllable text position bottom.

Type

float

class pyonfx.ass_core.Word[source]

Word object contains informations about a single word of a line in the Ass.

A word can be defined as some text with some optional space before or after (e.g.: In the string “What a beautiful world!”, “beautiful” and “world” are both distinct words).

i

Word index number

Type

int

start_time

Word start time (same as line start time) (in milliseconds).

Type

int

end_time

Word end time (same as line end time) (in milliseconds).

Type

int

duration

Word duration (same as line duration) (in milliseconds).

Type

int

styleref

Reference to the Style object of this object original line.

Type

obj

text

Word text.

Type

str

prespace

Word free space before text.

Type

int

postspace

Word free space after text.

Type

int

width

Word text width.

Type

float

height

Word text height.

Type

float

x

Word text position horizontal (depends on alignment).

Type

float

y

Word text position vertical (depends on alignment).

Type

float

left

Word text position left.

Type

float

center

Word text position center.

Type

float

right

Word text position right.

Type

float

top

Word text position top.

Type

float

middle

Word text position middle.

Type

float

bottom

Word text position bottom.

Type

float

class pyonfx.ass_core.Line[source]

Line object contains informations about a single line in the Ass.

Note

(*) = This field is available only if extended = True

i

Line index number

Type

int

comment

If True, this line will not be displayed on the screen.

Type

bool

layer

Layer for the line. Higher layer numbers are drawn on top of lower ones.

Type

int

start_time

Line start time (in milliseconds).

Type

int

end_time

Line end time (in milliseconds).

Type

int

duration

Line duration (in milliseconds) (*).

Type

int

leadin

Time between this line and the previous one (in milliseconds; first line = 1000.1) (*).

Type

float

leadout

Time between this line and the next one (in milliseconds; first line = 1000.1) (*).

Type

float

style

Style name used for this line.

Type

str

styleref

Reference to the Style object of this line (*).

Type

obj

actor

Actor field.

Type

str

margin_l

Left margin for this line.

Type

int

margin_r

Right margin for this line.

Type

int

margin_v

Vertical margin for this line.

Type

int

effect

Effect field.

Type

str

raw_text

Line raw text.

Type

str

text

Line stripped text (no tags).

Type

str

width

Line text width (*).

Type

float

height

Line text height (*).

Type

float

ascent

Line font ascent (*).

Type

float

descent

Line font descent (*).

Type

float

internal_leading

Line font internal lead (*).

Type

float

external_leading

Line font external lead (*).

Type

float

x

Line text position horizontal (depends on alignment) (*).

Type

float

y

Line text position vertical (depends on alignment) (*).

Type

float

left

Line text position left (*).

Type

float

center

Line text position center (*).

Type

float

right

Line text position right (*).

Type

float

top

Line text position top (*).

Type

float

middle

Line text position middle (*).

Type

float

bottom

Line text position bottom (*).

Type

float

words

List containing objects Word in this line (*).

Type

list

syls

List containing objects Syllable in this line (if available) (*).

Type

list

chars

List containing objects Char in this line (*).

Type

list

copy()[source]
Returns

A deep copy of this object (line)

class pyonfx.ass_core.Ass(path_input='', path_output='Output.ass', keep_original=True, extended=True, vertical_kanji=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.

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

Example

io = Ass("in.ass")
meta, styles, lines = io.get_data()
get_data()[source]

Utility function to retrieve easily meta styles and lines.

Returns

meta, styles and lines

write_line(line)[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=False)[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()[source]

Open the output (specified in self.path_output) with Aegisub.

This can be usefull if you don’t have MPV installed or you want to look at your output in detailed.

Returns

0 if success, -1 if the output couldn’t be opened.

open_mpv(video_path='', video_start='', full_screen=False)[source]

Open the output (specified in self.path_output) in softsub with the MPV player. To utilize this function, MPV player is required. Additionally if you’re on Windows, MPV must be in the PATH (check https://pyonfx.readthedocs.io/en/latest/quick%20start.html#installation-extra-step).

This is one of the fastest way to reproduce your output in a comfortable way.

Parameters
  • video_path (string) – The video file path (absolute) to reproduce. If not specified, meta.video is automatically taken.

  • video_start (string) – The start time for the video (more info: https://mpv.io/manual/master/#options-start). If not specified, 0 is automatically taken.

  • full_screen (bool) – If True, it will reproduce the output in full screen. If not specified, False is automatically taken.