public function execute()
 {
     $this->forceSystemAuthentication();
     myDbHelper::$use_alternative_con = null;
     //myDbHelper::DB_HELPER_CONN_PROPEL3;
     $entry_id = $this->getP("entry_id");
     echo "Creating new conversion profile for entry [{$entry_id}]<br>";
     $new_conversion_profile = myPartnerUtils::getConversionProfile2ForEntry($entry_id);
     echo "result:\n" . print_r($new_conversion_profile, true . "<br>");
     die;
 }
Пример #2
0
 public static function getReadyBehavior(flavorAsset $flavorAsset)
 {
     if ($flavorAsset->getIsOriginal()) {
         try {
             $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
             if ($profile) {
                 $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavorAsset->getFlavorParamsId(), $profile->getId());
                 if ($flavorParamsConversionProfile) {
                     return $flavorParamsConversionProfile->getReadyBehavior();
                 }
             }
         } catch (Exception $e) {
             KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
         }
     }
     $targetFlavor = flavorParamsOutputPeer::retrieveByFlavorAssetId($flavorAsset->getId());
     if ($targetFlavor) {
         return $targetFlavor->getReadyBehavior();
     }
     return flavorParamsConversionProfile::READY_BEHAVIOR_INHERIT_FLAVOR_PARAMS;
 }
Пример #3
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Пример #4
0
 /**
  * Convert entry
  * 
  * @param string $entryId Media entry id
  * @param int $conversionProfileId
  * @param KalturaConversionAttributeArray $dynamicConversionAttributes
  * @return bigint job id
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND
  * @throws KalturaErrors::FLAVOR_PARAMS_NOT_FOUND
  */
 protected function convert($entryId, $conversionProfileId = null, KalturaConversionAttributeArray $dynamicConversionAttributes = null)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (!$srcFlavorAsset) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     if (is_null($conversionProfileId) || $conversionProfileId <= 0) {
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
         if (!$conversionProfile) {
             throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
         }
         $conversionProfileId = $conversionProfile->getId();
     } else {
         //The search is with the entry's partnerId. so if conversion profile wasn't found it means that the
         //conversionId is not exist or the conversion profileId does'nt belong to this partner.
         $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId);
         if (is_null($conversionProfile)) {
             throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
         }
     }
     $srcSyncKey = $srcFlavorAsset->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);
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     } else {
         if (!$local) {
             kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync));
         }
     }
     // even if it null
     $entry->setConversionQuality($conversionProfileId);
     $entry->save();
     if ($dynamicConversionAttributes) {
         $flavors = assetParamsPeer::retrieveByProfile($conversionProfileId);
         if (!count($flavors)) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_NOT_FOUND);
         }
         $srcFlavorParamsId = null;
         $flavorParams = $entry->getDynamicFlavorAttributes();
         foreach ($flavors as $flavor) {
             if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
                 $srcFlavorParamsId = $flavor->getId();
             }
             $flavorParams[$flavor->getId()] = $flavor;
         }
         $dynamicAttributes = array();
         foreach ($dynamicConversionAttributes as $dynamicConversionAttribute) {
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 $dynamicConversionAttribute->flavorParamsId = $srcFlavorParamsId;
             }
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 continue;
             }
             $dynamicAttributes[$dynamicConversionAttribute->flavorParamsId][trim($dynamicConversionAttribute->name)] = trim($dynamicConversionAttribute->value);
         }
         if (count($dynamicAttributes)) {
             $entry->setDynamicFlavorAttributes($dynamicAttributes);
             $entry->save();
         }
     }
     $srcFilePath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey);
     $job = kJobsManager::addConvertProfileJob(null, $entry, $srcFlavorAsset->getId(), $srcFilePath);
     if (!$job) {
         return null;
     }
     return $job->getId();
 }
Пример #5
0
 /**
  * @param BatchJob $parentJob
  * @param int $srcParamsId
  */
 public static function generateThumbnailsFromFlavor($entryId, BatchJob $parentJob = null, $srcParamsId = null)
 {
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     } catch (Exception $e) {
         KalturaLog::err('getConversionProfile2ForEntry Error: ' . $e->getMessage());
     }
     if (!$profile) {
         KalturaLog::notice("Profile not found for entry id [{$entryId}]");
         return;
     }
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         KalturaLog::notice("Entry id [{$entryId}] not found");
         return;
     }
     $assetParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($profile->getId());
     if (!count($assetParamsIds)) {
         KalturaLog::notice("No asset params objects found for profile id [" . $profile->getId() . "]");
         return;
     }
     // the alternative is the source or the highest bitrate if source not defined
     $alternateFlavorParamsId = null;
     if (is_null($srcParamsId)) {
         $flavorParamsObjects = flavorParamsPeer::retrieveByPKs($assetParamsIds);
         foreach ($flavorParamsObjects as $flavorParams) {
             if ($flavorParams->hasTag(flavorParams::TAG_SOURCE)) {
                 $alternateFlavorParamsId = $flavorParams->getId();
             }
         }
         if (is_null($alternateFlavorParamsId)) {
             $srcFlavorAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entryId);
             $alternateFlavorParamsId = $srcFlavorAsset->getFlavorParamsId();
         }
         if (is_null($alternateFlavorParamsId)) {
             KalturaLog::notice("No source flavor params object found for entry id [{$entryId}]");
             return;
         }
     }
     // create list of created thumbnails
     $thumbAssetsList = array();
     $thumbAssets = thumbAssetPeer::retrieveByEntryId($entryId);
     if (count($thumbAssets)) {
         foreach ($thumbAssets as $thumbAsset) {
             if (!is_null($thumbAsset->getFlavorParamsId())) {
                 $thumbAssetsList[$thumbAsset->getFlavorParamsId()] = $thumbAsset;
             }
         }
     }
     $thumbParamsObjects = thumbParamsPeer::retrieveByPKs($assetParamsIds);
     foreach ($thumbParamsObjects as $thumbParams) {
         // check if this thumbnail already created
         if (isset($thumbAssetsList[$thumbParams->getId()])) {
             continue;
         }
         if (is_null($srcParamsId) && is_null($thumbParams->getSourceParamsId())) {
             // alternative should be used
             $thumbParams->setSourceParamsId($alternateFlavorParamsId);
         } elseif ($thumbParams->getSourceParamsId() != $srcParamsId) {
             // only thumbnails that uses srcParamsId should be generated for now
             continue;
         }
         kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams, $parentJob);
     }
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param flavorAsset $currentFlavorAsset
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob = null, flavorAsset $currentFlavorAsset)
 {
     KalturaLog::debug("entry id [" . $currentFlavorAsset->getEntryId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "]");
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($currentFlavorAsset->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $currentReadyBehavior = self::getReadyBehavior($currentFlavorAsset, $profile);
     KalturaLog::debug("Current ready behavior [{$currentReadyBehavior}]");
     if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
         return $dbBatchJob;
     }
     $rootBatchJob = null;
     if ($dbBatchJob) {
         $rootBatchJob = $dbBatchJob->getRootJob();
     }
     if ($rootBatchJob) {
         KalturaLog::debug("root batch job id [" . $rootBatchJob->getId() . "] type [" . $rootBatchJob->getJobType() . "]");
     }
     // update the root job end exit
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $siblingJobs = $rootBatchJob->getChildJobs();
         foreach ($siblingJobs as $siblingJob) {
             // checking only conversion child jobs
             if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::CONVERT_COLLECTION && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) {
                 continue;
             }
             // if not complete leave function
             if (!in_array($siblingJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
                 KalturaLog::debug("job id [" . $siblingJob->getId() . "] status [" . $siblingJob->getStatus() . "]");
                 return $dbBatchJob;
             }
         }
         KalturaLog::debug("finish bulk download root job");
         // all child jobs completed
         kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         return $dbBatchJob;
     }
     $inheritedFlavorParamsIds = array();
     $requiredFlavorParamsIds = array();
     $flavorParamsConversionProfileItems = array();
     if ($profile) {
         $flavorParamsConversionProfileItems = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     }
     foreach ($flavorParamsConversionProfileItems as $flavorParamsConversionProfile) {
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             $inheritedFlavorParamsIds[] = $flavorParamsConversionProfile->getFlavorParamsId();
         }
     }
     $flavorParamsItems = assetParamsPeer::retrieveByPKs($inheritedFlavorParamsIds);
     foreach ($flavorParamsItems as $flavorParams) {
         if ($flavorParams->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     // go over all the flavor assets of the entry
     $inCompleteFlavorIds = array();
     $origianlAssetFlavorId = null;
     $siblingFlavorAssets = assetPeer::retrieveFlavorsByEntryId($currentFlavorAsset->getEntryId());
     foreach ($siblingFlavorAssets as $siblingFlavorAsset) {
         KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] flavor params id [" . $siblingFlavorAsset->getFlavorParamsId() . "]");
         // don't mark any incomplete flag
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ready");
             if (isset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()])) {
                 unset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()]);
             }
             continue;
         }
         $readyBehavior = self::getReadyBehavior($siblingFlavorAsset, $profile);
         if ($siblingFlavorAsset->getStatus() == flavorAsset::ASSET_STATUS_EXPORTING) {
             if ($siblingFlavorAsset->getIsOriginal()) {
                 $origianlAssetFlavorId = $siblingFlavorAsset->getFlavorParamsId();
             } else {
                 if ($readyBehavior != flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
                     KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
                     $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
                 }
             }
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ignored");
             continue;
         }
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
             $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is required");
             $requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("left required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     KalturaLog::debug("left incomplete flavor ids [" . print_r($inCompleteFlavorIds, true) . "]");
     if (count($requiredFlavorParamsIds)) {
         $inCompleteRequiredFlavorParamsIds = array_keys($requiredFlavorParamsIds);
         foreach ($inCompleteRequiredFlavorParamsIds as $inCompleteFlavorId) {
             $inCompleteFlavorIds[] = $inCompleteFlavorId;
         }
         KalturaLog::debug('Convert Finished - has In-Complete Required flavors [[' . print_r($inCompleteRequiredFlavorParamsIds, true) . ']');
     } elseif ($currentFlavorAsset->getStatus() == asset::ASSET_STATUS_READY && ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL || $currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED)) {
         // mark the entry as ready if all required conversions completed or any of the optionals
         if ($currentFlavorAsset->getentry()->getReplacedEntryId()) {
             KalturaLog::debug('Entry is temporary replacement and requires all flavors to complete');
         } else {
             KalturaLog::debug('Mark the entry as ready');
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
         }
     }
     if ($origianlAssetFlavorId) {
         $inCompleteFlavorIds = array_diff($inCompleteFlavorIds, array($origianlAssetFlavorId));
     }
     if (!count($inCompleteFlavorIds)) {
         KalturaLog::debug('Convert Finished');
         if ($origianlAssetFlavorId && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             kStorageExporter::exportSourceAssetFromJob($rootBatchJob);
         } else {
             // mark the context root job as finished only if all conversion jobs are completed
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             }
         }
         return $dbBatchJob;
     }
     KalturaLog::debug('Convert Finished - has In-Complete flavors [' . print_r($inCompleteFlavorIds, true) . ']');
     if (!$rootBatchJob || $rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return $dbBatchJob;
     }
     $childJobs = $rootBatchJob->getChildJobs();
     KalturaLog::debug('Child jobs found [' . count($childJobs) . ']');
     if (count($childJobs) > 1) {
         $allDone = true;
         foreach ($childJobs as $childJob) {
             if ($childJob->getId() != $rootBatchJob->getId() && $childJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
                 KalturaLog::debug('Child job id [' . $childJob->getId() . '] status [' . $childJob->getStatus() . ']');
                 $allDone = false;
             }
         }
         if ($allDone) {
             KalturaLog::debug('All child jobs done, closing profile');
             kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         }
     }
     return $dbBatchJob;
 }
Пример #7
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     // gets the flavor params by the id
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     self::checkConvertProfileParams($flavors, $conversionProfileFlavorParams, $entry);
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     try {
         return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $profile->getId(), $mediaInfo);
     } catch (Exception $e) {
         KalturaLog::err('decideProfileFlavorsConvert - ' . $e->getMessage());
     }
 }
Пример #8
0
 public static function addExtractMediaJob(BatchJob $parentJob, $inputFileSyncLocalPath, $flavorAssetId)
 {
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($parentJob->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $mediaInfoEngine = mediaParserType::MEDIAINFO;
     if ($profile) {
         $mediaInfoEngine = $profile->getMediaParserType();
     }
     $extractMediaData = new kExtractMediaJobData();
     $srcFileSyncDescriptor = new kSourceFileSyncDescriptor();
     $srcFileSyncDescriptor->setFileSyncLocalPath($inputFileSyncLocalPath);
     $extractMediaData->setSrcFileSyncs(array($srcFileSyncDescriptor));
     $extractMediaData->setFlavorAssetId($flavorAssetId);
     $batchJob = $parentJob->createChild(BatchJobType::EXTRACT_MEDIA, $mediaInfoEngine, false);
     $batchJob->setObjectId($flavorAssetId);
     $batchJob->setObjectType(BatchJobObjectType::ASSET);
     KalturaLog::log("Creating Extract Media job, with source file: " . $extractMediaData->getSrcFileSyncLocalPath());
     return self::addJob($batchJob, $extractMediaData, BatchJobType::EXTRACT_MEDIA, $mediaInfoEngine);
 }
Пример #9
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;
 }
Пример #10
0
 private static function deleteTemporaryFlavors($entryId)
 {
     $originalflavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if ($originalflavorAsset && $originalflavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_TEMP) {
         $originalflavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalflavorAsset->setDeletedAt(time());
         $originalflavorAsset->save();
     }
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$conversionProfile) {
         return;
     }
     $criteria = new Criteria();
     $criteria->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
     $criteria->add(flavorParamsConversionProfilePeer::DELETE_POLICY, AssetParamsDeletePolicy::DELETE);
     $tempFlavorsParams = flavorParamsConversionProfilePeer::doSelect($criteria);
     foreach ($tempFlavorsParams as $tempFlavorsParam) {
         $tempFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $tempFlavorsParam->getFlavorParamsId());
         if ($tempFlavorAsset) {
             $tempFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
             $tempFlavorAsset->setDeletedAt(time());
             $tempFlavorAsset->save();
         }
     }
 }
Пример #11
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 = flavorAssetPeer::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);
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', $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();
         }
     }
     $entry->setLengthInMsecs($contentDuration);
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensions($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }
 /**
  * @param UploadToken $uploadToken
  */
 public static function handleUploadFailed(UploadToken $uploadToken)
 {
     $uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_DELETED);
     $uploadToken->save();
     if (is_subclass_of($uploadToken->getObjectType(), assetPeer::OM_CLASS)) {
         $dbAsset = assetPeer::retrieveById($uploadToken->getObjectId());
         if (!$dbAsset) {
             KalturaLog::err("Asset id [" . $uploadToken->getObjectId() . "] not found");
             return;
         }
         if ($dbAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING) {
             $dbAsset->setStatus(asset::ASSET_STATUS_ERROR);
             $dbAsset->save();
         }
         $profile = null;
         try {
             $profile = myPartnerUtils::getConversionProfile2ForEntry($dbAsset->getEntryId());
             KalturaLog::debug("profile [" . $profile->getId() . "]");
         } catch (Exception $e) {
             KalturaLog::err($e->getMessage());
             return;
         }
         $currentReadyBehavior = kBusinessPostConvertDL::getReadyBehavior($dbAsset, $profile);
         if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             kBatchManager::updateEntry($dbAsset->getEntryId(), entryStatus::ERROR_IMPORTING);
         }
         return;
     }
     if ($uploadToken->getObjectType() == entryPeer::OM_CLASS) {
         $dbEntry = entryPeer::retrieveByPK($uploadToken->getObjectId());
         if ($dbEntry && $dbEntry->getStatus() == entryStatus::IMPORT) {
             kBatchManager::updateEntry($dbEntry->getId(), entryStatus::ERROR_IMPORTING);
         }
     }
 }