Skip to content

Instantly share code, notes, and snippets.

@sash13
Created October 15, 2011 10:09
Show Gist options
  • Save sash13/1289363 to your computer and use it in GitHub Desktop.
Save sash13/1289363 to your computer and use it in GitHub Desktop.
Machine Learning local --> SRT
from xml.dom.minidom import parse
import os
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def startGr(slide,file_o):
getListOf(slide.getElementsByTagName("p"), file_o)
def getListOf(points, file_o):
i=1
f=open('video/10/'+file_o, 'w')
for point in points:
f.write(str(i)+'\n')
begin = point.getAttribute('begin').split(':')
dur = point.getAttribute('dur').split(':')
h=str( (int(begin[0])+int(dur[0])) if (int(begin[0])+int(dur[0]))>10 else '0'+str(int(begin[0])+int(dur[0])) )
m=str(int(begin[1])+int(dur[1])) if (int(begin[1])+int(dur[1]))>10 else '0'+str(int(begin[1])+int(dur[1]))
f.write(point.getAttribute('begin').split('.')[0]+','+ point.getAttribute('begin').split('.')[1]+' -->'+''.join(h+':'+m+':'+str(float(begin[2])+float(dur[2])).split('.')[0]+','+str(float(begin[2])+float(dur[2])).split('.')[1] ))
f.write(getText(point.childNodes)+'\n\n')
i+=1
listing = os.listdir('xml/')
for file_i in listing:
dom= parse('xml/'+file_i)
file_o=file_i.split('-subtitles.xml')[0]+'.srt'
startGr(dom, file_o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment