Lately I’ve seen more and more people connecting their Final Cut Server systems to other MAMs, and one of the main questions in these “multiple MAMs” environments is how to exchange metadata in between the different systems.
If you want to copy asset metadata from an external MAM into Final Cut Server, this basically includes the following steps:
- copy media file into Final Cut Server
- copy related metadata as an XML file into Final Cut Server
Both steps would work with or without watch folders, you can e.g. copy new assets into FCSvr as part of a Final Cut Pro project file and let Final Cut Server automatically grab any related XML files after analyzing a file. The real challenge lies in creating the proper XML file.
At http://developer.apple.com/mac/library/technotes/tn2009/tn2255.html you find a very good article, which describes how the XML file needs to be structured. If your external MAM can create Final Cut Server import XML file structures directly, that’s great. If not, you need to restructure the XML file to prepare it for Final Cut Server usage.
While the latter is not part of this article, the main challenge lies in the fact, that Final Cut Server creates an asset ID for each new asset in its database, which needs to be contained in the related import XML file. This article mainly explains the process of finding this ID and writing it into the XML file.
Let’s start.
First we create a “Run an external script or command” response in the Final Cut Server administration panel. I call it “Add FCSvr Asset ID to VPMS XML”, as in my case I take an XML file as my input file, which has been generated by S4M’s VPMS.
Then I enter the path to the script I am going to show you in a minute, and then tell FCSvr to send the file name and the asset id as parameters:
At a later stage this would basically invoke my script like e.g.
/usr/local/vpms2fcsvr mytestfile.mxf 34
where “mytestfile.mxf” is the name of my file, and “34″ is the asset ID.
Now let’s have a look at the script, which is going to process everything:
#!/bin/bash
#
#######################################################
# #
# vpms2fcsvr reads an XML file exported by S4M's #
# VPMS and adds the Final Cut Server asset id of #
# the related media file to it. #
# copyright 2010 by Andre Aulich, www.andre-aulich.de #
# #
#######################################################
# First we define some variables:
VPMSFOLDER="/Users/cadmin/Desktop/Final Cut Server/VPMS_IN"
LOGFILE="/Users/cadmin/Desktop/Final Cut Server/vpms2fcsvr.log"
MEDIAFILENAME="$1"
ASSETID="$2"
TOBEREPLACED="STRING_TO_BE_REPLACED"
FCSvrXMLIN="/Users/cadmin/Desktop/Final Cut Server/Watchers/XML"
# Log some debugging information:
echo "Starting XML import at "$(date)"." >> "$LOGFILE"
echo "Media filename is "$MEDIAFILENAME"." >> "$LOGFILE"
echo "Asset ID is "$ASSETID"." >> "$LOGFILE"
# Let's generate the path to the XML file:
x="$MEDIAFILENAME"
XMLFILE="${x%.*}".xml
XMLFILEPATH="$VPMSFOLDER/$XMLFILE"
echo "The XML file is named ""$XMLFILEPATH""." >> "$LOGFILE"
# Now it's a good time to quit and log an error if the XML file doesn't exist.
if ! [[ -e "$XMLFILEPATH" ]]; then
echo "No XML file found at "$XMLFILEPATH". Can't import metadata from VPMS." >> "$LOGFILE"
exit 0
fi
# Now we replace STRING_TO_BE_REPLACED in our XML file with the FCSvr asset ID:
sed -i "" s/"$TOBEREPLACED"/"$ASSETID"/ "$XMLFILEPATH" >> "$LOGFILE"
# Copy the modified XML file into the FCSvr XML watch folder and remove the original XML file.
cp "$XMLFILEPATH" "$FCSvrXMLIN"/
rm "$XMLFILEPATH"
# We also remove the original media file.
rm "$VPMSFOLDER"/"$MEDIAFILENAME"
You see, there’s no magic involved. But let’s go through it step by step. First I tell my script where it finds all the media and XML files exported by your external MAM:
VPMSFOLDER="/Users/cadmin/Desktop/Final Cut Server/VPMS_IN"
This folder is not a Final Cut Server device. Then I define a log path:
LOGFILE="/Users/cadmin/Desktop/Final Cut Server/vpms2fcsvr.log"
In the next step I map the FCSvr parameters filename and asset id to my scripts global variables:
MEDIAFILENAME="$1"
ASSETID="$2"
The incoming XML file uses a fixed text string instead of the asset ID which I am going to replace. So I need to define which text string needs to be replaced:
TOBEREPLACED="STRING_TO_BE_REPLACED"
My final XML input file will be copied into a FCSvr watch folder, and here I define the path of that folder:
FCSvrXMLIN="/Users/cadmin/Desktop/Final Cut Server/Watchers/XML"
For debugging purposes, I log some information each time I invoke the script:
# Log some debugging information:
echo "Starting XML import at "$(date)"." >> "$LOGFILE"
echo "Media filename is "$MEDIAFILENAME"." >> "$LOGFILE"
echo "Asset ID is "$ASSETID"." >> "$LOGFILE"
Starting with the file name of the media file, I generate the path of the related XML file:
# Let's generate the path to the XML file:
x="$MEDIAFILENAME"
XMLFILE="${x%.*}".xml
XMLFILEPATH="$VPMSFOLDER/$XMLFILE"
echo "The XML file is named ""$XMLFILEPATH""." >> "$LOGFILE"
If this XML doesn’t exit, we quit the script:
# Now it's a good time to quit and log an error if the XML file doesn't exist.
if ! [[ -e "$XMLFILEPATH" ]]; then
echo "No XML file found at "$XMLFILEPATH". Can't import metadata from VPMS." >> "$LOGFILE"
exit 0
fi
Now we replace the place holder text string in the original XML file with the asset ID:
# Now we replace STRING_TO_BE_REPLACED in our XML file with the FCSvr asset ID:
sed -i "" s/"$TOBEREPLACED"/"$ASSETID"/ "$XMLFILEPATH" >> "$LOGFILE"
And then we copy the new XML file into our XML watch folder before deleting the original XML file:
# Copy the modified XML file into the FCSvr XML watch folder and remove the original XML file.
cp "$XMLFILEPATH" "$FCSvrXMLIN"/
rm "$XMLFILEPATH"
We also delete the original media file:
# We also remove the original media file.
rm "$VPMSFOLDER"/"$MEDIAFILENAME"
Removing the media and XML files is optional depending on your workflow, and instead of in-place-replacing the asset ID in the XML file you might also want to not touch the original XML file but redirect the “seded” XML file into the XML watch folder directly.
Take this as an example only and adapt it to your needs.
Now, as a next step, we need to tell Final Cut Server to trigger our script whenever a new asset gets created. To do so, open the subscription panel in the FCSvr admin interface and create a new subscription which is attached to assets. I call my subscription “Update VPMS metadata during asset creation”, enable it, and choose “Analyzed” as the only Event Type filter. This means, that my subscription gets triggered whenever an asset gets analyzed. If you choose “Created” as your trigger, your script might be invoked before Final Cut Server analyzed technical metadata of your file, and then Final Cut Server might overwrite the metadata you just imported through the XML import. Feel free to choose the filter which best fits your needs.
In the Response List I select my response “Add FCSvr Asset ID To VPMS XML” and then I enable the subscription:
Now I need to define my XML watch folder. I take Final Cut Server’s default Watchers device and create a subfolder inside called “XML”. Now I create a “Read XML” response called “Read XML”. After that I create a watcher called “Import translated VPMS XML” with these settings:
As you can see, I use the XML subfolder of my Watchers device as the Monitor Address, then I use “Read XML” and “Delete” as my responses, which means, that the XML will be read in and be deleted afterwards, if the read process worked well. This all gets triggered after a file has been created. The process starts if the files has been listed twice without file size changes, and FCSvr pauses for 10 seconds before listing a file again, so the whole process takes at least a bit more than 10 seconds.
My watcher only scans for xml files and ignores any other file types.
If you enable this job, and copy both a media file and a related XML file (with the same name like the media file, but with xml as suffix) into our input folder, and from there drag the media file into FCSvr, Final Cut Server will now write the asset’s ID into the XML and import the XML into its DB.
Of course this assumes, that your incoming XML file is already structured in the way Final Cut Server likes it. If not, you might want to adapt the script we use to restructure the incoming XML file. For this you might want to use XMLStarlet within bash or better use Ruby, Python, or Perl instead.





