import csv import xml.etree.ElementTree as ET import os import uuid # Import the uuid module from lxml import etree # Import lxml for XML handling from xml.dom import minidom import msvcrt # Function to convert timecode (HH:MM:SS:FF) to total frames based on the fps def timecode_to_frames(timecode, fps=60): """Convert a timecode (HH:MM:SS:FF) to total frames based on the fps.""" try: h, m, s, f = map(int, timecode.split(':')) # Split into hours, minutes, seconds, and frames return (h * 3600 + m * 60 + s) * fps + f # Convert to frames except ValueError: print(f"Invalid timecode: {timecode}") return 0 # Return 0 or handle error as appropriate # Define marker colors # pproColor keys: # default/blank/invalid = Green # "4281740498" # Red # "4289825711" # Purple # "4280578025" # Orange # "4281049552" # Yellow # "4294967295" # White # "4294741314" # Blue # "4292277273" # Turquoise marker_colors = { "FUNI": "4294741314", # Blue "SEG": "4280578025", # Orange "gamign": "4289825711", # Purple "env": "4289825711", # Purple "AFK": "4281049552", # Yellow "UNAFK": "4281049552", # Yellow "BEGIN": "4281049552", # Yellow "END": "4281049552" # Yellow } # Get a list of all CSV files in the current directory csv_files = [f for f in os.listdir('.') if f.endswith('.csv')] for csv_file in csv_files: print(f"Processing '{csv_file}'...") # Extract base name for sequence name video_base = os.path.splitext(csv_file)[0] sequence_name = f"{video_base}" # Function to generate the XML structure def generate_xml(markers, duration, sequence_name): # Create the root element xmeml = ET.Element("xmeml", version="4") # Create the element sequence = ET.SubElement(xmeml, "sequence", id="sequence") # Manually add the attributes with dots sequence.set("TL.SQAudioVisibleBase", "0") sequence.set("TL.SQVideoVisibleBase", "0") sequence.set("TL.SQVisibleBaseTime", "0") sequence.set("TL.SQAVDividerPosition", "0.5") sequence.set("TL.SQHideShyTracks", "0") sequence.set("TL.SQHeaderWidth", "292") sequence.set("Monitor.ProgramZoomOut", "0") sequence.set("Monitor.ProgramZoomIn", "0") sequence.set("TL.SQTimePerPixel", "0.19999999999999998") sequence.set("MZ.EditLine", "0") sequence.set("MZ.Sequence.PreviewFrameSizeHeight", "1080") sequence.set("MZ.Sequence.PreviewFrameSizeWidth", "1920") sequence.set("MZ.Sequence.AudioTimeDisplayFormat", "200") sequence.set("MZ.Sequence.PreviewRenderingClassID", "1061109567") sequence.set("MZ.Sequence.PreviewRenderingPresetCodec", "1634755439") sequence.set("MZ.Sequence.PreviewRenderingPresetPath", "EncoderPresets/SequencePreview/795454d9-d3c2-429d-9474-923ab13b7018/QuickTime.epr") sequence.set("MZ.Sequence.PreviewUseMaxRenderQuality", "false") sequence.set("MZ.Sequence.PreviewUseMaxBitDepth", "false") sequence.set("MZ.Sequence.EditingModeGUID", "795454d9-d3c2-429d-9474-923ab13b7018") sequence.set("MZ.Sequence.VideoTimeDisplayFormat", "101") sequence.set("MZ.WorkOutPoint", "4612930560000") sequence.set("MZ.WorkInPoint", "0") sequence.set("explodedTracks", "true") # Generate a unique UUID and set it in the sequence element uuid_val = str(uuid.uuid4()).replace('-', '') # Generate a unique UUID without dashes ET.SubElement(sequence, "uuid").text = uuid_val # Set the duration right after the UUID duration_tag = ET.SubElement(sequence, "duration") duration_tag.text = str(duration) # Add rate (timebase and ntsc) rate = ET.SubElement(sequence, "rate") timebase = ET.SubElement(rate, "timebase") timebase.text = "60" ntsc = ET.SubElement(rate, "ntsc") ntsc.text = "FALSE" # Set sequence name name = ET.SubElement(sequence, "name") name.text = sequence_name # Create media section media = ET.SubElement(sequence, "media") video = ET.SubElement(media, "video") format_tag = ET.SubElement(video, "format") samplecharacteristics = ET.SubElement(format_tag, "samplecharacteristics") # Now let's add a rate and other information under samplecharacteristics (to make it meaningful) rate = ET.SubElement(samplecharacteristics, "rate") timebase = ET.SubElement(rate, "timebase") timebase.text = "60" ntsc = ET.SubElement(rate, "ntsc") ntsc.text = "FALSE" # Add codec information codec = ET.SubElement(samplecharacteristics, "codec") name = ET.SubElement(codec, "name") name.text = "Apple ProRes 422" appspecificdata = ET.SubElement(codec, "appspecificdata") appname = ET.SubElement(appspecificdata, "appname") appname.text = "Final Cut Pro" appmanufacturer = ET.SubElement(appspecificdata, "appmanufacturer") appmanufacturer.text = "Apple Inc." appversion = ET.SubElement(appspecificdata, "appversion") appversion.text = "7.0" data = ET.SubElement(appspecificdata, "data") qtcodec = ET.SubElement(data, "qtcodec") codecname1 = ET.SubElement(qtcodec, "codecname") codecname1.text = "Apple ProRes 422" codectypename = ET.SubElement(qtcodec, "codectypename") codectypename.text = "Apple ProRes 422" codecname2 = ET.SubElement(qtcodec, "codecname") codecname2.text = "Apple ProRes 422" codectypecode = ET.SubElement(qtcodec, "codectypecode") codectypecode.text = "apcn" codecvendorcode = ET.SubElement(qtcodec, "codecvendorcode") codecvendorcode.text = "appl" spatialquality = ET.SubElement(qtcodec, "spatialquality") spatialquality.text = "1024" temporalquality = ET.SubElement(qtcodec, "temporalquality") temporalquality.text = "0" keyframerate = ET.SubElement(qtcodec, "keyframerate") keyframerate.text = "0" datarate = ET.SubElement(qtcodec, "datarate") datarate.text = "0" # Add dimension info width = ET.SubElement(samplecharacteristics, "width") width.text = "1920" height = ET.SubElement(samplecharacteristics, "height") height.text = "1080" anamorphic = ET.SubElement(samplecharacteristics, "anamorphic") anamorphic.text = "FALSE" pixelaspectratio = ET.SubElement(samplecharacteristics, "pixelaspectratio") pixelaspectratio.text = "square" fielddominance = ET.SubElement(samplecharacteristics, "fielddominance") fielddominance.text = "none" colordepth = ET.SubElement(samplecharacteristics, "colordepth") colordepth.text = "24" # Create the element track = ET.SubElement(video, "track") track.set("TL.SQTrackShy", "0") track.set("TL.SQTrackExpandedHeight", "25") track.set("TL.SQTrackExpanded", "0") track.set("MZ.TrackTargeted", "0") #Add track modifiers enabled = ET.SubElement(track, "enabled") enabled.text = "TRUE" locked = ET.SubElement(track, "locked") locked.text = "FALSE" # Add generator item (matte) generatoritem = ET.SubElement(track, "generatoritem", id="clipitem-1") item_name = ET.SubElement(generatoritem, "name") item_name.text = f"Marker Color Matte ({markers[0]['time']})" enabled = ET.SubElement(generatoritem, "enabled") enabled.text = "TRUE" generatoritem_duration = ET.SubElement(generatoritem, "duration") generatoritem_duration.text = str(duration) rate = ET.SubElement(generatoritem, "rate") timebase = ET.SubElement(rate, "timebase") timebase.text = "60" ntsc = ET.SubElement(rate, "ntsc") ntsc.text = "FALSE" start = ET.SubElement(generatoritem, "start") start.text = "0" end = ET.SubElement(generatoritem, "end") end.text = str(duration) in_time = ET.SubElement(generatoritem, "in") in_time.text = "0" out_time = ET.SubElement(generatoritem, "out") out_time.text = str(duration) alphatype = ET.SubElement(generatoritem, "alphatype") alphatype.text = "none" effect = ET.SubElement(generatoritem, "effect") effect_name = ET.SubElement(effect, "name") effect_name.text = "Color" effectid = ET.SubElement(effect, "effectid") effectid.text = "Color" effectcategory = ET.SubElement(effect, "effectcategory") effectcategory.text = "Matte" effecttype = ET.SubElement(effect, "effecttype") effecttype.text = "generator" mediatype = ET.SubElement(effect, "mediatype") mediatype.text = "video" parameter = ET.SubElement(effect, "parameter", authoringApp="PremierePro") parameterid = ET.SubElement(parameter, "parameterid") parameterid.text = "fillcolor" param_name = ET.SubElement(parameter, "name") param_name.text = "Color" value = ET.SubElement(parameter, "value") alpha = ET.SubElement(value, "alpha") alpha.text = "0" red = ET.SubElement(value, "red") red.text = "0" green = ET.SubElement(value, "green") green.text = "0" blue = ET.SubElement(value, "blue") blue.text = "0" filter_tag = ET.SubElement(generatoritem, "filter") filter_effect = ET.SubElement(filter_tag, "effect") filter_effect_name = ET.SubElement(filter_effect, "name") filter_effect_name.text = "Opacity" filter_effectid = ET.SubElement(filter_effect, "effectid") filter_effectid.text = "opacity" filter_effectcategory = ET.SubElement(filter_effect, "effectcategory") filter_effectcategory.text = "motion" filter_effecttype = ET.SubElement(filter_effect, "effecttype") filter_effecttype.text = "motion" filter_mediatype = ET.SubElement(filter_effect, "mediatype") filter_mediatype.text = "video" pproBypass = ET.SubElement(filter_effect, "pproBypass") pproBypass.text = "false" filter_parameter = ET.SubElement(filter_effect, "parameter", authoringApp="PremierePro") filter_parameterid = ET.SubElement(filter_parameter, "parameterid") filter_parameterid.text = "opacity" filter_param_name = ET.SubElement(filter_parameter, "name") filter_param_name.text = "opacity" filter_valuemin = ET.SubElement(filter_parameter, "valuemin") filter_valuemin.text = "0" filter_valuemax = ET.SubElement(filter_parameter, "valuemax") filter_valuemax.text = "100" filter_value = ET.SubElement(filter_parameter, "value") filter_value.text = "0" # Create the