Skip to content

Instantly share code, notes, and snippets.

@Deflated-Criossant
Forked from adammw/tt2srt.py
Created December 10, 2015 12:15
Show Gist options
  • Select an option

  • Save Deflated-Criossant/6340bedb6524e8ec3791 to your computer and use it in GitHub Desktop.

Select an option

Save Deflated-Criossant/6340bedb6524e8ec3791 to your computer and use it in GitHub Desktop.

Revisions

  1. @adammw adammw created this gist Apr 12, 2011.
    19 changes: 19 additions & 0 deletions tt2srt.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # 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