Created
April 3, 2014 20:51
-
-
Save rlander/9962650 to your computer and use it in GitHub Desktop.
Script to reencode iso-8859-1subtitles to UTF-8r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, getopt | |
import codecs | |
BLOCKSIZE = 1048576 | |
def main(argv): | |
inputfile = '' | |
outputfile = '' | |
try: | |
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="]) | |
except getopt.GetoptError: | |
print 'test.py -i <inputfile> -o <outputfile>' | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print 'reencode.py -i <inputfile> -o <outputfile>' | |
sys.exit() | |
elif opt in ("-i", "--ifile"): | |
inputfile = arg | |
elif opt in ("-o", "--ofile"): | |
outputfile = arg | |
with codecs.open(inputfile, 'r', "iso-8859-1") as sourceFile: | |
with codecs.open(outputfile, "w", "utf-8") as targetFile: | |
while True: | |
contents = sourceFile.read(BLOCKSIZE) | |
if not contents: | |
break | |
targetFile.write(contents) | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment