/** * Add flavor asset * * @action add * @param string $entryId * @param KalturaFlavorAsset $flavorAsset * @return KalturaFlavorAsset * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::FLAVOR_ASSET_ALREADY_EXISTS * @validateUser entry entryId edit */ function addAction($entryId, KalturaFlavorAsset $flavorAsset) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP || !in_array($dbEntry->getMediaType(), array(KalturaMediaType::VIDEO, KalturaMediaType::AUDIO))) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } if (!is_null($flavorAsset->flavorParamsId)) { $dbFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorAsset->flavorParamsId); if ($dbFlavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ALREADY_EXISTS, $dbFlavorAsset->getId(), $flavorAsset->flavorParamsId); } } if (!is_null($flavorAsset->flavorParamsId)) { $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->flavorParamsId); } $type = null; if ($flavorParams) { $type = $flavorParams->getType(); } $dbFlavorAsset = flavorAsset::getInstance($type); $dbFlavorAsset = $flavorAsset->toInsertableObject($dbFlavorAsset); /* @var $dbFlavorAsset flavorAsset */ if ($flavorParams && $flavorParams->hasTag(flavorParams::TAG_SOURCE)) { $dbFlavorAsset->setIsOriginal(true); } $dbFlavorAsset->setEntryId($entryId); $dbFlavorAsset->setPartnerId($dbEntry->getPartnerId()); $dbFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED); $dbFlavorAsset->save(); $flavorAsset = KalturaFlavorAsset::getInstance($dbFlavorAsset, $this->getResponseProfile()); return $flavorAsset; }
protected function addFlavorByMsnId(array &$flavorAssetsByMsnId, $msnId, $entryId, $flavorAssetId) { if ($flavorAssetId != -1) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorAssetId); if ($flavorAsset) { $flavorAssetsByMsnId[$msnId] = $flavorAsset; } } }
/** * * @param $version * @param $format * @return FileSync */ public function getDownloadFileSyncAndLocal($version = NULL, $format = null, $sub_type = null) { $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($this->getPartnerId(), $format); if (!$flavorParams) { return null; } $flavorAssets = assetPeer::retrieveByEntryIdAndParams($this->getId(), $flavorParams->getId()); if (!$flavorAssets) { return null; } $syncKey = $flavorAssets->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!$syncKey) { return null; } return kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); }
/** * batch createFlavorAsset orgenize a convert job data * * @param flavorParamsOutputWrap $flavor * @param int $partnerId * @param int $entryId * @param string $description * @return flavorAsset */ public static function createErrorFlavorAsset(flavorParamsOutputWrap $flavor, $partnerId, $entryId, $description) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavor->getFlavorParamsId()); if ($flavorAsset) { $description = $flavorAsset->getDescription() . "\n" . $description; $flavorAsset->setDescription($description); // $flavorAsset->incrementVersion(); } else { // creates the flavor asset $flavorAsset = flavorAsset::getInstance($flavor->getType()); $flavorAsset->setPartnerId($partnerId); $flavorAsset->setEntryId($entryId); $flavorAsset->setDescription($description); } $flavorAsset->setTags($flavor->getTags()); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->setFlavorParamsId($flavor->getFlavorParamsId()); $flavorAsset->setFileExt($flavor->getFileExt()); $flavorAsset->save(); // save flavor params $flavor->setPartnerId($partnerId); $flavor->setEntryId($entryId); $flavor->setFlavorAssetId($flavorAsset->getId()); $flavor->setFlavorAssetVersion($flavorAsset->getVersion()); $flavor->save(); return $flavorAsset; }
/** * Serves the file content * * @action serveByFlavorParamsId * @param string $entryId Document entry id * @param string $flavorParamsId Flavor params id * @param bool $forceProxy force to get the content without redirect * @return file * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND */ public function serveByFlavorParamsIdAction($entryId, $flavorParamsId = null, $forceProxy = false) { // temporary workaround for getting the referrer from a url with the format ....&forceProxy/true/referrer/... $referrer = null; if (isset($_GET["forceProxy"]) && kString::beginsWith($_GET["forceProxy"], "true/referrer/")) { $referrer = substr($_GET["forceProxy"], strlen("true/referrer/")); $referrer = base64_decode($referrer); } KalturaResponseCacher::disableCache(); myPartnerUtils::resetPartnerFilter('entry'); $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != entryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $ksObj = $this->getKs(); $ks = $ksObj ? $ksObj->getOriginalString() : null; $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, $referrer, ContextType::DOWNLOAD); $securyEntryHelper->validateForDownload(); $flavorAsset = null; if ($flavorParamsId) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorParamsId); } } else { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId); } } if (!$securyEntryHelper->isAssetAllowed($flavorAsset)) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId); } $fileName = $dbEntry->getName() . '.' . $flavorAsset->getFileExt(); return $this->serveFlavorAsset($flavorAsset, $fileName, $forceProxy); }
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); }
/** * decideThumbGenerate is the decision layer for a single thumbnail generation * * @param entry $entry * @param thumbParams $destThumbParams * @param BatchJob $parentJob * @return thumbAsset */ public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false) { $srcAsset = null; assetPeer::resetInstanceCriteriaFilter(); if ($sourceAssetId) { $srcAsset = assetPeer::retrieveById($sourceAssetId); } else { if ($destThumbParams->getSourceParamsId()) { KalturaLog::debug("Look for flavor params [" . $destThumbParams->getSourceParamsId() . "]"); $srcAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getSourceParamsId()); } if (is_null($srcAsset)) { KalturaLog::debug("Look for original flavor"); $srcAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); } if (is_null($srcAsset) || $srcAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::debug("Look for highest bitrate flavor"); $srcAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId()); } } if (is_null($srcAsset)) { throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY); } $errDescription = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription); $thumbAsset = thumbAssetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId()); if ($thumbAsset) { $description = $thumbAsset->getDescription() . "\n" . $errDescription; $thumbAsset->setDescription($description); } else { $thumbAsset = new thumbAsset(); $thumbAsset->setPartnerId($entry->getPartnerId()); $thumbAsset->setEntryId($entry->getId()); $thumbAsset->setDescription($errDescription); $thumbAsset->setFlavorParamsId($destThumbParams->getId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); $thumbAsset->setTags($destThumbParamsOutput->getTags()); $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt()); if (!$destThumbParamsOutput) { $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); return null; } $thumbAsset->save(); // save flavor params $destThumbParamsOutput->setPartnerId($entry->getPartnerId()); $destThumbParamsOutput->setEntryId($entry->getId()); $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId()); $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion()); $destThumbParamsOutput->save(); $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcAssetType = $srcAsset->getType(); if (!$runSync) { $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAssetType, $destThumbParamsOutput); return $thumbAsset; } $errDescription = null; $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription); // failed if (!$capturedPath) { $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}"); $thumbAsset->save(); return $thumbAsset; } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); if (file_exists($capturedPath)) { list($width, $height, $type, $attr) = getimagesize($capturedPath); $thumbAsset->setWidth($width); $thumbAsset->setHeight($height); $thumbAsset->setSize(filesize($capturedPath)); } $logPath = $capturedPath . '.log'; if (file_exists($logPath)) { $thumbAsset->incLogFileVersion(); $thumbAsset->save(); // creats the file sync $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); kFileSyncUtils::moveFromFile($logPath, $logSyncKey); KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey)); } else { $thumbAsset->save(); } $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($capturedPath, $syncKey); KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { // increment thumbnail version $entry->setThumbnail(".jpg"); $entry->save(); $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey, false); if ($syncFile) { // removes the DEFAULT_THUMB tag from all other thumb assets $entryThumbAssets = thumbAssetPeer::retrieveByEntryId($thumbAsset->getEntryId()); foreach ($entryThumbAssets as $entryThumbAsset) { if ($entryThumbAsset->getId() == $thumbAsset->getId()) { continue; } if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { continue; } $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB)); $entryThumbAsset->save(); } } } if (!is_null($thumbAsset->getFlavorParamsId())) { kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId()); } return $thumbAsset; }
/** * 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 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); }
public function execute() { requestUtils::handleConditionalGet(); $entry_id = $this->getRequestParameter("entry_id"); $ks_str = $this->getRequestParameter("ks"); $base64_referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64_referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $clip_from = $this->getRequestParameter("clip_from", 0); // milliseconds $clip_to = $this->getRequestParameter("clip_to", 2147483647); // milliseconds if ($clip_to == 0) { $clip_to = 2147483647; } $request = $_SERVER["REQUEST_URI"]; // remove dynamic fields from the url so we'll request a single url from the cdn $request = str_replace("/referrer/{$base64_referrer}", "", $request); $request = str_replace("/ks/{$ks_str}", "", $request); $entry = null; if ($ks_str) { try { kCurrentContext::initKsPartnerUser($ks_str); } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS); } } else { $entry = kCurrentContext::initPartnerByEntryId($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } kEntitlementUtils::initEntitlementEnforcement(); // workaround the filter which hides all the deleted entries - // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here if (!$entry) { $entry = entryPeer::retrieveByPKNoFilter($entry_id); } else { if (!kEntitlementUtils::isEntryEntitled($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'keditorservices.flvclipper', $entry->getPartnerId()); myPartnerUtils::blockInactivePartner($entry->getPartnerId()); if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_BLOCK_FLVCLIPPER_ACTION, $entry->getPartnerId())) { KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED); } // set the memory size to be able to serve big files in a single chunk ini_set("memory_limit", "64M"); // set the execution time to be able to serve big files in a single chunk ini_set("max_execution_time", 240); if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) { // because the fiter was turned off - a manual check for deleted entries must be done. KExternalErrors::dieGracefully(); } else { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $version = $this->getRequestParameter("version", null); $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); $crop_provider = $this->getRequestParameter("crop_provider", null); $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $type = $this->getRequestParameter("type", 1); $quality = $this->getRequestParameter("quality", 0); $src_x = $this->getRequestParameter("src_x", 0); $src_y = $this->getRequestParameter("src_y", 0); $src_w = $this->getRequestParameter("src_w", 0); $src_h = $this->getRequestParameter("src_h", 0); $vid_sec = $this->getRequestParameter("vid_sec", -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); if ($width == -1 && $height == -1) { $width = 640; $height = 480; } else { if ($width == -1) { // if only either width or height is missing reset them to zero, and convertImage will handle them $width = 0; } else { if ($height == -1) { $height = 0; } } } $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices); kFileUtils::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0); } } $audio_only = $this->getRequestParameter("audio_only"); // milliseconds $flavor = $this->getRequestParameter("flavor", 1); // $flavor_param_id = $this->getRequestParameter("flavor_param_id", null); // $streamer = $this->getRequestParameter("streamer"); // if (substr($streamer, 0, 4) == "rtmp") { // the fms may add .mp4 to the end of the url $streamer = "rtmp"; } // grab seek_from_bytes parameter and normalize url $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1); $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request); if ($seek_from_bytes <= 0) { $seek_from_bytes = -1; } // grab seek_from parameter and normalize url $seek_from = $this->getRequestParameter("seek_from", -1); $request = str_replace("/seek_from/{$seek_from}", "", $request); if ($seek_from <= 0) { $seek_from = -1; } $this->dump_from_byte = 0; // reset accurate seek from timestamp $seek_from_timestamp = -1; // backward compatibility if ($flavor === "0") { // for edit version $flavor = "edit"; } if ($flavor === "1" || $flavor === 1) { // for play version $flavor = null; } // when flavor is null, we will get a default flavor if ($flavor == "edit") { $flavorAsset = assetPeer::retrieveBestEditByEntryId($entry->getId()); } elseif (!is_null($flavor)) { $flavorAsset = assetPeer::retrieveById($flavor); // when specific asset was request, we don't validate its tags if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) { $flavorAsset = null; } // we will throw an error later } elseif (is_null($flavor) && !is_null($flavor_param_id)) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor_param_id); if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAsset = null; } // we will throw an error later } else { if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId()); } else { $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId()); } if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB); if (count($flavorAssets) > 0) { $flavorAsset = $flavorAssets[0]; } } } if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::file_exists($syncKey, false)) { $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); } else { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset); if (!$urlManager) { KalturaLog::log("Error - failed to find an HTTP delivery for storage profile [" . $fileSync->getDc() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $url = rtrim($urlManager->getUrl(), '/') . '/' . ltrim($urlManager->getFileSyncUrl($fileSync), '/'); header('location: ' . $url); die; } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); $this->redirect($remoteUrl); } $flv_wrapper = new myFlvHandler($path); $isFlv = $flv_wrapper->isFlv(); // scrubbing is not allowed within mp4 files if (!$isFlv) { $seek_from = $seek_from_bytes = -1; } if ($seek_from !== -1 && $seek_from !== 0) { if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only); list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only); $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte; } // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath(); $extStorageUrl = $entry->getExtStorageUrl(); if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $request_host = parse_url($extStorageUrl, PHP_URL_HOST); $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl); $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); KExternalErrors::dieGracefully(); } elseif ($extStorageUrl) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$extStorageUrl}"); KExternalErrors::dieGracefully(); } // use headers to detect cdn $cdn_name = ""; $via_header = @$_SERVER["HTTP_VIA"]; if (strpos($via_header, "llnw.net") !== false) { $cdn_name = "limelight"; } else { if (strpos($via_header, "akamai") !== false) { $cdn_name = "akamai"; } else { if (strpos($via_header, "Level3") !== false) { $cdn_name = "level3"; } } } // setting file extension - first trying frrom flavor asset $ext = $flavorAsset->getFileExt(); // if failed, set extension according to file type (isFlv) if (!$ext) { $ext = $isFlv ? "flv" : "mp4"; } $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0"; // dont check for rtmp / and for an already redirect url if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // check security using ks $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer, ContextType::PLAY); if ($securyEntryHelper->shouldPreview()) { $this->checkForPreview($securyEntryHelper, $clip_to); } else { $securyEntryHelper->validateForPlay($entry, $ks_str); } } else { // if needs security check using cdn authentication mechanism // for now assume this is a cdn request and don't check for security } // use limelight mediavault if either security policy requires it or if we're trying to seek within the video if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) { // we have three options: // arrived through limelight mediavault url - the url is secured // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url // didnt use limelight - enforce ks // the cdns are configured to authenticate request for /s/.... // check if we're already in a redirected secure link using the "/s/" prefix $secure_request = substr($request, 0, 3) == "/s/"; if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) { // request was validated by cdn let it through } else { // extract ks $ks_str = $this->getRequestParameter("ks", ""); if ($entry->getSecurityPolicy()) { if (!$ks_str) { $this->logMessage("flvclipper - no KS"); KExternalErrors::dieGracefully(); } $ks = kSessionUtils::crackKs($ks_str); if (!$ks) { $this->logMessage("flvclipper - invalid ks [{$ks_str}]"); KExternalErrors::dieGracefully(); } $matched_privs = $ks->verifyPrivileges("sview", $entry_id); $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]"); if (!$matched_privs) { $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]"); KExternalErrors::dieGracefully(); } } if ($cdn_name == "limelight") { $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension; $secret = kConf::get("limelight_madiavault_password"); $expire = "&e=" . (time() + 120); $ll_url .= $expire; $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}"; $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs; //header("Location: $ll_url"); $this->redirect($ll_url); } else { if ($cdn_name == "level3") { $level3_url = $request . $flv_extension; if ($entry->getSecurityPolicy()) { $level3_url = "/s{$level3_url}"; // set expire time in GMT hence the date("Z") offset $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30); $level3_url .= $expire; $secret = kConf::get("level3_authentication_key"); $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20); $level3_url .= "&h={$hash}"; } $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}"; header("Location: {$level3_url}"); KExternalErrors::dieGracefully(); } else { if ($cdn_name == "akamai") { $akamai_url = $request . $flv_extension; // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); KExternalErrors::dieGracefully(); } } } // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $this->dump_from_byte = $seek_from_bytes; } } } // always add the file suffix to the request (needed for scrubbing by some cdns, // and also breaks without extension on some corporate antivirus). // we add the the novar paramter since a leaving a trailing "?" will be trimmed // and then the /seek_from request will result in another url which level3 // will try to refetch from the origin // note that for streamer we dont add the file extension if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $request .= "/seek_from_bytes/{$seek_from_bytes}"; } requestUtils::sendCdnHeaders("flv", 0); header("Location: {$request}" . $flv_extension); KExternalErrors::dieGracefully(); } // mp4 if (!$isFlv) { $limit_file_size = 0; if ($clip_to != 2147483647) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2); } } KalturaLog::info("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]"); kFileUtils::dumpFile($path, null, null, $limit_file_size); } $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning"); if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } //$start = microtime(true); list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only); $metadata_size = $flv_wrapper->getMetadataSize($audio_only); $this->from_byte = $from_byte; $this->to_byte = $to_byte; //$end1 = microtime(true); //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]"); $data_offset = $metadata_size + myFlvHandler::getHeaderSize(); // if we're returning a partial file adjust the total size: // substract the metadata and bytes which are not delivered if ($this->dump_from_byte >= $data_offset && !$audio_only) { $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset); } $this->total_length = $data_offset + $bytes; //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die; $this->cuepoint_time = 0; $this->cuepoint_pos = 0; if ($streamer == "chunked" && $clip_to != 2147483647) { $this->cuepoint_time = $clip_to - 1; $this->cuepoint_pos = $cuepoint_pos; $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE; } //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); $this->flv_wrapper = $flv_wrapper; $this->audio_only = $audio_only; try { Propel::close(); } catch (Exception $e) { $this->logMessage("flvclipperAction: error closing db {$e}"); } KExternalErrors::terminateDispatch(); return sfView::SUCCESS; }
public function entryHandled(entry $dbEntry) { $srcEntry = entryPeer::retrieveByPK($this->entryId); if ($srcEntry->getType() == KalturaEntryType::MEDIA_CLIP && $dbEntry->getType() == KalturaEntryType::MEDIA_CLIP && $dbEntry->getMediaType() == KalturaMediaType::IMAGE) { if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) { $dbEntry->setDimensions($srcEntry->getWidth(), $srcEntry->getHeight()); $dbEntry->setMediaDate($srcEntry->getMediaDate(null)); $dbEntry->save(); } else { $srcFlavorAsset = null; if (is_null($this->flavorParamsId)) { $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId); } else { $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId); } if ($srcFlavorAsset) { $dbEntry->setDimensions($srcFlavorAsset->getWidth(), $srcFlavorAsset->getHeight()); $dbEntry->save(); } } } return parent::entryHandled($dbEntry); }
/** * * @return thumbAsset */ public static function retrieveByEntryIdAndParams($entryId, $paramsId) { self::getInstance(); return parent::retrieveByEntryIdAndParams($entryId, $paramsId); }
protected function initFlavorIds() { $flavorIdsStr = $this->getRequestParameter("flavorIds", null); if ($flavorIdsStr) { $this->flavorIds = explode(",", $flavorIdsStr); } $this->flavorId = $this->getRequestParameter("flavorId", null); if (!$this->flavorId) { $flavorParamIds = $this->getRequestParameter("flavorParamIds", null); if ($flavorParamIds !== null) { $this->flavorIds = assetPeer::retrieveReadyFlavorsIdsByEntryId($this->entry->getId(), explode(",", $flavorParamIds)); if (!$this->flavorIds || count($this->flavorIds) == 0) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } } else { $flavorParamId = $this->getRequestParameter("flavorParamId", null); if ($flavorParamId || $flavorParamId === "0") { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entry->getId(), $flavorParamId); if (!$flavorAsset) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $this->flavorId = $flavorAsset->getId(); } } } }
private function getFlavorAssetUrl($kalturaEntry) { $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId); if (!$partner) { return null; } $flavorAsset = assetPeer::retrieveByEntryIdAndParams($kalturaEntry->id, $this->syndicationFeed->flavorParamId); if (!$flavorAsset) { return null; } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($partner, $flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } if ($this->syndicationFeedDb->getServePlayManifest()) { $shouldAddKtToken = false; if ($this->syndicationFeed->type == KalturaSyndicationFeedType::ITUNES) { $entry = $flavorAsset->getentry(); $accessControl = $entry->getaccessControl(); if ($accessControl && $accessControl->hasRules()) { $shouldAddKtToken = true; } } $cdnHost = requestUtils::getApiCdnHost(); $clientTag = 'feed:' . $this->syndicationFeedDb->getId(); $url = $cdnHost . $flavorAsset->getPlayManifestUrl($clientTag, null, PlaybackProtocol::HTTP, $shouldAddKtToken); } else { $urlManager = DeliveryProfilePeer::getDeliveryProfile($flavorAsset->getEntryId()); $urlManager->initDeliveryDynamicAttributes(null, $flavorAsset); $protocol = requestUtils::getProtocol(); if (!$urlManager->isProtocolSupported($protocol)) { $protocol = $protocol == 'http' ? 'https' : 'http'; if (!$urlManager->isProtocolSupported($protocol)) { $protocol = 'http'; } } $url = $protocol . '://' . $urlManager->getFullAssetUrl($flavorAsset); } return $url; }
private function getFlavorAssetUrl($kalturaEntry) { $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId); if (!$partner) { return null; } $flavorAsset = assetPeer::retrieveByEntryIdAndParams($kalturaEntry->id, $this->syndicationFeed->flavorParamId); if (!$flavorAsset) { return null; } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($partner, $flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } if ($this->syndicationFeedDb->getServePlayManifest()) { $cdnHost = requestUtils::getApiCdnHost(); $clientTag = 'feed:' . $this->syndicationFeedDb->getId(); $url = $cdnHost . $flavorAsset->getPlayManifestUrl($clientTag); } else { $urlManager = DeliveryProfilePeer::getDeliveryProfile($flavorAsset->getEntryId()); $urlManager->initDeliveryDynamicAttributes(null, $flavorAsset); $url = "http://" . $urlManager->getFullAssetUrl($flavorAsset); } return $url; }
/** * Serves the file content * * @action serveByFlavorParamsId * @serverOnly * @param string $entryId Document entry id * @param string $flavorParamsId Flavor params id * @param bool $forceProxy force to get the content without redirect * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND */ public function serveByFlavorParamsIdAction($entryId, $flavorParamsId = null, $forceProxy = false) { KalturaResponseCacher::disableCache(); entryPeer::setDefaultCriteriaFilter(); $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != entryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $ksObj = $this->getKs(); $ks = $ksObj ? $ksObj->getOriginalString() : null; $securyEntryHelper = new KSecureEntryHelper($dbEntry, $ks, null); $securyEntryHelper->validateForDownload(); $flavorAsset = null; assetPeer::resetInstanceCriteriaFilter(); if ($flavorParamsId) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorParamsId); } } else { $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorParamsId); } } $fileName = $dbEntry->getName() . '.' . $flavorAsset->getFileExt(); return $this->serveFlavorAsset($flavorAsset, $fileName, $forceProxy); }
/** * Serves caption by entry id and thumnail params id * * @action serveByEntryId * @param string $entryId * @param int $captionParamId if not set, default caption will be used. * @return file * * @throws KalturaCaptionErrors::CAPTION_ASSET_PARAMS_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ public function serveByEntryIdAction($entryId, $captionParamId = null) { $entry = null; if (!kCurrentContext::$ks) { $entry = kCurrentContext::initPartnerByEntryId($entryId); if (!$entry || $entry->getStatus() == entryStatus::DELETED) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // enforce entitlement kEntitlementUtils::initEntitlementEnforcement(); if (!kEntitlementUtils::isEntryEntitled($entry)) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } } else { $entry = entryPeer::retrieveByPK($entryId); } if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, accessControlContextType::DOWNLOAD); $securyEntryHelper->validateForDownload(); $captionAsset = null; if (is_null($captionParamId)) { $captionAssets = assetPeer::retrieveByEntryId($entryId, array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION))); foreach ($captionAssets as $checkCaptionAsset) { if ($checkCaptionAsset->getDefault()) { $captionAsset = $checkCaptionAsset; break; } } } else { $captionAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $captionParamId); } if (!$captionAsset) { throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_PARAMS_ID_NOT_FOUND, $captionParamId); } $fileName = $captionAsset->getId() . '.' . $captionAsset->getFileExt(); return $this->serveAsset($captionAsset, $fileName); }
private function getFlavorAssetUrl($kalturaEntry) { $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId); if (!$partner) { return null; } $flavorAsset = assetPeer::retrieveByEntryIdAndParams($kalturaEntry->id, $this->syndicationFeed->flavorParamId); if (!$flavorAsset) { return null; } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($partner, $flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $this->protocol = StorageProfile::PLAY_FORMAT_HTTP; $this->cdnHost = myPartnerUtils::getCdnHost($this->syndicationFeed->partnerId, $this->protocol); $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost, $flavorAsset->getEntryId()); $urlManager->setDomain($this->cdnHost); $url = $urlManager->getAssetUrl($flavorAsset); $url = $this->cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); return $this->protocol . '://' . $url; }
public static function createThumbnailFromEntry(entry $entry, entry $source_entry, $time_offset, $flavorParamsId = null) { $media_type = $source_entry->getMediaType(); // should capture thumbnail from video if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO && $time_offset != -1) { $flavorAsset = null; if ($flavorParamsId) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($source_entry->getId(), $flavorParamsId); } if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) { $flavorAsset = assetPeer::retrieveOriginalByEntryId($source_entry->getId()); } if (is_null($flavorAsset)) { $flavorAsset = assetPeer::retrieveHighestBitrateByEntryId($source_entry->getId()); } if (is_null($flavorAsset)) { throw new Exception("Flavor asset not found"); } $flavorSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!$flavorSyncKey) { return false; } $dataPath = kFileSyncUtils::getReadyLocalFilePathForKey($flavorSyncKey); $tempPath = myContentStorage::getFSUploadsPath(); $tempThumbPrefix = $tempPath . "temp_thumb" . microtime(true); $thumbBigFullPath = $tempThumbPrefix . "big_1.jpg"; $thumbFullPath = $tempThumbPrefix . '1.jpg'; myFileConverter::autoCaptureFrame($dataPath, $tempThumbPrefix . "big_", $time_offset, -1, -1); // removed creation of "small thumb" - not in use myFileConverter::convertImage($thumbBigFullPath, $thumbFullPath); $bigThumbExists = file_exists($thumbBigFullPath) && filesize($thumbBigFullPath); if (!$bigThumbExists) { return false; } $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); // create new thumb file for entry $newThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::moveFromFile($thumbBigFullPath, $newThumbKey); } else { if ($media_type == entry::ENTRY_MEDIA_TYPE_VIDEO && $time_offset == -1 || $media_type == entry::ENTRY_MEDIA_TYPE_SHOW) { $thumbBigFullKey = $source_entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); if (!kFileSyncUtils::fileSync_exists($thumbBigFullKey)) { return false; } $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); // copy existing thumb $newThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::softCopy($thumbBigFullKey, $newThumbKey); } elseif ($media_type == entry::ENTRY_MEDIA_TYPE_IMAGE) { $thumb_key = $source_entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); $thumb_path = kFileSyncUtils::getLocalFilePathForKey($thumb_key); $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); // copy existing thumb $newThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::copyFromFile($thumb_path, $newThumbKey); } else { return false; } } return true; }
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(); } } }
/** * 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); } }
/** * Serves thumbnail by entry id and thumnail params id * * @action serveByEntryId * @param string $entryId * @param int $thumbParamId if not set, default thumbnail will be used. * @return file * * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY * @throws KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ public function serveByEntryIdAction($entryId, $thumbParamId = null) { $entry = null; if (!kCurrentContext::$ks) { $entry = kCurrentContext::initPartnerByEntryId($entryId); if (!$entry || $entry->getStatus() == entryStatus::DELETED) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // enforce entitlement kEntitlementUtils::initEntitlementEnforcement(); if (!kEntitlementUtils::isEntryEntitled($entry)) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } } else { $entry = entryPeer::retrieveByPK($entryId); } if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $securyEntryHelper = new KSecureEntryHelper($entry, kCurrentContext::$ks, null, accessControlContextType::THUMBNAIL); $securyEntryHelper->validateAccessControl(); $fileName = $entry->getId() . '.jpg'; if (is_null($thumbParamId)) { return $this->serveFile($entry, entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB, $fileName, $entryId); } $thumbAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $thumbParamId); if (!$thumbAsset) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, $thumbParamId); } return $this->serveAsset($thumbAsset, $fileName); }
/** * @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 ingestAsset(entry $entry, $dbAsset, $filename) { $flavorParamsId = $dbAsset->getFlavorParamsId(); $flavorParams = assetParamsPeer::retrieveByPKNoFilter($flavorParamsId); // is first chunk $recordedAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavorParamsId); if ($recordedAsset) { KalturaLog::info("Asset [" . $recordedAsset->getId() . "] of flavor params id [{$flavorParamsId}] already exists"); return; } // create asset $recordedAsset = assetPeer::getNewAsset(assetType::FLAVOR); $recordedAsset->setPartnerId($entry->getPartnerId()); $recordedAsset->setEntryId($entry->getId()); $recordedAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); $recordedAsset->setFlavorParamsId($flavorParams->getId()); $recordedAsset->setFromAssetParams($flavorParams); if ($dbAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { $recordedAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR)); } if ($flavorParams->hasTag(assetParams::TAG_SOURCE)) { $recordedAsset->setIsOriginal(true); } $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext) { $recordedAsset->setFileExt($ext); } $recordedAsset->save(); // create file sync $recordedAssetKey = $recordedAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($filename, $recordedAssetKey, true, true); kEventsManager::raiseEvent(new kObjectAddedEvent($recordedAsset)); }
/** * @param int $flavorParamsId * @return string */ public function getDownloadAssetUrl($flavorParamsId) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($this->getId(), $flavorParamsId); if ($flavorAsset && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { return $flavorAsset->getDownloadUrl(); } if (assetPeer::retrieveOriginalByEntryId($this->getId())) { return null; } // flavor asset should be created // entry file sync should be used (data or download) return $this->getRawDownloadUrl(); }
public static function handleBulkDownloadPending(BatchJob $dbBatchJob, kBulkDownloadJobData $data, BatchJob $twinJob = null) { $entryIds = explode(',', $data->getEntryIds()); $flavorParamsId = $data->getFlavorParamsId(); $jobIsFinished = true; foreach ($entryIds as $entryId) { $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { KalturaLog::err("Entry id [{$entryId}] not found."); } else { if ($entry->hasDownloadAsset($flavorParamsId)) { // why we don't send the notification in case of image is ready? $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId); if ($flavorAsset && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $downloadUrl = $flavorAsset->getDownloadUrl(); $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $downloadUrl = $flavorAsset->getDownloadUrl(); $notificationData = array("puserId" => $entry->getPuserId(), "entryId" => $entry->getId(), "entryIntId" => $entry->getIntId(), "entryVersion" => $entry->getVersion(), "fileFormat" => $flavorAsset->getFileExt(), "archivedFile" => $localPath, "downoladPath" => $localPath, "conversionQuality" => $entry->getConversionQuality(), "downloadUrl" => $downloadUrl); $extraData = array("data" => json_encode($notificationData), "partner_id" => $entry->getPartnerId(), "puser_id" => $entry->getPuserId(), "entry_id" => $entry->getId(), "entry_int_id" => $entry->getIntId(), "entry_version" => $entry->getVersion(), "file_format" => $flavorAsset->getFileExt(), "archived_file" => $localPath, "downolad_path" => $localPath, "target" => $localPath, "conversion_quality" => $entry->getConversionQuality(), "download_url" => $downloadUrl, "status" => $entry->getStatus(), "abort" => $dbBatchJob->getAbort(), "progress" => $dbBatchJob->getProgress(), "message" => $dbBatchJob->getMessage(), "description" => $dbBatchJob->getDescription(), "updates_count" => $dbBatchJob->getUpdatesCount(), "job_type" => BatchJobType::DOWNLOAD, "status" => BatchJob::BATCHJOB_STATUS_FINISHED, "progress" => 100, "debug" => __LINE__); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_BATCH_JOB_SUCCEEDED, $dbBatchJob, $dbBatchJob->getPartnerId(), null, null, $extraData, $entryId); } } else { $jobIsFinished = false; $entry->createDownloadAsset($dbBatchJob, $flavorParamsId, $data->getPuserId()); } } } if ($jobIsFinished) { // mark the job as finished $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED); } else { // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); } return $dbBatchJob; }