Traslate a .SRT file using any with custom translator
Project description
SRTranslator
Install
pip install srttranslator-bariskeser
Usage from script
Import stuff
import os
# SRT File
from srtranslator import SrtFile
# ASS File
from srtranslator import AssFile
from srtranslator.translators.deepl_api import DeeplApi
from srtranslator.translators.deepl_scrap import DeeplTranslator
from srtranslator.translators.translatepy import TranslatePy
from srtranslator.translators.pydeeplx import PyDeepLX
Initialize translator. It can be any translator, even your own, check the docs, there are instructions per translator and how to create your own.
translator = DeeplTranslator() # or TranslatePy() or DeeplApi(api_key) or DeepLX()
Load, translate and save. For multiple recursive files in folder, check examples folder
filepath = "./filepath/to/srt"
# SRT File
sub = SrtFile(filepath)
# ASS File
sub = AssFile(filepath)
# Translate
sub.translate(translator, "en", "es")
# Making the result subtitles prettier
sub.wrap_lines()
sub.save(f"{os.path.splitext(filepath)[0]}_translated.srt")
Quit translator
translator.quit()
# SRT file
python -m srtranslator ./filepath/to/srt -i SRC_LANG -o DEST_LANG
# ASS file
python -m srtranslator ./filepath/to/ass -i SRC_LANG -o DEST_LANG
Advanced usage
usage: __main__.py [-h] [-i SRC_LANG] [-o DEST_LANG] [-v] [-vv] [-s] [-w WRAP_LIMIT] [-t {deepl-scrap,translatepy,deepl-api,pydeeplx}] [--auth AUTH] path
Translate an .STR and .ASS file
positional arguments:
path File to translate
options:
-h, --help show this help message and exit
-i SRC_LANG, --src-lang SRC_LANG
Source language. Default: auto
-o DEST_LANG, --dest-lang DEST_LANG
Destination language. Default: es (spanish)
-v, --verbose Increase output verbosity
-vv, --debug Increase output verbosity for debugging
-s, --show-browser Show browser window
-w WRAP_LIMIT, --wrap-limit WRAP_LIMIT
Number of characters -including spaces- to wrap a line of text. Default: 50
-t {deepl-scrap,translatepy,deepl-api}, --translator {deepl-scrap,translatepy,deepl-api,pydeeplx}
Built-in translator to use
--auth AUTH Api key if needed on translator
--proxies Use proxy by default for pydeeplx
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 srtranslator_bariskeser-0.0.1.tar.gz.
File metadata
- Download URL: srtranslator_bariskeser-0.0.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84060f02054459df8efc96e12b2f1d403f4e8fb82835a0d1caa5afaa2e2d5e9c
|
|
| MD5 |
148e3813bc1bec0bece698f76516b439
|
|
| BLAKE2b-256 |
4cdcffe4786df4196f2497ec2a6540949e932fe9206e59eee5d673210622b3af
|
File details
Details for the file srtranslator_bariskeser-0.0.1-py3-none-any.whl.
File metadata
- Download URL: srtranslator_bariskeser-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afeb86966f40c0cf223419fb3b6d1423c5799a32d0d45a1e588dd30bf2f43ea7
|
|
| MD5 |
7afca1f61aefe087d190cc9c37045c05
|
|
| BLAKE2b-256 |
46dd1c9d90d5fb27d0adfb474ec0e50d36b77f50271a0a023cf7c87988eeb4e9
|