Skip to main content

ASS subtitle Simplified/Traditional Chinese conversion tool

Project description

ass-hanvert

Simple ASS subtitle Simplified/Traditional Chinese conversion tool

About

Motivation

Popular conversion tools like Fanhuaji have decent accuracy and can detect subtitle formats for smart conversion, but they fail with karaoke-tagged subtitles. For example, 苹{\k}果 is incorrectly converted to 苹{\k}果 instead of the correct 蘋{\k}果.

OpenCC, on the other hand, doesn't recognize subtitle formats, causing unwanted conversions (e.g., to fonts or Japanese text).

This project aims to solve these problems by implementing ASS subtitle conversion in Python, supporting multiple converters with good extensibility.

Features

  1. Skip Japanese subtitles (identified by style name, \r not yet supported)
  2. Skip non-Chinese text
  3. Ignore tags and line breaks during conversion, then restore original formatting
  4. Display a warning if length changes before and after conversion
  5. Multiple built-in converters (see list below)
  6. Conversion result caching to reduce duplicate work

Installation

pip install ass-hanvert

Usage

CLI

# Basic usage - convert a single file (default: S2T, Fanhuaji Taiwan)
ass-hanvert input.ass

# Specify converter
ass-hanvert -c OpenCC-TW input.ass

# T2S conversion
ass-hanvert -c OpenCC-S input.ass

# Batch process multiple files
ass-hanvert *.ass

# Use cache directory (speeds up repeated conversions)
ass-hanvert --cache ./cache input.ass

# Custom output file suffix
ass-hanvert --suffix traditional input.ass

# Full example: specify converter, reference converter, font mapping, and cache
ass-hanvert -c FHJ-TW --ref-converter OpenCC-S --font-mapping fonts.json --cache ./cache input.ass

Parameters:

Parameter Description Default
files ASS subtitle file(s) to convert (supports multiple files and globs) Required
-c, --converter Converter name, see list below FHJ-TW
--ref-converter Reference converter, auto-selected based on main converter direction if omitted Auto
--suffix Output file suffix inserted before .ass cht (S2T) / chs (T2S)
--cache Cache directory path None
--no-skip-comment Do not skip comment lines Skip
--no-deduplicate Do not deduplicate Deduplicate
--no-sort Do not sort events Sort by start time
--font-mapping Font mapping JSON file path None
--pre-replace Pre-replace rules JSON file path None
--post-replace Post-replace rules JSON file path None
--protected-patterns Protected patterns JSON file path (list of regexes) None

Built-in converters:

Simplified to Traditional:

Name Description
FHJ-T Fanhuaji - Traditional
FHJ-HK Fanhuaji - Hong Kong
FHJ-TW Fanhuaji - Taiwan
FHJ-WT Fanhuaji - Wiki Traditional
OpenCC-T OpenCC - Traditional
OpenCC-HK OpenCC - Hong Kong
OpenCC-TW OpenCC - Taiwan
OpenCC-TWP OpenCC - Taiwan (with Taiwan-specific idioms)

Traditional to Simplified:

Name Description
FHJ-S Fanhuaji - Simplified
OpenCC-S OpenCC - Simplified
OpenCC-HKS OpenCC - Hong Kong to Simplified
OpenCC-TWS OpenCC - Taiwan to Simplified

Python API

from light_ass import Document
from ass_hanvert import convert_ass

# Load subtitle
doc = Document.load("input.ass")

# Convert (default: Fanhuaji Taiwan)
convert_ass(doc)

# Or specify a converter (S2T)
from ass_hanvert import OpenCCConverter

convert_ass(doc, converter=OpenCCConverter.Taiwan)

# T2S
convert_ass(doc, converter=OpenCCConverter.Simplified)

# Save
doc.save("output.cht.ass")

Credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ass_hanvert-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ass_hanvert-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file ass_hanvert-0.1.0.tar.gz.

File metadata

  • Download URL: ass_hanvert-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ass_hanvert-0.1.0.tar.gz
Algorithm Hash digest
SHA256 740c116e0b59456021615a517ced625e713479990b3352c156dd4448287d4bd8
MD5 40f1b0de3f4b3ce4df1e87bc5f5aab49
BLAKE2b-256 3c2254a35b8ad66c5b7700038d59a43cc761c08f1d28369420b8325e27f49fb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ass_hanvert-0.1.0.tar.gz:

Publisher: python-publish.yml on oborozuk1/ass-hanvert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ass_hanvert-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ass_hanvert-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ass_hanvert-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2a150befc911fc33349759557a707ef1c539b7f4c168ac75315bed06d5bc5c
MD5 f0433c36eee3da412e1db7445d3ec2e4
BLAKE2b-256 72ff2fb5a426373f51f01c464865b042d34fbc1271b7ee71e0a3d0fb5e748b84

See more details on using hashes here.

Provenance

The following attestation bundles were made for ass_hanvert-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on oborozuk1/ass-hanvert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page