Beispiel #1
0
 private function selectDeliveryTypeForAuto()
 {
     $enabledDeliveryTypes = $this->partner->getDeliveryTypes();
     $deliveryType = null;
     foreach ($enabledDeliveryTypes as $enabledDeliveryTypeKey => $values) {
         if ($enabledDeliveryTypeKey == PlaybackProtocol::AUTO) {
             unset($enabledDeliveryTypes[$enabledDeliveryTypeKey]);
         } else {
             if ($this->asset && $enabledDeliveryTypeKey == PlaybackProtocol::HTTP) {
                 $deliveryType = $enabledDeliveryTypes[$enabledDeliveryTypeKey];
             }
         }
     }
     if (!count($enabledDeliveryTypes)) {
         KalturaLog::err('At least one non auto delivery type must be specified');
         return array();
     }
     if (is_null($deliveryType)) {
         $deliveryTypeKeys = array();
         $deliveryTypeName = null;
         if ($this->isSecured) {
             $deliveryTypeKeys[] = 'secured_default_delivery_type';
         }
         if ($this->entry->getDuration() <= kConf::get('short_entries_max_duration')) {
             $deliveryTypeKeys[] = 'short_entries_default_delivery_type';
         }
         $deliveryTypeKeys[] = 'default_delivery_type';
         reset($enabledDeliveryTypes);
         $deliveryTypeName = key($enabledDeliveryTypes);
         foreach ($deliveryTypeKeys as $deliveryTypeKey) {
             $deliveryTypesToValidate = kConf::get($deliveryTypeKey);
             $deliveryTypesToValidate = explode(',', $deliveryTypesToValidate);
             foreach ($deliveryTypesToValidate as $deliveryTypeToValidate) {
                 if (isset($enabledDeliveryTypes[$deliveryTypeToValidate])) {
                     $deliveryTypeName = $deliveryTypeToValidate;
                     //When match is found break this loop and outer loop as well (http://www.php.net/manual/en/control-structures.break.php)
                     break 2;
                 }
             }
         }
         $deliveryType = $enabledDeliveryTypes[$deliveryTypeName];
     }
     return $deliveryType;
 }
 /**
  * decideThumbGenerate is the decision layer for a single thumbnail generation 
  * 
  * @param entry $entry
  * @param thumbParams $destThumbParams
  * @param BatchJob $parentJob
  * @return thumbAsset 
  */
 public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false, $srcAsset = null)
 {
     if (is_null($srcAsset)) {
         $srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $entry->getId());
         if (is_null($srcAsset)) {
             throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY);
         }
     }
     $errDescription = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId());
     $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription);
     if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) {
         $destThumbParamsOutput->setVideoOffset($entry->getThumbOffset());
     }
     $destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration()));
     if (!$destThumbParamsOutput->getDensity()) {
         $partner = $entry->getPartner();
         if (!is_null($partner)) {
             $destThumbParamsOutput->setDensity($partner->getDefThumbDensity());
         }
     }
     $thumbAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId());
     if ($thumbAsset) {
         $description = $thumbAsset->getDescription() . "\n" . $errDescription;
         $thumbAsset->setDescription($description);
     } else {
         $thumbAsset = new thumbAsset();
         $thumbAsset->setPartnerId($entry->getPartnerId());
         $thumbAsset->setEntryId($entry->getId());
         $thumbAsset->setDescription($errDescription);
         $thumbAsset->setFlavorParamsId($destThumbParams->getId());
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setTags($destThumbParamsOutput->getTags());
     $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
     if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) {
         $thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING);
     }
     //Sets the default thumb if this the only default thumb
     kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset);
     if (!$destThumbParamsOutput) {
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->save();
         return null;
     }
     $thumbAsset->save();
     // save flavor params
     $destThumbParamsOutput->setPartnerId($entry->getPartnerId());
     $destThumbParamsOutput->setEntryId($entry->getId());
     $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId());
     $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion());
     $destThumbParamsOutput->save();
     $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $srcAssetType = $srcAsset->getType();
     if (!$runSync) {
         $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput);
         return $thumbAsset;
     }
     $errDescription = null;
     // Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo.
     $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null);
     // failed
     if (!$capturedPath) {
         $thumbAsset->incrementVersion();
         $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR);
         $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}");
         $thumbAsset->save();
         return $thumbAsset;
     }
     $thumbAsset->incrementVersion();
     $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
     if (file_exists($capturedPath)) {
         list($width, $height, $type, $attr) = getimagesize($capturedPath);
         $thumbAsset->setWidth($width);
         $thumbAsset->setHeight($height);
         $thumbAsset->setSize(filesize($capturedPath));
     }
     $logPath = $capturedPath . '.log';
     if (file_exists($logPath)) {
         $thumbAsset->incLogFileVersion();
         $thumbAsset->save();
         // creats the file sync
         $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         kFileSyncUtils::moveFromFile($logPath, $logSyncKey);
         KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey));
     } else {
         $thumbAsset->save();
     }
     $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($capturedPath, $syncKey);
     KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey));
     if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
         // increment thumbnail version
         $entry->setThumbnail(".jpg");
         $entry->setCreateThumb(false);
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId());
             foreach ($entryThumbAssets as $entryThumbAsset) {
                 if ($entryThumbAsset->getId() == $thumbAsset->getId()) {
                     continue;
                 }
                 if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     continue;
                 }
                 $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
                 $entryThumbAsset->save();
             }
         }
     }
     if (!is_null($thumbAsset->getFlavorParamsId())) {
         kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId());
     }
     return $thumbAsset;
 }
Beispiel #3
0
 /**
  * @param string $templateName
  * @param KalturaQuickPlayDistributionProfile $distributionProfile
  * @param KalturaQuickPlayDistributionJobProviderData $providerData
  */
 public function __construct(KalturaDistributionJobData $distributionJobData, KalturaQuickPlayDistributionJobProviderData $providerData, array $flavorAssets, array $thumbnailAssets, entry $entry)
 {
     $this->_distributionJobData = $distributionJobData;
     $this->_distributionProfile = $distributionJobData->distributionProfile;
     $this->_providerData = $providerData;
     $xmlTemplate = realpath(dirname(__FILE__) . '/../') . '/xml/' . self::TEMPLATE_XML;
     $this->_doc = new KDOMDocument();
     $this->_doc->load($xmlTemplate);
     $this->_xpath = new DOMXPath($this->_doc);
     $this->_xpath->registerNamespace('qpm', 'http://www.quickplaymedia.com');
     // enclosure node template
     $node = $this->_xpath->query('//qpm:enclosure', $this->_doc->firstChild)->item(0);
     $this->_enclosureNode = $node->cloneNode(true);
     $node->parentNode->removeChild($node);
     $this->_fieldValues = unserialize($this->_providerData->fieldValues);
     if (!$this->_fieldValues) {
         $this->_fieldValues = array();
     }
     kXml::setNodeValue($this->_xpath, '/rss/channel/title', $this->_distributionProfile->channelTitle);
     kXml::setNodeValue($this->_xpath, '/rss/channel/link', $this->_distributionProfile->channelLink);
     kXml::setNodeValue($this->_xpath, '/rss/channel/description', $this->_distributionProfile->channelDescription);
     kXml::setNodeValue($this->_xpath, '/rss/channel/managingEditor', $this->_distributionProfile->channelManagingEditor);
     kXml::setNodeValue($this->_xpath, '/rss/channel/language', $this->_distributionProfile->channelLanguage);
     kXml::setNodeValue($this->_xpath, '/rss/channel/image/title', $this->_distributionProfile->channelImageTitle);
     kXml::setNodeValue($this->_xpath, '/rss/channel/image/width', $this->_distributionProfile->channelImageWidth);
     kXml::setNodeValue($this->_xpath, '/rss/channel/image/height', $this->_distributionProfile->channelImageHeight);
     kXml::setNodeValue($this->_xpath, '/rss/channel/image/link', $this->_distributionProfile->channelImageLink);
     kXml::setNodeValue($this->_xpath, '/rss/channel/image/url', $this->_distributionProfile->channelImageUrl);
     kXml::setNodeValue($this->_xpath, '/rss/channel/copyright', $this->_distributionProfile->channelCopyright);
     $this->setNodeValueDateFieldConfigId('/rss/channel/pubDate', KalturaQuickPlayDistributionField::PUB_DATE);
     $this->setNodeValueDate('/rss/channel/lastBuildDate', time());
     kXml::setNodeValue($this->_xpath, '/rss/channel/generator', $this->_distributionProfile->channelGenerator);
     kXml::setNodeValue($this->_xpath, '/rss/channel/rating', $this->_distributionProfile->channelRating);
     kXml::setNodeValue($this->_xpath, '/rss/channel/language', $this->_distributionProfile->channelLanguage);
     $this->setNodeValueFieldConfigId('/rss/channel/item/title', KalturaQuickPlayDistributionField::TITLE);
     $this->setNodeValueFieldConfigId('/rss/channel/item/description', KalturaQuickPlayDistributionField::DESCRIPTION);
     $this->setNodeValueFieldConfigId('/rss/channel/item/guid', KalturaQuickPlayDistributionField::GUID);
     $this->setNodeValueFieldConfigId('/rss/channel/item/category', KalturaQuickPlayDistributionField::CATEGORY);
     $this->setNodeValueDateFieldConfigId('/rss/channel/item/pubDate', KalturaQuickPlayDistributionField::PUB_DATE);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:keywords', KalturaQuickPlayDistributionField::QPM_KEYWORDS);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:priceID', KalturaQuickPlayDistributionField::QPM_PRICE_ID);
     $this->setNodeValueDateFieldConfigId('/rss/channel/item/qpm:updateDate', KalturaQuickPlayDistributionField::QPM_UPDATE_DATE);
     $this->setNodeValueDateFieldConfigId('/rss/channel/item/qpm:expiryDate', KalturaQuickPlayDistributionField::QPM_EXPIRY_DATE);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:sortOrder', KalturaQuickPlayDistributionField::QPM_SORT_ORDER);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:genre', KalturaQuickPlayDistributionField::QPM_GENRE);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:copyright', KalturaQuickPlayDistributionField::QPM_COPYRIGHT);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:artist', KalturaQuickPlayDistributionField::QPM_ARTIST);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:director', KalturaQuickPlayDistributionField::QPM_DIRECTOR);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:producer', KalturaQuickPlayDistributionField::QPM_PRODUCER);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:expDatePadding', KalturaQuickPlayDistributionField::QPM_EXP_DATE_PADDING);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:onDeviceExpirationPadding', KalturaQuickPlayDistributionField::QPM_ON_DEVICE_EXPIRATION_PADDING);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:onDeviceExpiration', KalturaQuickPlayDistributionField::QPM_ON_DEVICE_EXPIRATION);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:groupCategory', KalturaQuickPlayDistributionField::QPM_GROUP_CATEGORY);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:notes', KalturaQuickPlayDistributionField::QPM_NOTES);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:rating/@scheme', KalturaQuickPlayDistributionField::QPM_RATING_SCHEMA);
     $this->setNodeValueFieldConfigId('/rss/channel/item/qpm:rating/@value', KalturaQuickPlayDistributionField::QPM_RATING);
     $this->removeNodeIfEmpty('/rss/channel/generator');
     $this->removeNodeIfEmpty('/rss/channel/rating');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:artist');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:director');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:producer');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:expDatePadding');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:onDeviceExpirationPadding');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:onDeviceExpiration');
     $this->removeNodeIfEmpty('/rss/channel/item/qpm:groupCategory');
     foreach ($thumbnailAssets as $thumbnailAsset) {
         $encodingProfile = $thumbnailAsset->getWidth() . 'x' . $thumbnailAsset->getHeight();
         $this->_enclosuresXmls[] = $this->createEnclosureXml($thumbnailAsset, 'thumbnail', $encodingProfile, '0');
     }
     foreach ($flavorAssets as $flavorAsset) {
         if ($flavorAsset->getFlavorParams()) {
             $encodingProfile = $flavorAsset->getFlavorParams()->getName();
         } else {
             $encodingProfile = 'Unknown';
         }
         $this->_enclosuresXmls[] = $this->createEnclosureXml($flavorAsset, 'content', $encodingProfile, round($entry->getDuration()));
     }
 }
Beispiel #4
0
 /**
  * @param array $values
  * @param array $flavorAssets
  * @param array $thumbAssets
  */
 public function getItem(array $values, entry $entry, array $flavorAssets = null, array $thumbAssets = null, array $additionalAssets = null)
 {
     $item = $this->item->cloneNode(true);
     kXml::setNodeValue($this->xpath, 'atom:title', $values[SynacorHboDistributionField::ENTRY_TITLE], $item);
     kXml::setNodeValue($this->xpath, 'atom:summary', $values[SynacorHboDistributionField::ENTRY_SUMMARY], $item);
     $updatedTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_UPDATED]);
     kXml::setNodeValue($this->xpath, 'atom:updated', $updatedTime, $item);
     kXml::setNodeValue($this->xpath, 'atom:author/atom:name', $values[SynacorHboDistributionField::ENTRY_AUTHOR_NAME], $item);
     $categoryValue = $values[SynacorHboDistributionField::ENTRY_CATEGORY_TERM];
     if (strlen($categoryValue) > 0) {
         kXml::setNodeValue($this->xpath, 'atom:category/@term', $categoryValue, $item);
     } else {
         $this->removeNode('atom:category', $item);
     }
     $genreValue = $values[SynacorHboDistributionField::ENTRY_GENRE_TERM];
     if (strlen($genreValue) > 0) {
         kXml::setNodeValue($this->xpath, 'atom:genre/@term', $genreValue, $item);
     } else {
         $this->removeNode('atom:genre', $item);
     }
     kXml::setNodeValue($this->xpath, 'atom:assetType', $values[SynacorHboDistributionField::ENTRY_ASSET_TYPE], $item);
     kXml::setNodeValue($this->xpath, 'atom:assetId', $values[SynacorHboDistributionField::ENTRY_ASSET_ID], $item);
     $startTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_OFFERING_START]);
     kXml::setNodeValue($this->xpath, 'atom:offering/atom:start', $startTime, $item);
     $endTime = $this->formatSynacorHboTime($values[SynacorHboDistributionField::ENTRY_OFFERING_END]);
     kXml::setNodeValue($this->xpath, 'atom:offering/atom:end', $endTime, $item);
     $ratingValue = $values[SynacorHboDistributionField::ENTRY_RATING];
     if (strlen($ratingValue) > 0) {
         kXml::setNodeValue($this->xpath, 'atom:rating', $ratingValue, $item);
         $ratingType = stripos($ratingValue, 'tv') === '0' ? 'tv' : 'theatrical';
         kXml::setNodeValue($this->xpath, 'atom:rating/@type', $ratingType, $item);
     } else {
         $this->removeNode('atom:rating', $item);
     }
     $durationInSeconds = ceil($entry->getDuration());
     $durationInMinuesRoundedUp = ceil($durationInSeconds / 60);
     kXml::setNodeValue($this->xpath, 'atom:runtime', $durationInMinuesRoundedUp, $item);
     kXml::setNodeValue($this->xpath, 'atom:runtime/@timeInSeconds', $durationInSeconds, $item);
     kXml::setNodeValue($this->xpath, 'go:series/go:title', $values[SynacorHboDistributionField::ENTRY_SERIES_TITLE], $item);
     kXml::setNodeValue($this->xpath, 'atom:brand', $values[SynacorHboDistributionField::ENTRY_BRAND], $item);
     if (!is_null($flavorAssets) && is_array($flavorAssets) && count($flavorAssets) > 0) {
         $flavorAsset = $flavorAssets[0];
         /* @var $flavorAsset flavorAsset */
         $flavorUrl = $this->getAssetUrl($flavorAsset);
         // we don't have a way to identify the mime type of the file
         // as there is no guarantee that the file exists in the current data center
         // so we will just use those hardcoded conditions
         $mimeType = '';
         switch ($flavorAsset->getFileExt()) {
             case 'flv':
                 $mimeType = 'video/x-flv';
                 break;
             case 'mp4':
                 $mimeType = 'video/mp4';
                 break;
             case 'mpeg':
             case 'mpg':
                 $mimeType = 'video/mpeg';
                 break;
             default:
                 $mimeType = 'video/x-flv';
                 // default requested by synacor
         }
         kXml::setNodeValue($this->xpath, 'atom:link[@type=\'VIDEO_MIME_TYPE\']/@href', $flavorUrl, $item);
         kXml::setNodeValue($this->xpath, 'atom:link[@type=\'VIDEO_MIME_TYPE\']/@type', $mimeType, $item);
     }
     if (!is_null($thumbAssets) && is_array($thumbAssets) && count($thumbAssets) > 0) {
         $thumbAsset = $thumbAssets[0];
         /* @var $thumbAssets thumbAssets */
         $thumbUrl = $this->getAssetUrl($thumbAsset);
         kXml::setNodeValue($this->xpath, 'atom:link[@type=\'image/jpeg\']/@href', $thumbUrl, $item);
     }
     if (is_array($additionalAssets)) {
         foreach ($additionalAssets as $additionalAsset) {
             /* @var $additionalAsset asset */
             $assetType = $additionalAsset->getType();
             switch ($assetType) {
                 case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION):
                     /* @var $captionPlugin CaptionPlugin */
                     $captionPlugin = KalturaPluginManager::getPluginInstance(CaptionPlugin::PLUGIN_NAME);
                     $dummyElement = new SimpleXMLElement('<dummy/>');
                     $captionPlugin->contributeCaptionAssets($additionalAsset, $dummyElement);
                     $dummyDom = dom_import_simplexml($dummyElement);
                     $captionDom = $dummyDom->getElementsByTagName('subTitle');
                     $captionDom = $this->doc->importNode($captionDom->item(0), true);
                     $captionDom = $item->appendChild($captionDom);
                     break;
                 case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT):
                     /* @var $attachmentPlugin AttachmentPlugin */
                     $attachmentPlugin = KalturaPluginManager::getPluginInstance(AttachmentPlugin::PLUGIN_NAME);
                     $dummyElement = new SimpleXMLElement('<dummy/>');
                     $attachmentPlugin->contributeAttachmentAssets($additionalAsset, $dummyElement);
                     $dummyDom = dom_import_simplexml($dummyElement);
                     $attachmentDom = $dummyDom->getElementsByTagName('attachment');
                     $attachmentDom = $this->doc->importNode($attachmentDom->item(0), true);
                     $attachmentDom = $item->appendChild($attachmentDom);
                     break;
             }
         }
     }
     return $item;
 }