/** * @param flavorAsset $flavorAsset * @return string */ public function getFlavorAssetUrl(flavorAsset $flavorAsset) { $entry = $flavorAsset->getentry(); $partnerId = $entry->getPartnerId(); $subpId = $entry->getSubpId(); $flavorAssetId = $flavorAsset->getId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId); $this->setFileExtension($flavorAsset->getFileExt()); $url = "/s{$partnerPath}/serveFlavor/flavorId/{$flavorAssetId}"; if ($this->clipTo) { $url .= "/clipTo/{$this->clipTo}"; } if ($this->extention) { $url .= "/name/{$flavorAssetId}.{$this->extention}"; } $url = str_replace('\\', '/', $url); if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) { $url .= '?novar=0'; $url .= '&e=' . (time() + 120); $secret = $this->getMediaVault(); $fullUrl = $this->protocol . '://' . $this->domain . $url; $url .= '&h=' . md5($secret . $fullUrl); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $seekFromBytes = $this->getSeekFromBytes(kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($seekFromBytes) { $url .= '&fs=' . $seekFromBytes; } } else { $url .= '/forceproxy/true'; } return $url; }
protected function doGetFlavorAssetUrl(flavorAsset $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); $url = $this->getFileSyncUrl($fileSync); $url = $this->formatByExtension($url, false); return $url; }
/** * @param flavorAsset $flavor * @param StorageProfile $externalStorage */ protected function exportFlavorAsset(flavorAsset $flavor, StorageProfile $externalStorage) { $flavorParamsIds = $externalStorage->getFlavorParamsIds(); KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIds}]"); if (!is_null($flavorParamsIds) && strlen(trim($flavorParamsIds))) { $flavorParamsArr = explode(',', $flavorParamsIds); if (!in_array($flavor->getFlavorParamsId(), $flavorParamsArr)) { return; } } $key = $flavor->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $this->export($flavor->getentry(), $externalStorage, $key, !$flavor->getIsOriginal()); return true; }
/** * @param flavorAsset $flavorAsset * @return string */ public function getFlavorAssetUrl(flavorAsset $flavorAsset) { $entry = $flavorAsset->getentry(); $partnerId = $entry->getPartnerId(); $subpId = $entry->getSubpId(); $flavorAssetId = $flavorAsset->getId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId); $this->setFileExtension($flavorAsset->getFileExt()); $url = "{$partnerPath}/serveFlavor/flavorId/{$flavorAssetId}"; if ($this->clipTo) { $url .= "/clipTo/{$this->clipTo}"; } if ($this->extention) { $url .= "/name/{$flavorAssetId}.{$this->extention}"; } if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) { $url .= '?novar=0'; if ($entry->getSecurityPolicy()) { $url = "/s{$url}"; // set expire time in GMT hence the date("Z") offset $url .= "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30); $secret = kConf::get("level3_authentication_key"); $hash = "0" . substr(self::hmac('sha1', $secret, $url), 0, 20); $url .= "&h={$hash}"; } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $seekFromBytes = $this->getSeekFromBytes(kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($seekFromBytes) { $url .= '&start=' . $seekFromBytes; } } else { $url .= '/forceproxy/true'; } $url = str_replace('\\', '/', $url); return $url; }
/** * @param flavorAsset $originalFlavorAsset * @param entry $entry * @param BatchJob $convertProfileJob * @return BatchJob */ public static function bypassConversion(flavorAsset $originalFlavorAsset, entry $entry, BatchJob $convertProfileJob) { if (!$originalFlavorAsset->hasTag(flavorParams::TAG_MBR)) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId()); if ($mediaInfo) { $tagsArray = $originalFlavorAsset->getTagsArray(); $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfo, $tagsArray); $originalFlavorAsset->setTagsArray($finalTagsArray); } } $offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcFileSyncLocalPath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey); $jobSubType = BatchJob::BATCHJOB_SUB_TYPE_POSTCONVERT_BYPASS; return kJobsManager::addPostConvertJob($convertProfileJob, $jobSubType, $srcFileSyncLocalPath, $originalFlavorAsset->getId(), null, true, $offset); }
protected function addEntryFromFlavorAsset(KalturaBaseEntry $newEntry, entry $srcEntry, flavorAsset $srcFlavorAsset) { $newEntry->type = $srcEntry->getType(); if ($newEntry->name === null) { $newEntry->name = $srcEntry->getName(); } if ($newEntry->description === null) { $newEntry->description = $srcEntry->getDescription(); } if ($newEntry->creditUrl === null) { $newEntry->creditUrl = $srcEntry->getSourceLink(); } if ($newEntry->creditUserName === null) { $newEntry->creditUserName = $srcEntry->getCredit(); } if ($newEntry->tags === null) { $newEntry->tags = $srcEntry->getTags(); } $newEntry->sourceType = KalturaSourceType::SEARCH_PROVIDER; $newEntry->searchProviderType = KalturaSearchProviderType::KALTURA; $dbEntry = $this->prepareEntryForInsert($newEntry); $dbEntry->setSourceId($srcEntry->getId()); $kshow = $this->createDummyKShow(); $kshowId = $kshow->getId(); $msg = null; $flavorAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId(), $msg); if (!$flavorAsset) { KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "] reason [{$msg}]"); if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED, $msg); } $srcSyncKey = $srcFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $newSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($newSyncKey, $srcSyncKey); kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset)); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry); $newEntry->fromObject($dbEntry, $this->getResponseProfile()); return $newEntry; }
/** * @param flavorAsset $flavorAsset * @return boolean true if the given flavor asset is configured to be exported or false otherwise */ public function shouldExportFlavorAsset(flavorAsset $flavorAsset) { $shouldExport = null; // check if flavor params id is in the list to export $flavorParamsIdsToExport = $this->getFlavorParamsIds(); KalturaLog::log(__METHOD__ . " flavorParamsIds [{$flavorParamsIdsToExport}]"); if (is_null($flavorParamsIdsToExport) || strlen(trim($flavorParamsIdsToExport)) == 0) { // all flavor assets should be exported $shouldExport = true; } else { $flavorParamsIdsToExport = array_map('trim', explode(',', $flavorParamsIdsToExport)); if (in_array($flavorAsset->getFlavorParamsId(), $flavorParamsIdsToExport)) { // flavor set to export $shouldExport = true; } else { // flavor not set to export $shouldExport = false; } } // check if flavor fits the export rules defined on the profile if ($shouldExport) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $shouldExport = kStorageExporter::shouldExport($key, $this); if (!$shouldExport) { KalturaLog::log("no need to export key [{$key}] to externalStorage id[" . $this->getId() . "]"); } } return $shouldExport; }
private function getFlavorHttpUrl(flavorAsset $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($this->storageId) { // must be specific external storage return null; } $partner = $this->entry->getPartner(); if ($partner && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost); $urlManager->setClipTo($this->clipTo); $urlManager->setSeekFromTime($this->seekFrom); $urlManager->setDomain($this->cdnHost); $urlManager->setProtocol($this->format); $url = $urlManager->getFlavorAssetUrl($flavorAsset); if (strpos($url, "/") === 0) { $url = $this->cdnHost . $url; } $url = preg_replace('/^https?:\\/\\//', '', $url); return $this->protocol . '://' . $url; }
private function getSyncKeyAndForFlavorAsset(entry $entry, flavorAsset $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); return $syncKey; }
private static function decideSourceFlavorConvert($entryId, assetParams $sourceFlavor = null, flavorAsset $originalFlavorAsset, $conversionProfileId, $flavors, mediaInfo $mediaInfo = null, BatchJob $parentJob, BatchJob $convertProfileJob) { if ($sourceFlavor && ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) && $originalFlavorAsset->getInterFlowCount() == null) { KalturaLog::log("Source flavor asset requires conversion"); self::adjustAssetParams($entryId, array($sourceFlavor)); $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription); if (!$sourceFlavorOutput) { if (!$errDescription) { $errDescription = "Failed to create flavor params output from source flavor"; } $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); $originalFlavorAsset->setStatus(flavorAsset::ASSET_STATUS_ERROR); $originalFlavorAsset->save(); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FAILED); return false; } } elseif ($mediaInfo) { /* * Check whether there is a need for an intermediate source pre-processing */ $sourceFlavorOutput = KDLWrap::GenerateIntermediateSource($mediaInfo, $flavors); if (!$sourceFlavorOutput) { return true; } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; /* * Save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. * But, do it only if the conversion profile contains source flavor */ if ($sourceFlavor) { $sourceAsset = assetPeer::retrieveById($mediaInfo->getFlavorAssetId()); $copyFlavorParams = assetParamsPeer::retrieveBySystemName(self::SAVE_ORIGINAL_SOURCE_FLAVOR_PARAM_SYS_NAME); if (!$copyFlavorParams) { throw new APIException(APIErrors::OBJECT_NOT_FOUND); } $asset = $sourceAsset->copy(); $asset->setFlavorParamsId($copyFlavorParams->getId()); $asset->setFromAssetParams($copyFlavorParams); $asset->setStatus(flavorAsset::ASSET_STATUS_READY); $asset->setIsOriginal(0); $asset->setTags($copyFlavorParams->getTags()); $asset->incrementVersion(); $asset->save(); kFileSyncUtils::createSyncFileLinkForKey($asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET)); $origFileSync = kFileSyncUtils::getLocalFileSyncForKey($sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET)); $asset->setSize(intval($origFileSync->getFileSize() / 1000)); $asset->save(); } } /* * '_passthrough' controls whether the source is to be 'passthrough' although there * is a source flavor that contains transcoder settings. * Looks for a '_passthrough' flag on the source's flavor params output. */ if (!$sourceFlavorOutput || $sourceFlavorOutput->_passthrough == true) { return true; } // save flavor params $sourceFlavorOutput->setPartnerId($sourceFlavorOutput->getPartnerId()); $sourceFlavorOutput->setEntryId($entryId); $sourceFlavorOutput->setFlavorAssetId($originalFlavorAsset->getId()); $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); if ($errDescription) { $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); } $errDescription = kBusinessConvertDL::parseFlavorDescription($sourceFlavorOutput); if ($errDescription) { $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); } // decided by the business logic layer if ($sourceFlavorOutput->_create_anyway) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] selected to be created anyway"); } else { if (!$sourceFlavorOutput->IsValid()) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is invalid"); $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $originalFlavorAsset->save(); $errDescription = "Source flavor could not be converted"; self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId()); return false; } if ($sourceFlavorOutput->_force) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is forced"); } elseif ($sourceFlavorOutput->_isNonComply) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is none-comply"); } else { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is valid"); } } $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); if (isset($sourceFlavor)) { $originalFlavorAsset->addTags($sourceFlavor->getTagsArray()); $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt()); $originalFlavorAsset->save(); } // save flavor params $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); $mediaInfoId = null; if ($mediaInfo) { $mediaInfoId = $mediaInfo->getId(); } kJobsManager::addFlavorConvertJob(array($srcSyncKey), $sourceFlavorOutput, $originalFlavorAsset->getId(), $conversionProfileId, $mediaInfoId, $parentJob); return false; }
/** * Serves the file content * * @action serve * @param flavorAsset $flavorAsset * @param string $fileName * @param bool $forceProxy * @return file * * @throws KalturaErrors::FLAVOR_ASSET_IS_NOT_READY */ protected function serveFlavorAsset(flavorAsset $flavorAsset, $fileName, $forceProxy = false) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (!$fileSync) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY, $flavorAsset->getId()); } /* @var $fileSync FileSync */ if ($fileSync->getFileExt() != assetParams::CONTAINER_FORMAT_SWF) { header("Content-Disposition: attachment; filename=\"{$fileName}\""); } if ($local) { $filePath = $fileSync->getFullPath(); $mimeType = kFile::mimeType($filePath); return $this->dumpFile($filePath, $mimeType); } else { $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); KalturaLog::info("Redirecting to [{$remoteUrl}]"); if ($forceProxy) { kFileUtils::dumpUrl($remoteUrl); } else { // or redirect if no proxy header("Location: {$remoteUrl}"); die; } } }
private static function decideSourceFlavorConvert($entryId, assetParams $sourceFlavor = null, flavorAsset $originalFlavorAsset, $conversionProfileId, $flavors, mediaInfo $mediaInfo = null, BatchJob $parentJob, BatchJob $convertProfileJob) { if ($sourceFlavor && ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) && $originalFlavorAsset->getInterFlowCount() == null) { KalturaLog::log("Source flavor asset requires conversion"); self::adjustAssetParams($entryId, array($sourceFlavor)); $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription); if (!$sourceFlavorOutput) { if (!$errDescription) { $errDescription = "Failed to create flavor params output from source flavor"; } $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); $originalFlavorAsset->setStatus(flavorAsset::ASSET_STATUS_ERROR); $originalFlavorAsset->save(); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FAILED); return false; } /* * If the conversion profile contains source flavor and the source is tagged with 'save_source' ==> * save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. */ if (isset($sourceFlavor) && strstr($sourceFlavor->getTagsArray(), assetParams::TAG_SAVE_SOURCE) !== false) { self::saveOriginalSource($mediaInfo); } } elseif ($mediaInfo) { /* * Check whether there is a need for an intermediate source pre-processing */ $sourceFlavorOutput = KDLWrap::GenerateIntermediateSource($mediaInfo, $flavors); if (!$sourceFlavorOutput) { return true; } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; /* * Save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. * But, do it only if the conversion profile contains source flavor */ if (isset($sourceFlavor)) { self::saveOriginalSource($mediaInfo); } } /* * '_passthrough' controls whether the source is to be 'passthrough' although there * is a source flavor that contains transcoder settings. * Looks for a '_passthrough' flag on the source's flavor params output. */ if (!isset($sourceFlavorOutput) || $sourceFlavorOutput->_passthrough == true) { return true; } // save flavor params $sourceFlavorOutput->setPartnerId($sourceFlavorOutput->getPartnerId()); $sourceFlavorOutput->setEntryId($entryId); $sourceFlavorOutput->setFlavorAssetId($originalFlavorAsset->getId()); $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); if ($errDescription) { $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); } $errDescription = kBusinessConvertDL::parseFlavorDescription($sourceFlavorOutput); if ($errDescription) { $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); } // decided by the business logic layer if ($sourceFlavorOutput->_create_anyway) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] selected to be created anyway"); } else { if (!$sourceFlavorOutput->IsValid()) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is invalid"); $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $originalFlavorAsset->save(); $errDescription = "Source flavor could not be converted"; self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId()); return false; } if ($sourceFlavorOutput->_force) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is forced"); } elseif ($sourceFlavorOutput->_isNonComply) { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is none-comply"); } else { KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is valid"); } } $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); if (isset($sourceFlavor)) { $tagsArr = $sourceFlavor->getTagsArray(); // No need for 'save_source' tag on the inter-src asset, remove it. if (($key = array_search(assetParams::TAG_SAVE_SOURCE, $tagsArr)) !== false) { unset($tagsArr[$key]); } $originalFlavorAsset->addTags($tagsArr); $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt()); $originalFlavorAsset->save(); } // save flavor params $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); $mediaInfoId = null; if ($mediaInfo) { $mediaInfoId = $mediaInfo->getId(); } kJobsManager::addFlavorConvertJob(array($srcSyncKey), $sourceFlavorOutput, $originalFlavorAsset->getId(), $conversionProfileId, $mediaInfoId, $parentJob); return false; }
/** * * Allows to create additional files in the conversion process in addition to flavor asset */ private static function handleAdditionalFilesConvertFinished(flavorAsset $flavorAsset, BatchJob $dbBatchJob, kConvertJobData $data) { if (!$flavorAsset->getVersion() || !kFileSyncUtils::fileSync_exists($flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET))) { $flavorAsset->incrementVersion(); $flavorAsset->save(); } foreach ($data->getExtraDestFileSyncs() as $destFileSyncDesc) { $syncKey = $flavorAsset->getSyncKey($destFileSyncDesc->getFileSyncObjectSubType()); $flavorParamsOutput = $data->getFlavorParamsOutput(); $storageProfileId = $flavorParamsOutput->getSourceRemoteStorageProfileId(); if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) { kFileSyncUtils::moveFromFile($destFileSyncDesc->getFileSyncLocalPath(), $syncKey, false); } elseif ($flavorParamsOutput->getRemoteStorageProfileIds()) { $remoteStorageProfileIds = explode(',', $flavorParamsOutput->getRemoteStorageProfileIds()); foreach ($remoteStorageProfileIds as $remoteStorageProfileId) { $storageProfile = StorageProfilePeer::retrieveByPK($remoteStorageProfileId); kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $destFileSyncDesc->getFileSyncLocalPath(), $storageProfile); } } } }
private function validateVideo(flavorAsset $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false); $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if (!$mediaInfo) { return false; } try { FacebookGraphSdkUtils::validateVideoAttributes($videoAssetFilePath, $mediaInfo->getFileSize(), $mediaInfo->getVideoDuration()); return true; } catch (Exception $e) { KalturaLog::debug('Asset [' . $flavorAsset->getId() . '] not valid for distribution: ' . $e->getMessage()); } } return false; }
/** * @param flavorAsset $flavorAsset * @param IRemoteStorageResource $contentResource * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(flavorAsset $flavorAsset, IRemoteStorageResource $contentResource) { $resources = $contentResource->getResources(); $flavorAsset->setFileExt($contentResource->getFileExt()); $flavorAsset->incrementVersion(); $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } if ($flavorAsset->getIsOriginal()) { $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); } else { $flavorAsset->setStatusLocalReady(); } $flavorAsset->save(); kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset); }
/** * @param flavorAsset $flavorAsset * @return array */ private function getFlavorHttpUrl(flavorAsset $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($this->storageId) { // must be specific external storage return null; } $partner = $this->entry->getPartner(); if ($partner && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $urlManager = $this->getUrlManagerByCdn($this->cdnHost, null, $flavorAsset); $urlManager->setSeekFromTime($this->seekFrom); $urlManager->setDomain($this->cdnHost); $url = $urlManager->getAssetUrl($flavorAsset, false); $this->tokenizer = $urlManager->getTokenizer(); if ($this->format == StorageProfile::PLAY_FORMAT_RTSP) { // the host was already added by the url manager return $this->getFlavorAssetInfo($url, '', $flavorAsset); } $urlPrefix = ''; if (strpos($url, "/") === 0) { $flavorSizeKB = $flavorAsset->getSize(); if ($flavorSizeKB > kConf::get("max_file_size_downloadable_from_cdn_in_KB")) { $urlPrefix = requestUtils::getRequestHost(); } else { $urlPrefix = $this->cdnHost; } } $urlPrefix = preg_replace('/^https?:\\/\\//', '', $urlPrefix); $url = preg_replace('/^https?:\\/\\//', '', $url); if ($urlPrefix) { $urlPrefix = $this->protocol . '://' . $urlPrefix; $urlPrefix = rtrim($urlPrefix, "/") . "/"; } else { $url = $this->protocol . '://' . $url; } $url = ltrim($url, "/"); return $this->getFlavorAssetInfo($url, $urlPrefix, $flavorAsset); }