sub
DEFAULT_DIALOGUE_STYLES = ['default', 'main', 'alt', 'overlap', 'flashback', 'top', 'italics']
module-attribute
LINES = list[_Line]
module-attribute
SRT_REGEX = '\\d+[\\r\\n](?:(?P<start>\\d+:\\d+:\\d+,\\d+) --> (?P<end>\\d+:\\d+:\\d+,\\d+))[\\r\\n](?P<text>(?:.+\\r?\\n)+(?=(\\r?\\n)?))'
module-attribute
SubFileSelf = TypeVar('SubFileSelf', bound=SubFile)
module-attribute
__all__ = ['FontFile', 'SubFile', 'DEFAULT_DIALOGUE_STYLES']
module-attribute
FontFile
dataclass
SubFile
dataclass
Bases: BaseSubFile
Utility class representing a subtitle file with various functions to run on.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
PathLike | list[PathLike] | GlobSearch
|
Can be a string, Path object or GlobSearch. If the GlobSearch returns multiple results or if a list was passed it will merge them. |
required |
container_delay
|
int
|
Set a container delay used in the muxing process later. |
0
|
source
|
PathLike | None
|
The file this sub originates from, will be set by the constructor. |
None
|
encoding
|
Encoding used for reading and writing the subtitle files. |
required |
Source code in muxtools/subtitle/sub.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
|
encoding = 'utf_8_sig'
class-attribute
instance-attribute
__init__(file, container_delay=0, source=None, tags=None)
__post_init__()
Source code in muxtools/subtitle/sub.py
autoswapper(allowed_styles=DEFAULT_DIALOGUE_STYLES, print_swaps=False, inline_marker='*', line_marker='***')
autoswapper does the swapping. Too lazy to explain
Parameters:
Name | Type | Description | Default |
---|---|---|---|
allowed_styles
|
list[str] | None
|
List of allowed styles to do the swapping on Will run on every line if passed |
DEFAULT_DIALOGUE_STYLES
|
print_swaps
|
bool
|
Prints the swaps |
False
|
inline_marker
|
str
|
Marker to use for inline swaps. Should be one character. Default |
'*'
|
line_marker
|
str
|
Marker to use for full-line swaps. Default |
'***'
|
Returns:
Type | Description |
---|---|
SubFileSelf
|
This SubTrack |
Source code in muxtools/subtitle/sub.py
change_layers(styles=DEFAULT_DIALOGUE_STYLES, layer=None, additive=True)
Set layer to the specified number or adds the number to the existing one on every line with a style you selected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styles
|
list[str]
|
List of styles to look for. |
DEFAULT_DIALOGUE_STYLES
|
layer
|
int | None
|
The layer you want. Defaults to 50 for additive and 99 otherwise. |
None
|
additive
|
bool
|
Add specified layer number instead of replacing the existing one. |
True
|
Source code in muxtools/subtitle/sub.py
clean_comments()
Removes all comment lines from the file.
clean_extradata()
Removes the "Aegisub Extradata" section from the file.
clean_garbage()
Removes the "Aegisub Project Garbage" section from the file.
clean_styles()
Deletes unused styles from the document.
Source code in muxtools/subtitle/sub.py
collect_fonts(use_system_fonts=True, search_current_dir=True, additional_fonts=[], collect_draw_fonts=True, error_missing=False, use_ntfs_compliant_names=None)
Collects fonts for current subtitle. Note that this places all fonts into the workdir for the episode/Setup and all fonts in it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_system_fonts
|
bool
|
Parses and checks against all installed fonts |
True
|
search_current_dir
|
bool
|
Recursively checks the current work directory for fonts |
True
|
additional_fonts
|
list[PathLike]
|
Can be a directory or a path to a file directly (or a list of either) |
[]
|
collect_draw_fonts
|
bool
|
Whether or not to include fonts used for drawing (usually Arial) See https://github.com/libass/libass/issues/617 for details. |
True
|
error_missing
|
bool
|
Raise an error instead of just warnings when a font is missing. |
False
|
use_ntfs_compliant_names
|
bool | None
|
Ensure that filenames will work on a NTFS (Windows) filesystem. The |
None
|
Returns:
Type | Description |
---|---|
list[FontFile]
|
A list of FontFile objects |
Source code in muxtools/subtitle/sub.py
copy()
Creates a new copy of the current SubFile object, including its file. So you can run anything on the new one without impacting the other one.
Source code in muxtools/subtitle/sub.py
from_mkv(file, track=0, preserve_delay=False, quiet=True, **kwargs)
classmethod
Extract subtitle from mkv.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
PathLike
|
Input mkv file |
required |
track
|
int
|
Relative track number |
0
|
preserve_delay
|
bool
|
Preserve existing container delay |
False
|
kwargs
|
Any
|
Other args to pass to |
{}
|
Source code in muxtools/subtitle/sub.py
from_srt(file, an8_all_caps=True, style_all_caps=True, fps=Fraction(24000, 1001), encoding='UTF8')
classmethod
Convert srt subtitles to an ass SubFile. Automatically applies Gandhi styling. Feel free to restyle. Also worth noting that this creates a file that assumes 1920x1080. Use the resample function if you need something else.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
PathLike
|
Input srt file |
required |
an8_all_caps
|
bool
|
Automatically an8 every full caps line with over 7 characters because they're usually signs. |
True
|
style_all_caps
|
bool
|
Also set the style of these lines to "Sign" wether it exists or not. |
True
|
fps
|
Fraction | PathLike
|
FPS needed for the time conversion. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
encoding
|
str
|
Encoding used to read the file. Defaults to UTF8. |
'UTF8'
|
Source code in muxtools/subtitle/sub.py
manipulate_lines(func)
Function to manipulate any lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[[LINES], LINES | None]
|
Your own function you want to run on the list of lines. This can return a new list or just edit the one passed into it. |
required |
Source code in muxtools/subtitle/sub.py
merge(file, sync=None, sync2=None, fps=Fraction(24000, 1001), use_actor_field=False, no_error=False)
Merge another subtitle file with syncing if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
PathLike | GlobSearch
|
The file to be merged. |
required |
sync
|
None | int | str
|
Can be None to not adjust timing at all, an int for a frame number or a string for a syncpoint name. |
None
|
sync2
|
None | str
|
The syncpoint you want to use for the second file. This is needed if you specified a frame for sync and still want to use a specific syncpoint. |
None
|
fps
|
Fraction | PathLike
|
The fps used for time calculations. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
use_actor_field
|
bool
|
Checks the actor field instead of effect for the names if True. |
False
|
no_error
|
bool
|
Don't error and warn instead if syncpoint not found. |
False
|
Source code in muxtools/subtitle/sub.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
purge_macrons(styles=DEFAULT_DIALOGUE_STYLES)
Removes romaji macrons from every dialogue line. German subs use this a lot and a lot of fonts don't support it, so I like to purge them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styles
|
list[str] | None
|
List of styles to look for |
DEFAULT_DIALOGUE_STYLES
|
Source code in muxtools/subtitle/sub.py
resample(video=None, src_width=None, src_height=None, use_arch=None, quiet=True)
Resample subtitles to match the resolution of the specified video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
video
|
PathLike | None
|
Path to a video. Will resort to a 1080p dummy video if None. |
None
|
src_width
|
int | None
|
The width of the resolution the subs are currently at |
None
|
src_height
|
int | None
|
The height of the resolution the subs are currently at Both of the above params will be taken from the sub file if not given. (Assuming 640 x 360 if nothing is given in the document) |
None
|
use_arch
|
bool | None
|
Uses arch1t3cht's perspective resampler script to fix any perspective stuff after resampling. This requires arch.Resample.moon in either of your autoload folders. None means it will use it if it can find the script. True will try to force it. |
None
|
Source code in muxtools/subtitle/sub.py
restyle(styles, clean_after=True, delete_existing=False, adjust_styles=True)
Add (and replace existing) styles to the subtitle file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styles
|
Style | list[Style]
|
Either a single or a list of ass Styles |
required |
clean_after
|
bool
|
Clean unused styles after |
True
|
delete_existing
|
bool
|
Delete all existing styles before adding new ones |
False
|
adjust_styles
|
bool
|
Resize the styles to match the script resolution. This assumes 1080p for the actual style res as all the presets are that. |
True
|
Source code in muxtools/subtitle/sub.py
separate_signs(styles=DEFAULT_DIALOGUE_STYLES, inverse=False, heuristics=False, print_heuristics=True)
Basically deletes lines that have any of the passed styles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styles
|
list[str]
|
List of style names to get rid of |
DEFAULT_DIALOGUE_STYLES
|
inverse
|
bool
|
Treat the list as the opposite. Will remove lines that don't have any of those styles. |
False
|
heuristics
|
bool
|
Also use heuristics for detecting signs. |
False
|
Source code in muxtools/subtitle/sub.py
set_header(header, value)
A function to add headers to the "Script Info" section of the subtitle file.
This will validate the input for known functional headers but also allows arbitrary ones.
If you're planning on setting multiple at the same time, use the set_headers
function instead to avoid a lot of I/O.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header
|
str | ASSHeader
|
The name of the header or a header chosen from the enum. |
required |
value
|
str | int | bool | None
|
The value of the header. None will remove the header unless it's the Matrix header because None has a meaning there. |
required |
Source code in muxtools/subtitle/sub.py
set_headers(*headers)
A function to add headers to the "Script Info" section of the subtitle file. This will validate the input for known functional headers but also allows arbitrary ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers
|
tuple[str | ASSHeader, str | int | bool | None]
|
Any amount of tuples with the same typing as the single header function. |
()
|
Source code in muxtools/subtitle/sub.py
shift(frames, fps=Fraction(24000, 1001), delete_before_zero=False)
Shifts all lines by any frame number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames
|
int
|
Number of frames to shift by |
required |
fps
|
Fraction | PathLike
|
FPS needed for the timing calculations. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
delete_before_zero
|
bool
|
Delete lines that would be before 0 after shifting. |
False
|
Source code in muxtools/subtitle/sub.py
shift_0(fps=Fraction(24000, 1001), allowed_styles=DEFAULT_DIALOGUE_STYLES)
Does the famous shift by 0 frames to fix frame timing issues. (It's basically just converting time to frame and back)
This does not currently exactly reproduce the aegisub behaviour but it should have the same effect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fps
|
Fraction | PathLike
|
The fps fraction used for conversions. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
allowed_styles
|
list[str] | None
|
A list of style names this will run on. Will run on every line if None. |
DEFAULT_DIALOGUE_STYLES
|
Source code in muxtools/subtitle/sub.py
unfuck_cr(default_style='Default', keep_flashback=True, dialogue_styles=['main', 'default', 'narrator', 'narration'], top_styles=['top'], italics_styles=['italics', 'internal'], alt_style='Alt', alt_styles=None)
Removes any top and italics styles and replaces them with tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_style
|
str
|
The default style that everything will be set to |
'Default'
|
keep_flashback
|
bool
|
If not it will set the flashback styles to default_style |
True
|
dialogue_styles
|
list[str] | None
|
Styles that will be set to default_style |
['main', 'default', 'narrator', 'narration']
|
top_styles
|
list[str] | None
|
Styles that will be set to default_style and an8 added to tags |
['top']
|
italics_styles
|
list[str] | None
|
Styles that will be set to default_style and i1 added to tags |
['italics', 'internal']
|
alt_style
|
str
|
The default alt/overlap style that lines will be set to |
'Alt'
|
alt_styles
|
list[str] | None
|
Possible identifiers for styles that should be set to the alt_style |
None
|