Initial assumptions
I have a metadata subscription watching for Productions with a Status of "New" (which is my default for new Productions). This runs a command that creates a folder in my Media device with the same name as the Production's title. My editors then upload content to the Production and target this folder for uploads. This script depends on this, for reasons that will become clear.
Metadata subscription and responses
My subscription is on a custom created field called "Generate H.264". If this is set to "Yes", then the transcoding process kicks off. It is linked to two responses.
The first response is a Copy response, which copies the file to my Watchers device, and applies the appropriate transcoding setting (an H.264 setting, in this case).
The second response is a Run External Script or Command response. This runs my following script. In the "Parameters" field of the response, I pass the parameters [File Name] and [Location]. File Name is self-explanatory; Location is the folder inside the Media device (for example, "/Lecture One"). Note that Location = Production's Title field, because of the first automation.
The script
#!/bin/bash
FILENAME=$1
LOCATION=$2
ADDITION=$3
FILENAME_ESCAPED=${FILENAME// /%20}
LOCATION_ESCAPED=${LOCATION// /%20}
# Check command line parameters
if [ -z "$1" ]; then
echo Usage: $0 filename location type
exit
fi
if [ -z "$2" ]; then
echo Usage: $0 filename location type
exit
fi
if [ -z "$3" ]; then
echo Usage: $0 filename location type
exit
fi
# Set the location to the fcsvr_client binary
PATH_TO_BINARIES="/Library/Application Support/Final Cut Server/Final Cut Server.bundle/Contents/MacOS/fcsvr_client"
# Set the location of the Media folder
PATH_TO_MEDIA="/FCS/Production Media/Media"
PATH_TO_MEDIA_ESCAPED=${PATH_TO_MEDIA// /%20}
# Set the location of the Watcher folder
PATH_TO_WATCHER="/FCS/Production Media/Watchers/"
# Copy the file from the Watcher to the Media folder, and put it in the right location
# Add the suffix to the filename
FILENAME_NO_EXTENSION=`echo "$FILENAME" | awk -F. '{ print $1 }'`
FILENAME_EXTENSION=`echo "$FILENAME" | awk -F. '{ print $2 }'`
echo $FILENAME_NO_EXTENSION
echo $FILENAME_EXTENSION
mv "$PATH_TO_WATCHER""$FILENAME" "$PATH_TO_MEDIA""$LOCATION"/"$FILENAME_NO_EXTENSION"-$ADDITION."$FILENAME_EXTENSION"
# Determine original Production "address" by searching for the "location" (since this is the same as the Production name)
PROJECTNAME=$("$PATH_TO_BINARIES" search --crit "$2" /project | grep -i -o -e "/project/[0-9]*")
echo $PROJECTNAME
# Escape new filename
NEW_FILENAME="$FILENAME_NO_EXTENSION"-$ADDITION."$FILENAME_EXTENSION"
NEW_FILENAME=${NEW_FILENAME// /%20}
echo $NEW_FILENAME
# Create asset and associate it with the project
OUTPUT=$(sudo "$PATH_TO_BINARIES" createasset pa_asset_media --projaddr $PROJECTNAME /dev/6"$LOCATION_ESCAPED"/"$NEW_FILENAME")
echo $OUTPUT
Careful with the newlines! There is a link to the complete script file at the end of this post.
Explanation of each step follows:
# Set the location to the fcsvr_client binary
PATH_TO_BINARIES="/Library/Application Support/Final Cut Server/Final Cut Server.bundle/Contents/MacOS/fcsvr_client"
# Set the location of the Media folder
PATH_TO_MEDIA="/FCS/Production Media/Media"
PATH_TO_MEDIA_ESCAPED=${PATH_TO_MEDIA// /%20}
# Set the location of the Watcher folder
PATH_TO_WATCHER="/FCS/Production Media/Watchers/"
This sets up the locations to the appropriate Watcher and Media folders. The PATH_TO_MEDIA_ESCAPED variable replaces spaces with %20, which is required by the Final Cut Server command line (see later).
# Copy the file from the Watcher to the Media folder, and put it in the right location
# Add the suffix to the filename
FILENAME_NO_EXTENSION=`echo "$FILENAME" | awk -F. '{ print $1 }'`
FILENAME_EXTENSION=`echo "$FILENAME" | awk -F. '{ print $2 }'`
echo $FILENAME_NO_EXTENSION
echo $FILENAME_EXTENSION
mv "$PATH_TO_WATCHER""$FILENAME" "$PATH_TO_MEDIA""$LOCATION"/"$FILENAME_NO_EXTENSION"-$ADDITION."$FILENAME_EXTENSION"
This part figures out what the filename is minus the extension.
It then adds the third command line parameter to the end of the file (I pass the parameter "h264"). Then it moves the file from the Watchers folder to the Production's folder on the Media device.
# Determine original Production "address" by searching for the "location" (since this is the same as the Production name)
PROJECTNAME=$("$PATH_TO_BINARIES" search --crit "$2" /project | grep -i -o -e "/project/[0-9]*")
echo $PROJECTNAME
This is a really key step!
It searches for Productions that have some metadata that matches the [Location] command line parameter. The grep command then plucks out the Project that it belongs to.
# Escape new filename
NEW_FILENAME="$FILENAME_NO_EXTENSION"-$ADDITION."$FILENAME_EXTENSION"
NEW_FILENAME=${NEW_FILENAME// /%20}
echo $NEW_FILENAME
# Create asset and associate it with the project
OUTPUT=$(sudo "$PATH_TO_BINARIES" createasset pa_asset_media --projaddr $PROJECTNAME /dev/6"$LOCATION_ESCAPED"/"$NEW_FILENAME")
This section escapes the new filename (with %20 for spaces).
Then it uses the fcsvr_client createasset command to create an asset in the database,
and the --projaddr option uses the Production "address" (of the form /project/number) to add the newly created asset to the Production.
Complex, but works fairly reliably.
Thanks so much for taking the time to post this. It is a tremendous help to my own endeavors. You're right, it's complex, but I'm realizing that this is how it has to be done. Plus, you explained it very well.
ReplyDeleteJason Whetstone