Fcpxml To Xml Converter -

def extract_metadata(fcpxml_file): """Extract key metadata from FCPXML without full conversion.""" try: tree = ET.parse(fcpxml_file) root = tree.getroot() # Handle namespace ns = {'fcpxml': 'http://ns.apple.com/fcpxml/1.0'} print("\n=== FCPXML Metadata ===\n") # Project info project = root.find('.//fcpxml:project', ns) if project is not None: print(f"Project Name: {project.get('name', 'Unknown')}") print(f"Project Duration: {project.get('duration', 'Unknown')}") # Sequence/Event info event = root.find('.//fcpxml:event', ns) if event is not None: print(f"Event Name: {event.get('name', 'Unknown')}") # Library info library = root.find('.//fcpxml:library', ns) if library is not None: print(f"Library Name: {library.get('name', 'Unknown')}") # Count clips clips = root.findall('.//fcpxml:clip', ns) print(f"\nTotal Clips: {len(clips)}") # Count assets assets = root.findall('.//fcpxml:asset', ns) print(f"Total Assets: {len(assets)}") # Count markers markers = root.findall('.//fcpxml:marker', ns) print(f"Total Markers: {len(markers)}") # Get timeline duration timeline = root.find('.//fcpxml:timeline', ns) if timeline is not None: print(f"Timeline Duration: {timeline.get('duration', 'Unknown')}") # Get format info format_elem = root.find('.//fcpxml:format', ns) if format_elem is not None: print(f"Frame Rate: {format_elem.get('frameRateRange', 'Unknown')}") print(f"Resolution: {format_elem.get('width', 'Unknown')}x{format_elem.get('height', 'Unknown')}") except Exception as e: print(f"Error extracting metadata: {e}")

class FCPXMLConverter: def __init__(self, input_file, output_file=None, pretty=True, strip_namespace=True): self.input_file = input_file self.output_file = output_file self.pretty = pretty self.strip_namespace = strip_namespace self.tree = None self.root = None Fcpxml To Xml Converter

def main(): parser = argparse.ArgumentParser( description='Convert FCPXML (Final Cut Pro XML) to standard XML format', epilog='Example: python fcpxml_converter.py input.fcpxml -o output.xml --metadata' ) parser.add_argument('input', help='Input FCPXML file path') parser.add_argument('-o', '--output', help='Output XML file path (optional, prints to console if not provided)') parser.add_argument('--keep-namespace', action='store_true', help='Keep original namespace prefixes (default: strip them)') parser.add_argument('--compact', action='store_true', help='Output compact XML without pretty printing') parser.add_argument('--metadata', action='store_true', help='Extract and display metadata summary only (no conversion)') args = parser.parse_args() # Check input file exists if not os.path.exists(args.input): print(f"Error: Input file '{args.input}' not found.") sys.exit(1) # Metadata only mode if args.metadata: extract_metadata(args.input) sys.exit(0) # Perform conversion converter = FCPXMLConverter( input_file=args.input, output_file=args.output, pretty=not args.compact, strip_namespace=not args.keep_namespace ) if converter.convert(): print("\nConversion completed successfully.") else: print("\nConversion failed.") sys.exit(1) 'Unknown')}") print(f"Resolution: {format_elem.get('width'

#!/usr/bin/env python3 """ FCPXML to XML Converter Converts Final Cut Pro FCPXML files to standard XML format. Handles namespaces, pretty-printing, and optional structure flattening. """ help='Input FCPXML file path') parser.add_argument('-o'

def strip_namespaces(self, element): """Remove namespace prefixes from element tags.""" # Process element tag if '}' in element.tag: element.tag = element.tag.split('}', 1)[1] # Process attributes (remove namespace from attribute names if any) new_attrs = {} for attr, value in element.attrib.items(): if '}' in attr: new_attr = attr.split('}', 1)[1] else: new_attr = attr new_attrs[new_attr] = value element.attrib.clear() element.attrib.update(new_attrs) # Recursively process children for child in element: self.strip_namespaces(child)