-
Notifications
You must be signed in to change notification settings - Fork 41
/
03_4_adjust-chapters.py
44 lines (32 loc) · 1.05 KB
/
03_4_adjust-chapters.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import os
import sys
import xml.etree.ElementTree as et
def main():
os.chdir(sys.argv[1])
tree = et.parse("project.xml")
movie = tree.getroot()
duration = int( movie.attrib["frames"] )
start_frame = int( movie.attrib["start_frame"] )
end_frame = int( movie.attrib["end_frame"] )
f = open("chapters.txt~", "r")
chapters = [int(frame) for frame in f if frame]
f.close()
chapters = [ch for ch in chapters if ch < end_frame and ch > start_frame] # get rid of things that are outside of the bounds
chapters = [start_frame] + chapters
#chapters[0] = start_frame # in case we removed some credits from the beginning
chapters.append(end_frame) # so that we know how long the last chapter is
dur_counter = 0
for i in range( len(chapters) - 1 ):
dur_counter += chapters[i+1] - chapters[i]
print duration
print dur_counter
f_out = open("chapters.txt", "w")
for ch in chapters:
f_out.write("%d\n" % (ch))
f_out.close()
return
# #########################
if __name__ == "__main__":
main()
# #########################