-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXML_EXPORT.py
140 lines (103 loc) · 4.09 KB
/
XML_EXPORT.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import copy
import lxml.etree as etree
import uuid
class NOFI_XML():
# INSERTAR DATA PRESETEADA SECUENCIA
def __init__(self, base_xml=r"F:\DESARROLLO\VFX\NLE_OUTPUT\XML_TEMPLATES\XML.xml",
base_seq=r"F:\DESARROLLO\VFX\NLE_OUTPUT\XML_TEMPLATES\SEQ.xml",
nombre="NOFI_MID_EXPERIMENTAL",
lista_de_cortes=None
):
# CARGAR XML BASE
self.xml = etree.parse(base_xml)
self.uuid = uuid.uuid4()
self.nombre = nombre
self.carpeta_exports = "EXPORTS/"
self.archivo = self.carpeta_exports + self.nombre + ".xml"
# CARGAR TEMPLATE CLIP ITEMs
clip_item_template_1 = r"F:\DESARROLLO\VFX\NLE_OUTPUT\XML_TEMPLATES\CLIP_ITEM_1.xml"
clip_item_template_1 = etree.parse(clip_item_template_1)
clip_item_template_2 = r"F:\DESARROLLO\VFX\NLE_OUTPUT\XML_TEMPLATES\CLIP_ITEM_2.xml"
clip_item_template_2 = etree.parse(clip_item_template_2)
self.clip_item_templates = [clip_item_template_1, clip_item_template_2]
self.crear_lista_clips(lista_de_cortes=lista_de_cortes)
# CREAR SEQ
self.seq = etree.parse(base_seq)
self.crear_secuencia(self.seq.getroot())
def crear_lista_clips(self, lista_de_cortes=None):
self.clip_items = []
if lista_de_cortes==None:
lista_de_cortes = []
tiempo = 0
img = True
for x in range(0, 10):
# lista_de_cortes=[(tiempo, img)]
lista_de_cortes.append((tiempo, img))
tiempo += 25
img = not img
for n, item in enumerate(lista_de_cortes):
tiempo = item[0]
start = str(tiempo)
img = int(item[1])
# print("img")
# print(img)
# print(lista_de_corte[n + 1])
try:
end = str(lista_de_cortes[n+1][0])
except:
end = str(int(tiempo) + 25)
#print(start,end)
item = self.crear_clip_item(self.clip_item_templates[img], n+1, start, end)
# etree.dump(item)
self.clip_items.append(item)
return
def obtener_duracion(self):
pass
def crear_secuencia(self, seq):
#LLENAR UUID
seq.find('uuid').text = str(self.uuid)
# NOMBRE DE SEQ
seq.find('name').text = str(self.nombre)
# CLIP ITEMS
media = seq.find('media')
video = media.find('video')
track = video.find('track')
for n, item in enumerate(self.clip_items):
track.insert(n, item)
# INSERTAR SECUENCIA EN XML
xml = self.xml.getroot()
xml.insert(0, seq)
#self.seq = etree.parse(seq)
# etree.dump(video)
#INSERTAR CLIP_ITEM EN SEQ
# DURACIÓN
# CLIP ITEMS (Y LISTA DE CORTES VIDEO + AUDIO)
def crear_clip_item(self, clip_item_template, id=1, start=0, end=400):
#print(id, start, end)
nuevo_item = copy.deepcopy(clip_item_template.getroot())
#TODO: id="clipitem-x", <masterclipid>, <name>
item_id = 'masterclip-' + str(id)
nuevo_item.set('id', item_id)
#append <start> y <end>
nuevo_item.find('start').text = str(start)
nuevo_item.find('end').text = str(end)
#etree.dump(nuevo_item)
# nombre = nuevo_item.xpath('in/text()')
# print(nombre)
return nuevo_item
pass
# EXPORTAR ARCHIVO .xml
def exportar_xml(self, archivo = ''):
with open(archivo, 'wb') as arch:
self.xml.write(arch)
def _test(self):
test = self.xml.getroot()
nombre = test.xpath('sequence/name/text()')
#nombre = test.find('sequence/name')
# print(nombre)
#self.crear_clip_item(self.clip_item_templates[0])
# etree.dump(nombre)
if __name__ == "__main__":
nofi_xml = NOFI_XML()
#nofi_xml._test()
nofi_xml.exportar_xml()