NickVerri commited on
Commit
f495376
·
verified ·
1 Parent(s): c50d3eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -90,6 +90,18 @@ def clean_json_response(text):
90
  except Exception:
91
  return text
92
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  def timecode_to_frames(tc, fps):
94
  """Converts HH:MM:SS:FF to absolute integer frames based on timebase."""
95
  if not tc or not re.match(r"\d{2}:\d{2}:\d{2}[:\.]\d{2}", tc):
@@ -173,7 +185,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
173
  lines.append('<!DOCTYPE xmeml>')
174
  lines.append('<xmeml version="4">')
175
  lines.append('<sequence>')
176
- lines.append(f'\t<name>{sequence_name}</name>')
177
  lines.append('\t<rate>')
178
  lines.append(f'\t\t<timebase>{timebase}</timebase>')
179
  lines.append(f'\t\t<ntsc>{is_ntsc}</ntsc>')
@@ -234,7 +246,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
234
  tl_end = tl_start + duration_frames
235
 
236
  lines.append(f'\t\t\t\t<clipitem id="clipitem-v-{i}">')
237
- lines.append(f'\t\t\t\t\t<name>{clip_name_disp}</name>')
238
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
239
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
240
  lines.append(f'\t\t\t\t\t<start>{tl_start}</start>')
@@ -247,8 +259,8 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
247
  if is_vo:
248
  if not vo_file_defined:
249
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
250
- lines.append(f'\t\t\t\t\t\t<name>{source_name_to_use}</name>')
251
- lines.append(f'\t\t\t\t\t\t<pathurl>file://localhost/{source_name_to_use}.wav</pathurl>')
252
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
253
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
254
  lines.append(f'\t\t\t\t\t\t<timecode>')
@@ -268,8 +280,8 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
268
  elif is_graphic:
269
  if not gfx_file_defined:
270
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
271
- lines.append(f'\t\t\t\t\t\t<name>{source_name_to_use}</name>')
272
- lines.append(f'\t\t\t\t\t\t<pathurl>file://localhost/{source_name_to_use}.mov</pathurl>')
273
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
274
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
275
  lines.append(f'\t\t\t\t\t\t<timecode>')
@@ -289,7 +301,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
289
  else:
290
  if not file_defined:
291
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
292
- lines.append(f'\t\t\t\t\t\t<name>{source_name_to_use}</name>')
293
  lines.append(f'\t\t\t\t\t\t<pathurl>{path_url}</pathurl>')
294
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
295
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
@@ -309,7 +321,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
309
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}"/>')
310
 
311
  lines.append('\t\t\t\t\t<marker>')
312
- lines.append(f'\t\t\t\t\t\t<name>{clip_note}</name>')
313
  lines.append(f'\t\t\t\t\t\t<in>{src_in_frames}</in>')
314
 
315
  # Extends the marker duration to span the entire clip for VO and Graphics
@@ -367,7 +379,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset_fram
367
  tl_end = tl_start + duration_frames
368
 
369
  lines.append(f'\t\t\t\t<clipitem id="clipitem-a-{i}">')
370
- lines.append(f'\t\t\t\t\t<name>{source_name_to_use}</name>')
371
  lines.append(f'\t\t\t\t\t<masterclipid>{master_id_to_use}</masterclipid>')
372
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
373
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
@@ -801,3 +813,4 @@ if uploaded_file:
801
 
802
 
803
 
 
 
90
  except Exception:
91
  return text
92
 
93
+ def escape_xml(text):
94
+ """Safely escapes special characters for XML to prevent DOM parser errors."""
95
+ if not text:
96
+ return ""
97
+ text = str(text)
98
+ text = text.replace("&", "&amp;")
99
+ text = text.replace("<", "&lt;")
100
+ text = text.replace(">", "&gt;")
101
+ text = text.replace('"', "&quot;")
102
+ text = text.replace("'", "&apos;")
103
+ return text
104
+
105
  def timecode_to_frames(tc, fps):
106
  """Converts HH:MM:SS:FF to absolute integer frames based on timebase."""
107
  if not tc or not re.match(r"\d{2}:\d{2}:\d{2}[:\.]\d{2}", tc):
 
185
  lines.append('<!DOCTYPE xmeml>')
186
  lines.append('<xmeml version="4">')
187
  lines.append('<sequence>')
188
+ lines.append(f'\t<name>{escape_xml(sequence_name)}</name>')
189
  lines.append('\t<rate>')
190
  lines.append(f'\t\t<timebase>{timebase}</timebase>')
191
  lines.append(f'\t\t<ntsc>{is_ntsc}</ntsc>')
 
246
  tl_end = tl_start + duration_frames
247
 
248
  lines.append(f'\t\t\t\t<clipitem id="clipitem-v-{i}">')
249
+ lines.append(f'\t\t\t\t\t<name>{escape_xml(clip_name_disp)}</name>')
250
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
251
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
252
  lines.append(f'\t\t\t\t\t<start>{tl_start}</start>')
 
259
  if is_vo:
260
  if not vo_file_defined:
261
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
262
+ lines.append(f'\t\t\t\t\t\t<name>{escape_xml(source_name_to_use)}</name>')
263
+ lines.append(f'\t\t\t\t\t\t<pathurl>file://localhost/{escape_xml(source_name_to_use)}.wav</pathurl>')
264
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
265
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
266
  lines.append(f'\t\t\t\t\t\t<timecode>')
 
280
  elif is_graphic:
281
  if not gfx_file_defined:
282
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
283
+ lines.append(f'\t\t\t\t\t\t<name>{escape_xml(source_name_to_use)}</name>')
284
+ lines.append(f'\t\t\t\t\t\t<pathurl>file://localhost/{escape_xml(source_name_to_use)}.mov</pathurl>')
285
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
286
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
287
  lines.append(f'\t\t\t\t\t\t<timecode>')
 
301
  else:
302
  if not file_defined:
303
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}">')
304
+ lines.append(f'\t\t\t\t\t\t<name>{escape_xml(source_name_to_use)}</name>')
305
  lines.append(f'\t\t\t\t\t\t<pathurl>{path_url}</pathurl>')
306
  lines.append(f'\t\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
307
  lines.append(f'\t\t\t\t\t\t<duration>8640000</duration>')
 
321
  lines.append(f'\t\t\t\t\t<file id="{master_id_to_use}"/>')
322
 
323
  lines.append('\t\t\t\t\t<marker>')
324
+ lines.append(f'\t\t\t\t\t\t<name>{escape_xml(clip_note)}</name>')
325
  lines.append(f'\t\t\t\t\t\t<in>{src_in_frames}</in>')
326
 
327
  # Extends the marker duration to span the entire clip for VO and Graphics
 
379
  tl_end = tl_start + duration_frames
380
 
381
  lines.append(f'\t\t\t\t<clipitem id="clipitem-a-{i}">')
382
+ lines.append(f'\t\t\t\t\t<name>{escape_xml(source_name_to_use)}</name>')
383
  lines.append(f'\t\t\t\t\t<masterclipid>{master_id_to_use}</masterclipid>')
384
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
385
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
 
813
 
814
 
815
 
816
+