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
- Skip Japanese subtitles (identified by style name,
\rnot yet supported) - Skip non-Chinese text
- Ignore tags and line breaks during conversion, then restore original formatting
- Display a warning if length changes before and after conversion
- Multiple built-in converters (see list below)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
740c116e0b59456021615a517ced625e713479990b3352c156dd4448287d4bd8
|
|
| MD5 |
40f1b0de3f4b3ce4df1e87bc5f5aab49
|
|
| BLAKE2b-256 |
3c2254a35b8ad66c5b7700038d59a43cc761c08f1d28369420b8325e27f49fb8
|
Provenance
The following attestation bundles were made for ass_hanvert-0.1.0.tar.gz:
Publisher:
python-publish.yml on oborozuk1/ass-hanvert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ass_hanvert-0.1.0.tar.gz -
Subject digest:
740c116e0b59456021615a517ced625e713479990b3352c156dd4448287d4bd8 - Sigstore transparency entry: 2163405647
- Sigstore integration time:
-
Permalink:
oborozuk1/ass-hanvert@5a8d0668050bf233bc5a4df37cf80cd9ef5480a2 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/oborozuk1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5a8d0668050bf233bc5a4df37cf80cd9ef5480a2 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b2a150befc911fc33349759557a707ef1c539b7f4c168ac75315bed06d5bc5c
|
|
| MD5 |
f0433c36eee3da412e1db7445d3ec2e4
|
|
| BLAKE2b-256 |
72ff2fb5a426373f51f01c464865b042d34fbc1271b7ee71e0a3d0fb5e748b84
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ass_hanvert-0.1.0-py3-none-any.whl -
Subject digest:
9b2a150befc911fc33349759557a707ef1c539b7f4c168ac75315bed06d5bc5c - Sigstore transparency entry: 2163405670
- Sigstore integration time:
-
Permalink:
oborozuk1/ass-hanvert@5a8d0668050bf233bc5a4df37cf80cd9ef5480a2 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/oborozuk1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5a8d0668050bf233bc5a4df37cf80cd9ef5480a2 -
Trigger Event:
release
-
Statement type: