Created
March 25, 2015 05:27
-
-
Save willvincent/da274e0e6ba40eafa345 to your computer and use it in GitHub Desktop.
Parse filenames out of a FCPXML file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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