Skip to content

Instantly share code, notes, and snippets.

@mh-firouzjah
Last active May 30, 2021 06:55
Show Gist options
  • Save mh-firouzjah/9523507bf24f3410d591266b9992e56c to your computer and use it in GitHub Desktop.
Save mh-firouzjah/9523507bf24f3410d591266b9992e56c to your computer and use it in GitHub Desktop.
convert subtitle(.srt) files encoding form `windows 1256(arbic)` to `utf-8`.

Subtitle Decoder/Encoder

Subtitles are often not displayed properly on players due to incorrect encoding/decoding.

this python script is able to recive a path to subtitle/*.str files and change encoding form arabic/windows-1256 to utf-8.

'''
convert all subtile (*.srt) files inside given directory
from encoding `windows 1256` to `utf-8`
'''

import os

for filename in os.listdir(input("Enter file(s) directory: ")):
    if filename.endswith('.srt'):
        with open(filename, mode='r', encoding='windows-1256') as target:
            text = target.read()
            with open(filename, mode='w', encoding='utf-8') as dest:
                dest.write(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment