Subtitles and captions are lines of dialogue or other text displayed at the bottom of the screen in films, television programs, video games or other visual media. They can be transcriptions of the screenplay, translations of it, or information to help viewers who are deaf or hard-of-hearing understand what is shown (wikipedia).
The Subtitle Fixer is a simple tool that helps you fix subtitles in Kurdish (ckb), Persian, and Arabic. If you have ever encountered issues (see below images) when watching a movie with its subtitles, you have come to the right place to find a solution.
Only implement these codes on subtitle files that have issues. If you are proficient in Python and Unicode, you can use the necessary encodings for your files.
- Clone the repo
- Make sure all your subtitles are in the same directory as the repo
- Create a new file with a
.py
extension (e.g.example.py
) and copy the provided code into it
# -*- coding: utf-8 -*-
# import essential modules
import io
import sys
from pathlib import Path
# solve encoding problems
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
# import subtitle_fixer module
from subtitle_fixer import Subtitle_Fixer
# get current directory
current_directory = Path(__file__).parent
# get all files in current directory
srt_files = current_directory.iterdir()
# make an instance of Subtitle_Fixer class
subt = Subtitle_Fixer()
# find subtitles based on their extensions
# and fix encoding of all subtitle files
fix = [
subt.fix_encoding(s)
for s in srt_files
if str(s.name).split(".")[-1] in subt.subtitle_extensions
]
-
Run the file using the command line The entire process is outlined in the
example.py
file and can be easily executed using the following command: -
Linux or Mac: python
./example.py
-
Windows:
python .\example.py
orpython .//example.py
Once you run the script, all subtitle files in the directory will be fixed and renamed, adding a_fixed
suffix to the file name.
Fixed file has been encoded to UTF-8
and you can set your subtitle settings in your player to UTF-8
.
This method does not automatically set the encoding type to UTF-8
and requires manual configuration of subtitle settings in the player.
Please feel free to report any bugs or issues to us, email to: 0xdolan@gmail.com or open issues on Github.
Licensed under the GPLv3 License.