<?php
/*
*
*/
include_once('services/class.LevelLogger.php');
include_once('valueobjects/class.videoObject.php');
class CreateUMAXML{
private function getNiceGoverningAgreement($label){
if ($label){
$lowerLabel = strtolower($label);
if ($lowerLabel == "emi"){
return "EMI";
}else if ($lowerLabel == "sony"){
return "Sony";
}else if ($lowerLabel == "wmg"){
return "Warner";
}else if ($lowerLabel == "umg"){
return "Universal";
}else{
return false;
}
}
}
public function createXML($videoObject){
if ($videoObject){
// Get the Core
$videoCore = $videoObject->get_videoCore();
// Start the new XML
$returnXML = new SimpleXMLElement("<VideoObject></VideoObject>");
// Add the core Video Metadata details
$returnXML->addAttribute('Artist', $videoCore->get_artist());
$returnXML->addAttribute('ProdUPC', $videoCore->get_upc());
$returnXML->addAttribute('ISRC', $videoCore->get_isrc());
$returnXML->addAttribute('Track', $videoCore->get_track_name());
if ($label = $this->getNiceGoverningAgreement($videoCore->get_label())){
$returnXML->addAttribute('GoverningAgreement', $label);
}else{
$returnXML->addAttribute('GoverningAgreement', 'No Label Found');
}
// Add the UMA specification
$actionElmnt = $returnXML->addChild('Action');
$actionElmnt->addAttribute('Type', 'INSERT');
$actionElmnt->addAttribute('System', 'UMA');
// Get the VideoFiles. Loop through them adding the metadata for each one
$videoFilesObjects = $videoObject->get_videoFileArray();
foreach($videoFilesObjects as $videoFileObj){
// Get the output files
$outputFileObjects = $videoFileObj->get_outputFileArray();
foreach($outputFileObjects as $outputFileObj){
// Get the fileLocation
$fileLocation = $this->getAkamaiVideoPath($outputFileObj->get_video_encoded_location(), "video");
// If there's actually a filename returned
if ($fileLocation){
// Add the media Node
$videoElmnt = $actionElmnt->addChild('Media');
$fileExtension = $this->getFileTypeFromPath($fileLocation);
// Add The Videos
$videoElmnt->addAttribute('Type', 'Video');
$videoElmnt->addAttribute('Format', $fileExtension);
$videoElmnt->addAttribute('Width', $outputFileObj->get_output_width());
$videoElmnt->addAttribute('Height', $outputFileObj->get_output_height());
// Add the widescreen element
if ($videoFileObj->get_widescreen()){
$videoElmnt->addAttribute('is16x9', "true");
}else{
$videoElmnt->addAttribute('is16x9', "false");
}
// Add the asset location
$videoLocElmnt = $videoElmnt->addChild('Location', $fileLocation);
}
}
}
// Get the Thumbnail Files. Loop through them adding the metadata for each one
$thumbFileObjects = $videoObject->get_thumbFileArray();
foreach($thumbFileObjects as $thumbFileObject){
// Get the thumbnail location
$fileLocation = $this->getAkamaiVideoPath($thumbFileObject->get_thumb_dest_location(), "thumb");
if ($fileLocation){
// Add the media Node
$videoElmnt = $actionElmnt->addChild('Media');
// Get the file extension
$fileExtension = $this->getFileTypeFromPath($fileLocation);
// Add The Videos
$videoElmnt->addAttribute('Type', 'Image');
$videoElmnt->addAttribute('Format', $fileExtension);
$videoElmnt->addAttribute('Width', $thumbFileObject->get_thumb_width());
$videoElmnt->addAttribute('Height', $thumbFileObject->get_thumb_height());
// Add the asset location
$videoLocElmnt = $videoElmnt->addChild('Location', $fileLocation);
}
}
$returnXML = $this->getPrettyXML($returnXML);
return $returnXML;
}
}
private function getFileTypeFromPath($filename){
if ($filename){
// Get the last 3 chars of the filename (file extension)
$fileExtension = strtolower(substr($filename,-3,3));
return $fileExtension;
}
}
/**
* Returns a path without the akamai prefix
* @param String, path.
**/
private function getAkamaiVideoPath($path, $type){
if ($path){
// Strip out the prefix if it's there, and return the result
$akamaiPrefix = "/8619/_!";
$newPath = str_replace($akamaiPrefix, "", $path);
// Add the Akamai token prefix to the URL for the thumb
if ($type == "thumb"){
$newPath = ("http://a123.g.akamai.net/7/123/5290/v0001/mtviestor.download.akamai.com/8619/_!/".$newPath);
}
return $newPath;
}
}
/**
* The output from simpleXML is hideous, this function uses DOM to pretty it
* @param $xml simpleXML object
**/
private function getPrettyXML($xml) {
if ($xml){
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$domnode = dom_import_simplexml($xml);
$domnode = $doc->importNode($domnode, true);
$domnode = $doc->appendChild($domnode);
return ($doc->saveXML());
}
}
}
?>