public function toInsertableObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!is_null($this->thumbParamsId)) {
         $dbAssetParams = assetParamsPeer::retrieveByPK($this->thumbParamsId);
         if ($dbAssetParams) {
             $object_to_fill->setFromAssetParams($dbAssetParams);
         }
     }
     return parent::toInsertableObject($object_to_fill, $props_to_skip);
 }
Exemple #2
0
 /**
  * Creates new download job for multiple entry ids (comma separated), an email will be sent when the job is done
  * This sevice support the following entries: 
  * - MediaEntry
  * 	   - Video will be converted using the flavor params id
  *     - Audio will be downloaded as MP3
  *     - Image will be downloaded as Jpeg
  * - MixEntry will be flattened using the flavor params id
  * - Other entry types are not supported
  * 
  * Returns the admin email that the email message will be sent to 
  * 
  * @action xAddBulkDownload
  * @param string $entryIds Comma separated list of entry ids
  * @param string $flavorParamsId
  * @return string
  */
 public function xAddBulkDownloadAction($entryIds, $flavorParamsId = "")
 {
     $flavorParamsDb = null;
     if ($flavorParamsId !== null && $flavorParamsId != "") {
         $flavorParamsDb = assetParamsPeer::retrieveByPK($flavorParamsId);
         if (!$flavorParamsDb) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
         }
     }
     kJobsManager::addBulkDownloadJob($this->getPartnerId(), $this->getKuser()->getPuserId(), $entryIds, $flavorParamsId);
     return $this->getKuser()->getEmail();
 }
 public function toInsertableObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!is_null($this->captionParamsId)) {
         $dbAssetParams = assetParamsPeer::retrieveByPK($this->captionParamsId);
         if ($dbAssetParams) {
             $object_to_fill->setFromAssetParams($dbAssetParams);
         }
     }
     if ($this->format === null && $object_to_fill->getContainerFormat() === null) {
         $this->format = KalturaCaptionType::SRT;
     }
     return parent::toInsertableObject($object_to_fill, $props_to_skip);
 }
 /**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     $syndicationFeed->validateStorageId($this->getPartnerId());
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validatePropertyNotNull('xslt');
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->incrementVersion();
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->toInsertableObject($syndicationFeedDB);
     $syndicationFeedDB->setPartnerId($this->getPartnerId());
     $syndicationFeedDB->setStatus(KalturaSyndicationFeedStatus::ACTIVE);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $assetParams = assetParamsPeer::retrieveByPK($syndicationFeed->flavorParamId);
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             if ($assetParams) {
                 $fpc->setReadyBehavior($assetParams->getReadyBehavior());
                 $fpc->setSystemName($assetParams->getSystemName());
                 if ($assetParams->hasTag(assetParams::TAG_SOURCE) || $assetParams->hasTag(assetParams::TAG_INGEST)) {
                     $fpc->setOrigin(assetParamsOrigin::INGEST);
                 } else {
                     $fpc->setOrigin(assetParamsOrigin::CONVERT);
                 }
             }
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
 /**
  * batch decideAddEntryFlavor is the decision layer for adding a single flavor conversion to an entry
  *
  * @param BatchJob $parentJob
  * @param int $entryId
  * @param int $flavorParamsId
  * @param string $errDescription
  * @param string $flavorAssetId
  * @param array<kOperationAttributes> $dynamicAttributes
  * @return BatchJob
  */
 public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription, $flavorAssetId = null, array $dynamicAttributes = array(), $priority = 0)
 {
     KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]");
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         return null;
     }
     if ($originalFlavorAsset->getId() != $flavorAssetId && !$originalFlavorAsset->isLocalReadyStatus()) {
         $errDescription = 'Original flavor asset not ready';
         KalturaLog::err($errDescription);
         return null;
     }
     // TODO - if source flavor is remote storage, create import job and mark the flavor as FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT
     $mediaInfoId = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
     if (!$flavorParams) {
         KalturaLog::err("Flavor Params Id [{$flavorParamsId}] not found");
         return null;
     }
     $flavorParams->setDynamicAttributes($dynamicAttributes);
     self::adjustAssetParams($entryId, array($flavorParams));
     $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
     if (is_null($flavor)) {
         KalturaLog::err("Failed to validate media info [{$errDescription}]");
         return null;
     }
     if ($parentJob) {
         // prefer the partner id from the parent job, although it should be the same
         $partnerId = $parentJob->getPartnerId();
     } else {
         $partnerId = $originalFlavorAsset->getPartnerId();
     }
     if (is_null($flavorAssetId)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId);
         if ($flavorAsset) {
             $flavorAssetId = $flavorAsset->getId();
         }
     }
     $flavor->_force = true;
     // force to convert the flavor, even if none complied
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if ($conversionProfile) {
         $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor->getFlavorParamsId(), $conversionProfile->getId());
         if ($flavorParamsConversionProfile) {
             $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         }
     }
     $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId);
     if (!$flavorAsset) {
         return null;
     }
     if (!$flavorAsset->getIsOriginal()) {
         $flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE);
     }
     // should not be taken in completion rules check
     $flavorAssetId = $flavorAsset->getId();
     $collectionTag = $flavor->getCollectionTag();
     /*
      * CHANGE: collection porcessing only for ExpressionEncoder jobs
      * to allow FFmpeg/ISMV processing
      */
     KalturaLog::log("Check for collection case - asset(" . $flavorAssetId . "),engines(" . $flavor->getConversionEngines() . ")");
     if ($collectionTag && $flavor->getConversionEngines() == conversionEngineType::EXPRESSION_ENCODER3) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             throw new APIException(APIErrors::INVALID_ENTRY, $parentJob, $entryId);
         }
         $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entryId);
         $flavorAssets = assetPeer::filterByTag($flavorAssets, $collectionTag);
         $flavors = array();
         foreach ($flavorAssets as $tagedFlavorAsset) {
             $errDescription = null;
             if ($tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE || $tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
                 continue;
             }
             $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             if (is_null($flavorParamsOutput)) {
                 KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavorParams = assetParamsPeer::retrieveByPK($tagedFlavorAsset->getId());
                 self::adjustAssetParams($entryId, array($flavorParams));
                 $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
                 if (is_null($flavorParamsOutput)) {
                     KalturaLog::err("Failed to validate media info [{$errDescription}]");
                     continue;
                 }
             }
             if ($flavorParamsOutput) {
                 KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavors[$tagedFlavorAsset->getId()] = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             }
         }
         if ($flavorAssetId) {
             KalturaLog::log("Updating Collection flavor [" . $flavor->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
             $flavors[$flavorAssetId] = $flavor;
         }
         return self::decideCollectionConvert($collectionTag, $originalFlavorAsset, $entry, $parentJob, $flavors);
     } else {
         return self::decideFlavorConvert($flavorAsset, $flavor, $originalFlavorAsset, $conversionProfile->getId(), $mediaInfoId, $parentJob, null, false, $priority);
     }
 }
Exemple #6
0
 /**
  * @param flavorAsset $flavorAsset
  * @param SimpleXMLElement $mrss
  * @return SimpleXMLElement
  */
 protected static function appendFlavorAssetMrss(flavorAsset $flavorAsset, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null)
 {
     if (!$mrss) {
         $mrss = new SimpleXMLElement('<item/>');
     }
     $servePlayManifest = false;
     $playManifestClientTag = null;
     $storageId = null;
     if ($mrssParams) {
         $servePlayManifest = $mrssParams->getServePlayManifest();
         $playManifestClientTag = $mrssParams->getPlayManifestClientTag();
         $storageId = $mrssParams->getStorageId();
     }
     $content = $mrss->addChild('content');
     $content->addAttribute('url', kAssetUtils::getAssetUrl($flavorAsset, $servePlayManifest, $playManifestClientTag, $storageId));
     $content->addAttribute('flavorAssetId', $flavorAsset->getId());
     $content->addAttribute('isSource', $flavorAsset->getIsOriginal() ? 'true' : 'false');
     $content->addAttribute('containerFormat', $flavorAsset->getContainerFormat());
     $content->addAttribute('extension', $flavorAsset->getFileExt());
     $content->addAttribute('createdAt', $flavorAsset->getCreatedAt());
     // get the file size
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     $fileSize = $fileSync && $fileSync->getFileSize() > 0 ? $fileSync->getFileSize() : $flavorAsset->getSize() * 1024;
     $mediaParams = array('format' => $flavorAsset->getContainerFormat(), 'videoBitrate' => $flavorAsset->getBitrate(), 'fileSize' => $fileSize, 'videoCodec' => $flavorAsset->getVideoCodecId(), 'audioBitrate' => 0, 'audioCodec' => '', 'frameRate' => $flavorAsset->getFrameRate(), 'height' => $flavorAsset->getHeight(), 'width' => $flavorAsset->getWidth());
     if (!is_null($flavorAsset->getFlavorParamsId())) {
         $content->addAttribute('flavorParamsId', $flavorAsset->getFlavorParamsId());
         $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
         if ($flavorParams) {
             $content->addAttribute('flavorParamsName', $flavorParams->getName());
             $flavorParamsDetails = array('format' => $flavorParams->getFormat(), 'videoBitrate' => $flavorParams->getVideoBitrate(), 'videoCodec' => $flavorParams->getVideoCodec(), 'audioBitrate' => $flavorParams->getAudioBitrate(), 'audioCodec' => $flavorParams->getAudioCodec(), 'frameRate' => $flavorParams->getFrameRate(), 'height' => $flavorParams->getHeight(), 'width' => $flavorParams->getWidth());
             // merge the flavar param details with the flavor asset details
             // the flavor asset details take precedence whenever they exist
             $mediaParams = array_merge($flavorParamsDetails, array_filter($mediaParams));
         }
     }
     foreach ($mediaParams as $key => $value) {
         $content->addAttribute($key, $value);
     }
     $tags = $content->addChild('tags');
     foreach (explode(',', $flavorAsset->getTags()) as $tag) {
         $tags->addChild('tag', self::stringToSafeXml($tag));
     }
     if ($flavorAsset->hasTag(assetParams::TAG_SLWEB)) {
         self::addIsmLink($flavorAsset->getentry(), $mrss);
     }
 }
 /**
  * Delete Thumb Params by ID
  * 
  * @action delete
  * @param int $id
  */
 public function deleteAction($id)
 {
     $thumbParamsDb = assetParamsPeer::retrieveByPK($id);
     if (!$thumbParamsDb) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $id);
     }
     $thumbParamsDb->setDeletedAt(time());
     $thumbParamsDb->save();
 }
Exemple #8
0
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]");
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     $importingSources = false;
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) {
         KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist");
         $partner = $entry->getPartner();
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId());
         // load the asset params to the instance pool
         $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId());
         assetParamsPeer::retrieveByPKs($flavorIds);
         $conversionRequired = false;
         $sourceFileRequiredStorages = array();
         $sourceIncludedInProfile = false;
         $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId());
         KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]");
         foreach ($flavors as $flavor) {
             /* @var $flavor flavorParamsConversionProfile */
             if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source");
                 $sourceIncludedInProfile = true;
                 continue;
             }
             $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
             if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested");
                 continue;
             }
             if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
                 $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId());
                 if ($siblingFlavorAsset) {
                     KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested");
                     continue;
                 }
             }
             $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId();
             $conversionRequired = true;
             break;
         }
         if ($conversionRequired) {
             foreach ($sourceFileRequiredStorages as $storageId) {
                 if ($storageId == StorageProfile::STORAGE_KALTURA_DC) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false);
                     if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                         KalturaLog::debug("Creates import job for remote file sync");
                         $url = $syncFile->getExternalUrl($entry->getId());
                         kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true);
                         $importingSources = true;
                         continue;
                     }
                 } elseif ($flavorAsset->getExternalUrl($storageId)) {
                     continue;
                 }
                 kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING);
                 $flavorAsset = assetPeer::retrieveById($flavorAssetId);
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                 $flavorAsset->setDescription('Entry of size 0 should not be converted');
                 $flavorAsset->save();
                 KalturaLog::err('Entry of size 0 should not be converted');
                 return null;
             }
         } else {
             if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) {
                 if ($sourceIncludedInProfile) {
                     $flavorAsset->setStatusLocalReady();
                 } else {
                     $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED);
                     $flavorAsset->setDeletedAt(time());
                 }
                 $flavorAsset->save();
                 if ($sourceIncludedInProfile) {
                     kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset);
                 }
             }
             return null;
         }
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     $batchJob->setObjectId($entry->getId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     if ($importingSources) {
         $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
 /**
  * Retrieve a single object by pkey.
  *
  * @param      int $pk the primary key.
  * @param      PropelPDO $con the connection to use
  * @return     thumbParams
  */
 public static function retrieveByPK($pk, PropelPDO $con = null)
 {
     self::getInstance();
     return parent::retrieveByPK($pk, $con);
 }
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         $newConversionProfile->save();
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     $toPartner->save();
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
             $toPartner->save();
         }
     }
 }
 public function execute()
 {
     $this->forceSystemAuthentication();
     $this->pid = $this->getRequestParameter("pid", 0);
     if (!is_null($this->getRequestParameter("advanced"))) {
         $this->getResponse()->setCookie('flavor-params-advanced', $this->getRequestParameter("advanced"));
         $this->advanced = (int) $this->getRequestParameter("advanced");
     } else {
         $this->advanced = (int) $this->getRequest()->getCookie('flavor-params-advanced');
     }
     myDbHelper::$use_alternative_con = null;
     $this->editFlavorParam = null;
     $this->editFlavorParam = assetParamsPeer::retrieveByPK($this->getRequestParameter("id"));
     if ($this->getRequestParameter("clone")) {
         $newFalvorParams = $this->editFlavorParam->copy();
         $newFalvorParams->setSourceAssetParamsIds($this->editFlavorParam->getSourceAssetParamsIds());
         $newFalvorParams->setAspectRatioProcessingMode($this->editFlavorParam->getAspectRatioProcessingMode());
         $newFalvorParams->setForceFrameToMultiplication16($this->editFlavorParam->getForceFrameToMultiplication16());
         $newFalvorParams->setIsGopInSec($this->editFlavorParam->getIsGopInSec());
         $newFalvorParams->setIsAvoidVideoShrinkFramesizeToSource($this->editFlavorParam->getIsAvoidVideoShrinkFramesizeToSource());
         $newFalvorParams->setIsAvoidVideoShrinkBitrateToSource($this->editFlavorParam->getIsAvoidVideoShrinkBitrateToSource());
         $newFalvorParams->setIsVideoFrameRateForLowBrAppleHls($this->editFlavorParam->getIsVideoFrameRateForLowBrAppleHls());
         $newFalvorParams->setIsAvoidForcedKeyFrames($this->editFlavorParam->getIsAvoidForcedKeyFrames());
         $newFalvorParams->setMultiStream($this->editFlavorParam->getMultiStream());
         $newFalvorParams->setAnamorphicPixels($this->editFlavorParam->getAnamorphicPixels());
         $newFalvorParams->setMaxFrameRate($this->editFlavorParam->getMaxFrameRate());
         $newFalvorParams->setWatermarkData($this->editFlavorParam->getWatermarkData());
         $newFalvorParams->setIsDefault(false);
         $newFalvorParams->setPartnerId(-1);
         $newFalvorParams->save();
         $this->redirect("system/flavorParams?pid=" . $this->pid . "&id=" . $newFalvorParams->getId());
     }
     if ($this->getRequestParameter("delete")) {
         if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
             $this->editFlavorParam->setDeletedAt(time());
             $this->editFlavorParam->save();
         }
         $this->redirect("system/flavorParams?pid=" . $this->pid);
     }
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
             $partnerId = $this->getRequestParameter("partner-id");
             if ($this->advanced) {
                 $this->editFlavorParam->setPartnerId($partnerId);
             } else {
                 if ($partnerId != 0) {
                     $this->editFlavorParam->setPartnerId($partnerId);
                 }
             }
             if ($this->advanced >= 1) {
                 $this->editFlavorParam->setName($this->getRequestParameter("name"));
                 $this->editFlavorParam->setSystemName($this->getRequestParameter("systemName"));
                 $this->editFlavorParam->setDescription($this->getRequestParameter("description"));
                 $this->editFlavorParam->setIsDefault($this->getRequestParameter("is-default", false));
                 $this->editFlavorParam->setReadyBehavior($this->getRequestParameter("ready-behavior"));
                 $this->editFlavorParam->setTags($this->getRequestParameter("tags"));
                 $this->editFlavorParam->setSourceAssetParamsIds($this->getRequestParameter("sourceAssetParamsIds"));
                 $this->editFlavorParam->setFormat($this->getRequestParameter("format"));
                 $this->editFlavorParam->setTwoPass($this->getRequestParameter("two-pass", false));
                 $this->editFlavorParam->setRotate($this->getRequestParameter("rotate", false));
                 $this->editFlavorParam->setAspectRatioProcessingMode($this->getRequestParameter("aspectRatioProcessingMode", 0));
                 $this->editFlavorParam->setIsGopInSec($this->getRequestParameter("isGopInSec", 0));
                 $this->editFlavorParam->setForceFrameToMultiplication16($this->getRequestParameter("forceFrameToMultiplication16") ? "1" : "0");
                 $this->editFlavorParam->setIsAvoidVideoShrinkFramesizeToSource($this->getRequestParameter("isAvoidVideoShrinkFramesizeToSource", 0));
                 $this->editFlavorParam->setIsAvoidVideoShrinkBitrateToSource($this->getRequestParameter("isAvoidVideoShrinkBitrateToSource", 0));
                 $this->editFlavorParam->setIsVideoFrameRateForLowBrAppleHls($this->getRequestParameter("isVideoFrameRateForLowBrAppleHls", 0));
                 $this->editFlavorParam->setIsAvoidForcedKeyFrames($this->getRequestParameter("isAvoidForcedKeyFrames", 0));
                 $this->editFlavorParam->setMultiStream($this->getRequestParameter("multiStream", 0));
                 $this->editFlavorParam->setAnamorphicPixels($this->getRequestParameter("anamorphicPixels", 0));
                 $this->editFlavorParam->setWidth($this->getRequestParameter("width"));
                 $this->editFlavorParam->setHeight($this->getRequestParameter("height"));
                 $this->editFlavorParam->setVideoCodec($this->getRequestParameter("video-codec"));
                 $this->editFlavorParam->setVideoBitrate($this->getRequestParameter("video-bitrate"));
                 $this->editFlavorParam->setWatermarkData($this->getRequestParameter("watermarkData", 0));
                 $this->editFlavorParam->setFrameRate($this->getRequestParameter("frame-rate"));
                 $this->editFlavorParam->setMaxFrameRate($this->getRequestParameter("max-frame-rate"));
                 $this->editFlavorParam->setGopSize($this->getRequestParameter("gop-size"));
                 $this->editFlavorParam->setAudioCodec($this->getRequestParameter("audio-codec"));
                 $this->editFlavorParam->setAudioBitrate($this->getRequestParameter("audio-bitrate"));
                 $this->editFlavorParam->setAudioChannels($this->getRequestParameter("audio-channels"));
                 $this->editFlavorParam->setAudioSampleRate($this->getRequestParameter("audio-sample-rate"));
                 $this->editFlavorParam->setAudioResolution($this->getRequestParameter("audio-resolution"));
                 $this->editFlavorParam->setConversionEngines($this->getRequestParameter("conversion-engines"));
                 $this->editFlavorParam->setConversionEnginesExtraParams($this->getRequestParameter("conversion-engines-extra-params"));
                 $this->editFlavorParam->setOperators($this->getRequestParameter("operators"));
                 $this->editFlavorParam->setEngineVersion($this->getRequestParameter("engine-version"));
                 $this->editFlavorParam->setType($this->getRequestParameter("type"));
             }
             $this->editFlavorParam->save();
         }
         $this->redirect("system/flavorParams?pid=" . $this->editFlavorParam->getPartnerId());
     }
     $c = new Criteria();
     $c->add(assetParamsPeer::PARTNER_ID, array(0, $this->pid), Criteria::IN);
     $this->flavorParams = assetParamsPeer::doSelect($c);
     $this->formats = self::getEnumValues("flavorParams", "CONTAINER_FORMAT");
     $this->videoCodecs = self::getEnumValues("flavorParams", "VIDEO_CODEC");
     $this->audioCodecs = self::getEnumValues("flavorParams", "AUDIO_CODEC");
     $this->readyBehaviors = self::getEnumValues("flavorParamsConversionProfile", "READY_BEHAVIOR");
     $this->creationModes = self::getEnumValues("flavorParams", "CREATION_MODE");
 }
Exemple #12
0
 protected function attachRemoteAssetResource(entry $entry, kDistributionSubmitJobData $data)
 {
     $distributionProfile = DistributionProfilePeer::retrieveByPK($data->getDistributionProfileId());
     /* @var $distributionProfile UnicornDistributionProfile */
     $domainGuid = $distributionProfile->getDomainGuid();
     $applicationGuid = $distributionProfile->getAdFreeApplicationGuid();
     $assetParamsId = $distributionProfile->getRemoteAssetParamsId();
     $mediaItemGuid = $data->getRemoteId();
     $url = "{$domainGuid}/{$applicationGuid}/{$mediaItemGuid}/content.m3u8";
     $entry->setSource(KalturaSourceType::URL);
     $entry->save();
     $isNewAsset = false;
     $asset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $assetParamsId);
     if (!$asset) {
         $isNewAsset = true;
         $assetParams = assetParamsPeer::retrieveByPK($assetParamsId);
         $asset = assetPeer::getNewAsset($assetParams->getType());
         $asset->setPartnerId($entry->getPartnerId());
         $asset->setEntryId($entry->getId());
         $asset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED);
         $asset->setFlavorParamsId($assetParamsId);
         $asset->setFromAssetParams($assetParams);
         if ($assetParams->hasTag(assetParams::TAG_SOURCE)) {
             $asset->setIsOriginal(true);
         }
     }
     $asset->incrementVersion();
     $asset->setFileExt('m3u8');
     $asset->setStatus(asset::FLAVOR_ASSET_STATUS_READY);
     $asset->save();
     $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $storageProfile = StorageProfilePeer::retrieveByPK($distributionProfile->getStorageProfileId());
     $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $url, $storageProfile);
     if ($isNewAsset) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($asset));
     }
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($asset));
     kBusinessPostConvertDL::handleConvertFinished(null, $asset);
 }
 /**
  * batch decideAddEntryFlavor is the decision layer for adding a single flavor conversion to an entry 
  *
  * @param BatchJob $parentJob
  * @param int $entryId 
  * @param int $flavorParamsId
  * @param string $errDescription
  * @param string $flavorAssetId
  * @param array<kOperationAttributes> $dynamicAttributes
  * @return BatchJob 
  */
 public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription, $flavorAssetId = null, array $dynamicAttributes = array())
 {
     KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]");
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         return null;
     }
     if ($originalFlavorAsset->getId() != $flavorAssetId && !$originalFlavorAsset->isLocalReadyStatus()) {
         $errDescription = 'Original flavor asset not ready';
         KalturaLog::err($errDescription);
         return null;
     }
     // TODO - if source flavor is remote storage, create import job and mark the flavor as FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT
     $mediaInfoId = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
     if (!$flavorParams) {
         KalturaLog::err("Flavor Params Id [{$flavorParamsId}] not found");
         return null;
     }
     $flavorParams->setDynamicAttributes($dynamicAttributes);
     $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
     if (is_null($flavor)) {
         KalturaLog::err("Failed to validate media info [{$errDescription}]");
         return null;
     }
     if ($parentJob) {
         // prefer the partner id from the parent job, although it should be the same
         $partnerId = $parentJob->getPartnerId();
     } else {
         $partnerId = $originalFlavorAsset->getPartnerId();
     }
     if (is_null($flavorAssetId)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId);
         if ($flavorAsset) {
             $flavorAssetId = $flavorAsset->getId();
         }
     }
     $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $flavor->_force = true;
     // force to convert the flavor, even if none complied
     $flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE);
     // should not be taken in completion rules check
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if ($conversionProfile) {
         $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor->getFlavorParamsId(), $conversionProfile->getId());
         if ($flavorParamsConversionProfile) {
             $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         }
     }
     $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err("Failed to create flavor asset");
         return null;
     }
     $flavorAssetId = $flavorAsset->getId();
     $collectionTag = $flavor->getCollectionTag();
     if ($collectionTag) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             throw new APIException(APIErrors::INVALID_ENTRY, $parentJob, $entryId);
         }
         $dbConvertCollectionJob = null;
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild(false);
             $dbConvertCollectionJob->setEntryId($entryId);
             $dbConvertCollectionJob->save();
         }
         $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entryId);
         $flavorAssets = assetPeer::filterByTag($flavorAssets, $collectionTag);
         $flavors = array();
         foreach ($flavorAssets as $tagedFlavorAsset) {
             if ($tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE || $tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
                 continue;
             }
             $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             if (is_null($flavorParamsOutput)) {
                 KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavorParams = assetParamsPeer::retrieveByPK($tagedFlavorAsset->getId());
                 $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
                 if (is_null($flavorParamsOutput)) {
                     KalturaLog::err("Failed to validate media info [{$errDescription}]");
                     continue;
                 }
             }
             if ($flavorParamsOutput) {
                 KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavors[$tagedFlavorAsset->getId()] = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             }
         }
         if ($flavorAssetId) {
             KalturaLog::log("Updating Collection flavor [" . $flavor->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
             $flavors[$flavorAssetId] = $flavor;
         }
         switch ($collectionTag) {
             case flavorParams::TAG_ISM:
                 KalturaLog::log("Calling addConvertIsmCollectionJob with [" . count($flavors) . "] flavor params");
                 return kJobsManager::addConvertIsmCollectionJob($collectionTag, $srcSyncKey, $entry, $parentJob, $flavors, $dbConvertCollectionJob);
             default:
                 KalturaLog::log("Error: Invalid collection tag [{$collectionTag}]");
                 return null;
         }
     }
     $dbConvertFlavorJob = null;
     if ($parentJob) {
         $dbConvertFlavorJob = $parentJob->createChild(false);
         $dbConvertFlavorJob->setEntryId($entryId);
         $dbConvertFlavorJob->save();
     }
     return kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAsset->getId(), $mediaInfoId, $parentJob, null, $dbConvertFlavorJob);
 }
 /**
  * @param kAssetParamsResourceContainer $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  * @throws KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND
  */
 protected function attachAssetParamsResourceContainer(kAssetParamsResourceContainer $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $assetParams = assetParamsPeer::retrieveByPK($resource->getAssetParamsId());
     if (!$assetParams) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $resource->getAssetParamsId());
     }
     if (!$dbAsset) {
         $dbAsset = assetPeer::retrieveByEntryIdAndParams($dbEntry->getId(), $resource->getAssetParamsId());
     }
     $isNewAsset = false;
     if (!$dbAsset) {
         $isNewAsset = true;
         $dbAsset = assetPeer::getNewAsset($assetParams->getType());
         $dbAsset->setPartnerId($dbEntry->getPartnerId());
         $dbAsset->setEntryId($dbEntry->getId());
         $dbAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED);
         $dbAsset->setFlavorParamsId($resource->getAssetParamsId());
         $dbAsset->setFromAssetParams($assetParams);
         if ($assetParams->hasTag(assetParams::TAG_SOURCE)) {
             $dbAsset->setIsOriginal(true);
         }
     }
     $dbAsset->incrementVersion();
     $dbAsset->save();
     $dbAsset = $this->attachResource($resource->getResource(), $dbEntry, $dbAsset);
     if ($dbAsset && $isNewAsset && $dbAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_IMPORTING) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
     }
     return $dbAsset;
 }
 private function renderITunesFeed($state, $entry = null, $e = null, $moreItems = false)
 {
     switch ($state) {
         case self::STATE_HEADER:
             if (is_null($this->mimeType)) {
                 $flavor = assetParamsPeer::retrieveByPK($this->syndicationFeed->flavorParamId);
                 if (!$flavor) {
                     throw new Exception("flavor not found for id " . $this->syndicationFeed->flavorParamId);
                 }
                 switch ($flavor->getFormat()) {
                     case 'mp4':
                         $this->mimeType = 'video/mp4';
                         break;
                     case 'm4v':
                         $this->mimeType = 'video/x-m4v';
                         break;
                     case 'mov':
                         $this->mimeType = 'video/quicktime';
                         break;
                     default:
                         $this->mimeType = 'video/mp4';
                 }
             }
             $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId);
             header("content-type: text/xml; charset=utf-8");
             '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
             $this->writeOpenXmlNode('rss', 0, array('xmlns:itunes' => "http://www.itunes.com/dtds/podcast-1.0.dtd", 'version' => "2.0"));
             $this->writeOpenXmlNode('channel', 1);
             $this->writeFullXmlNode('title', $this->stringToSafeXml($this->syndicationFeed->name), 2);
             $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 2);
             $this->writeFullXmlNode('language', $this->syndicationFeed->language, 2);
             $this->writeFullXmlNode('copyright', $partner->getName(), 2);
             $this->writeFullXmlNode('itunes:subtitle', $this->syndicationFeed->name, 2);
             $this->writeFullXmlNode('itunes:author', $this->syndicationFeed->feedAuthor, 2);
             $this->writeFullXmlNode('itunes:summary', $this->syndicationFeed->feedDescription, 2);
             $this->writeFullXmlNode('description', $this->syndicationFeed->feedDescription, 2);
             $this->writeOpenXmlNode('itunes:owner', 2);
             $this->writeFullXmlNode('itunes:name', $this->syndicationFeed->ownerName, 3);
             $this->writeFullXmlNode('itunes:email', $this->syndicationFeed->ownerEmail, 3);
             $this->writeClosingXmlNode('itunes:owner', 2);
             if ($this->syndicationFeed->feedImageUrl) {
                 $this->writeOpenXmlNode('image', 2);
                 $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 3);
                 $this->writeFullXmlNode('url', $this->syndicationFeed->feedLandingPage, 3);
                 $this->writeFullXmlNode('title', $this->syndicationFeed->name, 3);
                 $this->writeClosingXmlNode('image', 2);
                 $this->writeFullXmlNode('itunes:image', '', 2, array('href' => $this->syndicationFeed->feedImageUrl));
             }
             $categories = explode(',', $this->syndicationFeed->categories);
             $catTree = array();
             foreach ($categories as $category) {
                 if (!$category) {
                     continue;
                 }
                 if (strpos($category, '/')) {
                     $category_parts = explode('/', $category);
                     $catTree[$category_parts[0]][] = $category_parts[1];
                 } else {
                     $this->writeFullXmlNode('itunes:category', '', 2, array('text' => $category));
                 }
             }
             foreach ($catTree as $topCat => $subCats) {
                 if (!$topCat) {
                     continue;
                 }
                 $this->writeOpenXmlNode('itunes:category', 2, array('text' => $topCat));
                 foreach ($subCats as $cat) {
                     if (!$cat) {
                         continue;
                     }
                     $this->writeFullXmlNode('itunes:category', '', 3, array('text' => $cat));
                 }
                 $this->writeClosingXmlNode('itunes:category', 2);
             }
             break;
         case self::STATE_BODY:
             $url = $this->getFlavorAssetUrl($e);
             $this->writeOpenXmlNode('item', 2);
             $this->writeFullXmlNode('title', $this->stringToSafeXml($e->name), 3);
             $this->writeFullXmlNode('link', $this->syndicationFeed->landingPage . $e->id, 3);
             $this->writeFullXmlNode('guid', $url, 3);
             $this->writeFullXmlNode('pubDate', date('r', $e->createdAt), 3);
             $this->writeFullXmlNode('description', $this->stringToSafeXml($e->description), 3);
             $enclosure_attr = array('url' => $url, 'type' => $this->mimeType);
             $this->writeFullXmlNode('enclosure', '', 3, $enclosure_attr);
             $kuser = $entry->getkuser();
             if ($kuser && $kuser->getScreenName()) {
                 $this->writeFullXmlNode('itunes:author', $this->stringToSafeXml($kuser->getScreenName()), 3);
             }
             if ($e->description) {
                 $this->writeFullXmlNode('itunes:subtitle', $this->stringToSafeXml($e->description), 3);
                 $this->writeFullXmlNode('itunes:summary', $this->stringToSafeXml($e->description), 3);
             }
             $this->writeFullXmlNode('itunes:duration', $this->secondsToWords($e->duration), 3);
             $this->writeFullXmlNode('itunes:explicit', $this->syndicationFeed->adultContent, 3);
             $this->writeFullXmlNode('itunes:image', '', 3, array('href' => $e->thumbnailUrl . '/width/600/height/600/ext.jpg'));
             if ($e->tags) {
                 $this->writeFullXmlNode('itunes:keywords', $this->stringToSafeXml($e->tags), 3);
             }
             $this->writeClosingXmlNode('item', 2);
             break;
         case self::STATE_FOOTER:
             $this->writeClosingXmlNode('channel', 1);
             $this->writeClosingXmlNode('rss');
             break;
     }
 }
 /**
  * Add and convert new Flavor Asset for Entry with specific Flavor Params
  * 
  * @action convert
  * @param string $entryId
  * @param int $flavorParamsId
  * @param int $priority
  * @validateUser entry entryId edit
  */
 public function convertAction($entryId, $flavorParamsId, $priority = 0)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $flavorParamsDb = assetParamsPeer::retrieveByPK($flavorParamsId);
     assetParamsPeer::setUseCriteriaFilter(false);
     if (!$flavorParamsDb) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
     }
     $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY);
     if (!in_array($dbEntry->getStatus(), $validStatuses)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS);
     }
     $conversionProfile = $dbEntry->getconversionProfile2();
     if (!$conversionProfile) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $dbEntry->getConversionProfileId());
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset) || !$originalFlavorAsset->isLocalReadyStatus()) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     /* @var $fileSync FileSync */
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     if (!$local && $fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
         kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync));
     }
     $err = "";
     $dynamicFlavorAttributes = $dbEntry->getDynamicFlavorAttributesForAssetParams($flavorParamsDb->getId());
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err, null, $dynamicFlavorAttributes, $priority);
 }
 /**
  * @param flavorAsset $flavorAsset
  * @param SimpleXMLElement $mrss
  * @return SimpleXMLElement
  */
 protected static function appendFlavorAssetMrss(flavorAsset $flavorAsset, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null)
 {
     if (!$mrss) {
         $mrss = new SimpleXMLElement('<item/>');
     }
     $content = $mrss->addChild('content');
     $content->addAttribute('url', self::getAssetUrl($flavorAsset, $mrssParams ? $mrssParams->getStorageId() : null));
     $content->addAttribute('flavorAssetId', $flavorAsset->getId());
     $content->addAttribute('isSource', $flavorAsset->getIsOriginal() ? 'true' : 'false');
     $content->addAttribute('containerFormat', $flavorAsset->getContainerFormat());
     $content->addAttribute('extension', $flavorAsset->getFileExt());
     $content->addAttribute('createdAt', $flavorAsset->getCreatedAt());
     $mediaParams = array('format' => $flavorAsset->getContainerFormat(), 'videoBitrate' => $flavorAsset->getBitrate(), 'fileSize' => $flavorAsset->getSize() * 1024, 'videoCodec' => $flavorAsset->getVideoCodecId(), 'audioBitrate' => 0, 'audioCodec' => '', 'frameRate' => $flavorAsset->getFrameRate(), 'height' => $flavorAsset->getHeight(), 'width' => $flavorAsset->getWidth());
     if (!is_null($flavorAsset->getFlavorParamsId())) {
         $content->addAttribute('flavorParamsId', $flavorAsset->getFlavorParamsId());
         $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
         if ($flavorParams) {
             $content->addAttribute('flavorParamsName', $flavorParams->getName());
             $flavorParamsDetails = array('format' => $flavorParams->getFormat(), 'videoBitrate' => $flavorParams->getVideoBitrate(), 'videoCodec' => $flavorParams->getVideoCodec(), 'audioBitrate' => $flavorParams->getAudioBitrate(), 'audioCodec' => $flavorParams->getAudioCodec(), 'frameRate' => $flavorParams->getFrameRate(), 'height' => $flavorParams->getHeight(), 'width' => $flavorParams->getWidth());
             // merge the flavar param details with the flavor asset details
             // the flavor asset details take precedence whenever they exist
             $mediaParams = array_merge($flavorParamsDetails, array_filter($mediaParams));
         }
     }
     foreach ($mediaParams as $key => $value) {
         $content->addAttribute($key, $value);
     }
     $tags = $content->addChild('tags');
     foreach (explode(',', $flavorAsset->getTags()) as $tag) {
         $tags->addChild('tag', self::stringToSafeXml($tag));
     }
     if ($flavorAsset->hasTag(assetParams::TAG_SLWEB)) {
         self::addIsmLink($flavorAsset->getentry(), $mrss);
     }
 }
<?php

ini_set("memory_limit", "256M");
require_once 'bootstrap.php';
if ($argc == 3) {
    $assetParamsId = $argv[1];
    $permissionName = $argv[2];
} else {
    die('usage: php ' . $_SERVER['SCRIPT_NAME'] . " [asset_params_id] [permission_name]" . PHP_EOL);
}
$assetParams = assetParamsPeer::retrieveByPK($assetParamsId);
if (!$assetParams) {
    die('Asset params id ' . $assetParamsId . ' not found');
}
$requiredPermissions = $assetParams->getRequiredPermissions();
if (is_null($requiredPermissions)) {
    $requiredPermissions = array();
}
$requiredPermissions[] = $permissionName;
$assetParams->setRequiredPermissions($requiredPermissions);
$assetParams->save();
 /**
  * Getting name of flavor parameters
  * @return string|null Flavor parameters name or error
  */
 public function getFlavorParamsName()
 {
     $flavorParamsId = $this->getFlavorParamsId();
     if (is_null($flavorParamsId) && $this->getIsOriginal()) {
         $flavorParamsId = 0;
     }
     $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
     if ($flavorParams) {
         return $flavorParams->getName();
     }
     return null;
 }
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         /* @var $conversionProfile conversionProfile2 */
         if ($permissionRequiredOnly && !count($conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!self::isPartnerPermittedForCopy($toPartner, $conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         try {
             $newConversionProfile->save();
         } catch (Exception $e) {
             KalturaLog::info("Exception occured, conversion profile was not copied. Message: [" . $e->getMessage() . "]");
             continue;
         }
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
         }
     }
     if (!$toPartner->getDefaultLiveConversionProfileId()) {
         $fromPartnerDefaultLiveProfile = $fromPartner->getDefaultLiveConversionProfileId();
         if ($fromPartnerDefaultLiveProfile && key_exists($fromPartnerDefaultLiveProfile, $copiedList)) {
             $toPartner->setDefaultLiveConversionProfileId($copiedList[$fromPartnerDefaultLiveProfile]);
         }
     }
     $toPartner->save();
 }
Exemple #21
0
 public function handleHeader()
 {
     if (is_null($this->mimeType)) {
         $flavor = assetParamsPeer::retrieveByPK($this->syndicationFeed->flavorParamId);
         if (!$flavor) {
             throw new Exception("flavor not found for id " . $this->syndicationFeed->flavorParamId);
         }
         switch ($flavor->getFormat()) {
             case 'mp4':
                 $this->mimeType = 'video/mp4';
                 break;
             case 'mp3':
                 $this->mimeType = 'audio/mp3';
                 break;
             case 'm4v':
                 $this->mimeType = 'video/x-m4v';
                 break;
             case 'mov':
                 $this->mimeType = 'video/quicktime';
                 break;
             default:
                 $this->mimeType = 'video/mp4';
         }
     }
     $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId);
     $res = '';
     $res .= $this->writeOpenXmlNode('rss', 0, array('xmlns:itunes' => "http://www.itunes.com/dtds/podcast-1.0.dtd", 'version' => "2.0"));
     $res .= $this->writeOpenXmlNode('channel', 1);
     $res .= $this->writeFullXmlNode('title', $this->stringToSafeXml($this->syndicationFeed->name), 2);
     $res .= $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 2);
     $res .= $this->writeFullXmlNode('language', $this->syndicationFeed->language, 2);
     $res .= $this->writeFullXmlNode('copyright', $partner->getName(), 2);
     $res .= $this->writeFullXmlNode('itunes:subtitle', $this->syndicationFeed->name, 2);
     $res .= $this->writeFullXmlNode('itunes:author', $this->syndicationFeed->feedAuthor, 2);
     $res .= $this->writeFullXmlNode('itunes:summary', $this->syndicationFeed->feedDescription, 2);
     $res .= $this->writeFullXmlNode('description', $this->syndicationFeed->feedDescription, 2);
     $res .= $this->writeOpenXmlNode('itunes:owner', 2);
     $res .= $this->writeFullXmlNode('itunes:name', $this->syndicationFeed->ownerName, 3);
     $res .= $this->writeFullXmlNode('itunes:email', $this->syndicationFeed->ownerEmail, 3);
     $res .= $this->writeClosingXmlNode('itunes:owner', 2);
     if ($this->syndicationFeed->feedImageUrl) {
         $res .= $this->writeOpenXmlNode('image', 2);
         $res .= $this->writeFullXmlNode('link', $this->syndicationFeed->feedLandingPage, 3);
         $res .= $this->writeFullXmlNode('url', $this->syndicationFeed->feedLandingPage, 3);
         $res .= $this->writeFullXmlNode('title', $this->syndicationFeed->name, 3);
         $res .= $this->writeClosingXmlNode('image', 2);
         $res .= $this->writeFullXmlNode('itunes:image', '', 2, array('href' => $this->syndicationFeed->feedImageUrl));
     }
     $categories = explode(',', $this->syndicationFeed->categories);
     $catTree = array();
     foreach ($categories as $category) {
         if (!$category) {
             continue;
         }
         if (strpos($category, '/')) {
             $category_parts = explode('/', $category);
             $catTree[$category_parts[0]][] = $category_parts[1];
         } else {
             $res .= $this->writeFullXmlNode('itunes:category', '', 2, array('text' => $category));
         }
     }
     foreach ($catTree as $topCat => $subCats) {
         if (!$topCat) {
             continue;
         }
         $res .= $this->writeOpenXmlNode('itunes:category', 2, array('text' => $topCat));
         foreach ($subCats as $cat) {
             if (!$cat) {
                 continue;
             }
             $res .= $this->writeFullXmlNode('itunes:category', '', 3, array('text' => $cat));
         }
         $res .= $this->writeClosingXmlNode('itunes:category', 2);
     }
     return $res;
 }
Exemple #22
0
$readyBehavior = 2;
$isDefault = false;
$width = 0;
$height = 0;
$resolution = null;
$paperWidth = null;
$paperHeight = null;
$isReadonly = true;
/**************************************************
 * DON'T TOUCH THE FOLLOWING CODE
 ***************************************************/
chdir(dirname(__FILE__));
require_once __DIR__ . '/../../bootstrap.php';
$flavorParams = null;
if ($flavorParamsId) {
    $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
    if (!$flavorParams instanceof PdfFlavorParams) {
        echo "Flavor params id [{$flavorParamsId}] is not PDF flavor params\n";
        exit;
    }
    $flavorParams->setVersion($flavorParams->getVersion() + 1);
} else {
    $flavorParams = new PdfFlavorParams();
    $flavorParams->setVersion(1);
    $flavorParams->setFormat(flavorParams::CONTAINER_FORMAT_PDF);
    $flavorParams->setVideoBitrate(1);
}
$pdfOperator = new kOperator();
$pdfOperator->id = conversionEngineType::PDF_CREATOR;
$operators = new kOperatorSets();
$operators->addSet(array($pdfOperator));
 /**
  * @action regenerate
  * @param string $thumbAssetId
  * @return KalturaThumbAsset
  * 
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED
  * @throws KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED
  * @throws KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND
  * @throws KalturaErrors::INVALID_ENTRY_STATUS
  * @validateUser asset::entry thumbAssetId edit
  */
 public function regenerateAction($thumbAssetId)
 {
     $thumbAsset = assetPeer::retrieveById($thumbAssetId);
     if (!$thumbAsset || !$thumbAsset instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId);
     }
     if (is_null($thumbAsset->getFlavorParamsId())) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, null);
     }
     $destThumbParams = assetParamsPeer::retrieveByPK($thumbAsset->getFlavorParamsId());
     if (!$destThumbParams) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, $thumbAsset->getFlavorParamsId());
     }
     $entry = $thumbAsset->getentry();
     if (!in_array($entry->getType(), $this->mediaTypes)) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED, $entry->getType());
     }
     if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED, $entry->getMediaType());
     }
     $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY);
     if (!in_array($entry->getStatus(), $validStatuses)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS);
     }
     $dbThumbAsset = kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams);
     if (!$dbThumbAsset) {
         return null;
     }
     $thumbAsset = new KalturaThumbAsset();
     $thumbAsset->fromObject($dbThumbAsset);
     return $thumbAsset;
 }
Exemple #24
0
 public function getDynamicFlavorAttributesForAssetParams($assetParamsId)
 {
     // set dynamic flavor attributes
     $dynamicFlavorAttributes = array();
     $dynamicEntryAttributes = $this->getDynamicFlavorAttributes();
     // dynamic attributes for all entry flavors
     // if dynamic attributes are set for this specific flavor - use them
     if (isset($dynamicEntryAttributes[$assetParamsId])) {
         $dynamicFlavorAttributes = $dynamicEntryAttributes[$assetParamsId];
     } else {
         if (isset($dynamicEntryAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX])) {
             $assetParamsDb = assetParamsPeer::retrieveByPK($assetParamsId);
             if (!$assetParamsDb->hasTag(flavorParams::TAG_SOURCE)) {
                 $dynamicFlavorAttributes = $dynamicEntryAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX];
             }
         }
     }
     return $dynamicFlavorAttributes;
 }
Exemple #25
0
 /**
  * batch addMediaInfo adds a media info and updates the flavor asset 
  * 
  * @param mediaInfo $mediaInfoDb  
  * @return mediaInfo 
  */
 public static function addMediaInfo(mediaInfo $mediaInfoDb)
 {
     $mediaInfoDb->save();
     KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]");
     if (!$mediaInfoDb->getFlavorAssetId()) {
         return $mediaInfoDb;
     }
     $flavorAsset = assetPeer::retrieveById($mediaInfoDb->getFlavorAssetId());
     if (!$flavorAsset) {
         return $mediaInfoDb;
     }
     if ($flavorAsset->getIsOriginal()) {
         KalturaLog::log("Media info is for the original flavor asset");
         $tags = null;
         $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
         if ($profile) {
             $tags = $profile->getInputTagsMap();
         }
         KalturaLog::log("Flavor asset tags from profile [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             // support for old migrated profiles
             if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
                 if (!KDLWrap::CDLIsFLV($mediaInfoDb)) {
                     $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                     if ($key !== false) {
                         unset($tagsArray[$key]);
                     }
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             //KalturaLog::log("Flavor asset tags [".print_r($flavorAsset->setTags(),1)."]");
             $flavorAsset->addTags($finalTagsArray);
         }
     } else {
         KalturaLog::log("Media info is for the destination flavor asset");
         $tags = null;
         $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
         if ($flavorParams) {
             $tags = $flavorParams->getTags();
         }
         KalturaLog::log("Flavor asset tags from flavor params [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             $assetTagsArray = $flavorAsset->getTagsArray();
             foreach ($assetTagsArray as $tag) {
                 $tagsArray[] = $tag;
             }
             $maxMbrBitrate = 8000;
             if (kConf::hasParam('max_mbr_flavor_bitrate')) {
                 $maxMbrBitrate = kConf::get('max_mbr_flavor_bitrate');
             }
             if ($mediaInfoDb->getContainerBitRate() >= $maxMbrBitrate) {
                 $tagsArray = array_unique($tagsArray);
                 $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                 if ($key !== false) {
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = $tagsArray;
             //				bypass, KDLWrap::CDLMediaInfo2Tags doesn't support destination flavors and mobile tags
             //				$finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             $flavorAsset->setTags($finalTags);
         }
     }
     KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");");
     KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset);
     $flavorAsset->save();
     //		if(!$flavorAsset->hasTag(flavorParams::TAG_MBR))
     //			return $mediaInfoDb;
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (!$entry) {
         return $mediaInfoDb;
     }
     $contentDuration = $mediaInfoDb->getContainerDuration();
     if (!$contentDuration) {
         $contentDuration = $mediaInfoDb->getVideoDuration();
         if (!$contentDuration) {
             $contentDuration = $mediaInfoDb->getAudioDuration();
         }
     }
     if ($contentDuration && $entry->getCalculateDuration()) {
         $entry->setLengthInMsecs($contentDuration);
     }
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensionsIfBigger($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }