pyasstosrt¶
Welcome to the pyasstosrt documentation! Here you will find information about the core functionality and examples of how to use the library.
Overview¶
pyasstosrt is a Python library for converting Advanced SubStation Alpha (ASS/SSA) subtitle files to SubRip (SRT) format. It provides a simple and efficient way to transform subtitle files between these formats.
Main Features¶
Convert ASS/SSA subtitles to SRT format
Style filtering: Export only specific subtitle styles
Remove effects from subtitle text (optional)
Remove and merge consecutive duplicate dialogues (optional)
List available styles in ASS files
Support for both string paths and Path-like objects
Command-line interface (CLI) for easy usage
Installation¶
To install pyasstosrt from PyPI, use the following command:
$ pip install 'pyasstosrt[cli]'
If you don’t need the CLI functionality, you can install the library without extras:
$ pip install pyasstosrt
For development purposes, you can clone the repository and install it in editable mode:
$ git clone https://github.com/GitBib/pyasstosrt.git
$ cd pyasstosrt
$ pip install -e .
You can also run pyasstosrt without installation using uvx:
$ uvx --from 'pyasstosrt[cli]' pyasstosrt export * --remove-effects --remove-duplicates
Quick Start¶
Here’s a basic example of how to use pyasstosrt:
from pyasstosrt import Subtitle
# Convert a single file
sub = Subtitle('subtitle.ass')
sub.export()
# Convert with effects removal
sub = Subtitle('subtitle.ass', removing_effects=True)
sub.export()
# Convert with duplicate removal
sub = Subtitle('subtitle.ass', remove_duplicates=True)
sub.export()
# Convert with custom output directory and encoding
sub = Subtitle('subtitle.ass')
sub.export(output_dir='output', encoding='utf-8')
# Export only default dialogue styles
sub = Subtitle('subtitle.ass', only_default_style=True)
sub.export()
# Export specific styles
sub = Subtitle('subtitle.ass', include_styles=['Default', 'Alt'])
sub.export()
# List available styles
sub = Subtitle('subtitle.ass')
styles = sub.get_styles()
print(styles) # ['Default', 'Signs', 'Credits', ...]
Command Line Interface¶
The library provides a command-line interface for easy usage:
# Convert a single file
pyasstosrt export subtitle.ass
# Convert multiple files
pyasstosrt export file1.ass file2.ass
# Convert with effects removal
pyasstosrt export subtitle.ass --remove-effects
# Convert with duplicate removal
pyasstosrt export subtitle.ass --remove-duplicates
# Convert with custom output directory
pyasstosrt export subtitle.ass --output-dir ./output
# Convert with custom encoding
pyasstosrt export subtitle.ass --encoding utf-8
# Print dialogues to console
pyasstosrt export subtitle.ass --output-dialogues
# List available styles
pyasstosrt styles subtitle.ass
# Export only default dialogue styles
pyasstosrt export subtitle.ass --only-default
# Export specific styles
pyasstosrt export subtitle.ass --include-styles "Default,Alt"
# Exclude specific styles
pyasstosrt export subtitle.ass --exclude-styles "Signs,Credits"
# Run without installation using uvx
uvx --from 'pyasstosrt[cli]' pyasstosrt export * --remove-effects --remove-duplicates
For more details on the CLI, see the CLI documentation.
Documentation¶
API Reference¶
API Reference