forked from kieranjol/IFIscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcpsubs2srt.py
executable file
·29 lines (23 loc) · 1013 Bytes
/
dcpsubs2srt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
from lxml import etree
filename = sys.argv[1]
srt_file = filename +'.srt'
dcp_subtitle = etree.parse(filename)
total_subtitles = int(dcp_subtitle.xpath('count(//Subtitle)'))
counter = 0
with open(srt_file, "w") as myfile:
print srt_file,' created'
while counter < total_subtitles:
xpath_counter = counter + 1
in_point = dcp_subtitle.xpath('//Subtitle')[counter].attrib['TimeIn']
out_point = dcp_subtitle.xpath('//Subtitle')[counter].attrib['TimeOut']
in_point = in_point[:8] + '.' + in_point[9:]
out_point = out_point[:8] + '.' + out_point[9:]
with open(srt_file, "a") as myfile:
myfile.write(str(counter + 1) + '\n')
myfile.write(in_point + ' --> ' + out_point + '\n')
subtitle_text = [subtitle_text.text for subtitle_text in dcp_subtitle.iterfind('.//Subtitle[%s]/Text' % int(xpath_counter) ) ]
for i in subtitle_text:
myfile.write(i + '\n')
myfile.write('\n')
counter +=1