pyasstosrt – this tool will help you convert Advanced SubStation Alpha (ASS/SSA) subtitle files to SubRip (SRT) files.
Support for str path:
from pyasstosrt import Subtitle
sub = Subtitle('sub.ass')
sub.export()Support for all Path-like objects, instead of only pathlib's Path:
from pathlib import Path
from pyasstosrt import Subtitle
path = Path('sub.ass')
sub = Subtitle(path)
sub.export()You can get a sheet with dialogue by specifying output_dialogues.
from pathlib import Path
from pyasstosrt import Subtitle
path = Path('sub.ass')
sub = Subtitle(path)
sub.export(output_dialogues=True)If you want to remove effects from text, you can use the removing_effects.
from pyasstosrt import Subtitle
sub = Subtitle('sub.ass', removing_effects=True)
sub.export()You can enable the deletion of duplicate lines with the rearrangement of start and end times.
from pyasstosrt import Subtitle
sub = Subtitle('sub.ass', remove_duplicates=True)
sub.export()You can get a list of all styles in the file and filter subtitles by style names.
from pyasstosrt import Subtitle
# Get list of all styles in the file
sub = Subtitle('sub.ass')
styles = sub.get_styles()
print(styles) # ['Default', 'Alt', 'Signs', 'Credits']
# Export only styles with "Default" in name (e.g., Default, Default_dvd)
sub = Subtitle('sub.ass', only_default_style=True)
sub.export()
# Export only Default style
sub = Subtitle('sub.ass', include_styles=['Default'])
sub.export()
# Export only Default and Alt styles
sub = Subtitle('sub.ass', include_styles=['Default', 'Alt'])
sub.export()
# Exclude Signs and Credits styles
sub = Subtitle('sub.ass', exclude_styles=['Signs', 'Credits'])
sub.export()Convert ASS/SSA subtitle files to SRT format with various options.
Basic usage:
pyasstosrt export subtitle.assSpecify output directory:
pyasstosrt export subtitle.ass --output-dir /path/to/output
# or use short form
pyasstosrt export subtitle.ass -o /path/to/outputRemove effects and duplicates:
pyasstosrt export subtitle.ass --remove-effects --remove-duplicates
# or use short form
pyasstosrt export subtitle.ass -r -dProcess multiple files at once:
pyasstosrt export subtitle1.ass subtitle2.ass subtitle3.assStyle filtering options:
# Export only styles with "Default" in name (e.g., Default, Default_dvd)
pyasstosrt export subtitle.ass --only-default
# Export only specific styles
pyasstosrt export subtitle.ass --include-styles "Default,Signs"
# Exclude specific styles
pyasstosrt export subtitle.ass --exclude-styles "Signs,Credits"Custom encoding:
pyasstosrt export subtitle.ass --encoding utf-16Print dialogues to console:
pyasstosrt export subtitle.ass --output-dialoguesList all unique styles found in an ASS subtitle file.
Basic usage:
pyasstosrt styles subtitle.assDisplay in table format:
pyasstosrt styles subtitle.ass --table
# or use short form
pyasstosrt styles subtitle.ass -tShow version:
pyasstosrt --version
# or
pyasstosrt -vShow help:
pyasstosrt --help
pyasstosrt export --help
pyasstosrt styles --helpEnable shell completion:
# For bash
pyasstosrt --install-completion bash
# For zsh
pyasstosrt --install-completion zsh
# For fish
pyasstosrt --install-completion fishMost users will want to simply install the latest version, hosted on PyPI:
$ pip install 'pyasstosrt[cli]'
If you just want to use it as a library and don't need the CLI, you can omit the [cli] extra.