Skip to content

GitBib/pyasstosrt

Repository files navigation

pyasstosrt

Downloads codecov

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()

CLI

🎬 Export Command

Convert ASS/SSA subtitle files to SRT format with various options.

Basic usage:

pyasstosrt export subtitle.ass

Specify output directory:

pyasstosrt export subtitle.ass --output-dir /path/to/output
# or use short form
pyasstosrt export subtitle.ass -o /path/to/output

Remove effects and duplicates:

pyasstosrt export subtitle.ass --remove-effects --remove-duplicates
# or use short form
pyasstosrt export subtitle.ass -r -d

Process multiple files at once:

pyasstosrt export subtitle1.ass subtitle2.ass subtitle3.ass

Style 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-16

Print dialogues to console:

pyasstosrt export subtitle.ass --output-dialogues

🎨 Styles Command

List all unique styles found in an ASS subtitle file.

Basic usage:

pyasstosrt styles subtitle.ass

Display in table format:

pyasstosrt styles subtitle.ass --table
# or use short form
pyasstosrt styles subtitle.ass -t

🔧 General Options

Show version:

pyasstosrt --version
# or
pyasstosrt -v

Show help:

pyasstosrt --help
pyasstosrt export --help
pyasstosrt styles --help

Enable shell completion:

# For bash
pyasstosrt --install-completion bash

# For zsh
pyasstosrt --install-completion zsh

# For fish
pyasstosrt --install-completion fish

Installation

Most 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.

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages