-
-
Save Deflated-Criossant/6340bedb6524e8ec3791 to your computer and use it in GitHub Desktop.
Timed Text Captions to SRT Subtitles converter script
This file contains hidden or 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
| # Usage: python tt2srt.py source.xml output.srt | |
| from xml.dom.minidom import parse | |
| import sys | |
| i=1 | |
| dom = parse(sys.argv[1]) | |
| out = open(sys.argv[2], 'w') | |
| body = dom.getElementsByTagName("body")[0] | |
| paras = body.getElementsByTagName("p") | |
| for para in paras: | |
| out.write(str(i) + "\n") | |
| out.write(para.attributes['begin'].value.replace('.',',') + ' --> ' + para.attributes['end'].value.replace('.',',') + "\n") | |
| for child in para.childNodes: | |
| if child.nodeName == 'br': | |
| out.write("\n") | |
| elif child.nodeName == '#text': | |
| out.write(unicode(child.data).encode('utf=8')) | |
| out.write("\n\n") | |
| i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment