Skip to content

Instantly share code, notes, and snippets.

@willvincent
Created March 25, 2015 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willvincent/da274e0e6ba40eafa345 to your computer and use it in GitHub Desktop.
Save willvincent/da274e0e6ba40eafa345 to your computer and use it in GitHub Desktop.
Parse filenames out of a FCPXML file.
<?php
$xml = simplexml_load_file($argv[1]);
$media = array();
$video = array();
$audio = array();
foreach ($xml->sequence->media->video->track->clipitem as $item) {
if (trim($item->name->__toString())) {
$media[] = $item->name->__toString();
if (!in_array($item->name, $video)) {
$video[] = $item->name->__toString();
}
}
}
foreach ($xml->sequence->media->audio->track->clipitem as $item) {
if (trim($item->name->__toString())) {
$media[] = $item->name->__toString();
if (!in_array($item->name, $audio)) {
$audio[] = $item->name->__toString();
}
}
}
$csv = fopen("parsed-xml.csv", 'w') or die("Can't open file: parsed-xml.csv for writing.");
$count = count($video);
if (count($audio) > $count) {
$count = count($audio);
}
fputcsv($csv, array('Video', 'Audio'));
for ($i = 0; $i < $count; $i++) {
$line = array();
$line['Video'] = isset($video[$i]) ? $video[$i] : NULL;
$line['Audio'] = isset($audio[$i]) ? $audio[$i] : NULL;
fputcsv($csv, $line);
}
fclose($csv);
$file = fopen("parsed-xml.txt", 'w') or die("Can't open file: parsed-xml.txt for writing.");
foreach ($media as $line) {
fputs($file, $line . "\n");
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment