Last active
August 29, 2015 14:05
-
-
Save Luavis/1fcb88356efb2b14bd20 to your computer and use it in GitHub Desktop.
pid install pycaption
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from pycaption import SAMIReader, SRTWriter | |
import sys | |
import os | |
from chardet.universaldetector import UniversalDetector | |
def main(): | |
if len(sys.argv) < 1: | |
print("./smi_srt.py [smi file name].smi") | |
else: | |
sub_path = sys.argv[1] | |
u = UniversalDetector() | |
sami = open(sub_path, 'rb').read() | |
u.feed(sami) | |
u.close() | |
encoding_name = u.result['encoding'].lower() | |
sami_content = "" | |
if not encoding_name == 'utf-8': | |
uni_sami = unicode(sami, encoding_name) | |
sami_content = uni_sami.encode('utf8') | |
else: | |
sami_content = str(sami) | |
pycaps = SAMIReader().read(sami_content) | |
srt_content = SRTWriter().write(pycaps) | |
new_path = os.path.splitext(sub_path)[0] + '.srt' | |
open(new_path, 'w+').write(srt_content) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment