protected static function getAssetUrl(asset $asset) { $urlManager = DeliveryProfilePeer::getDeliveryProfile($asset->getEntryId()); if ($asset instanceof flavorAsset) { $urlManager->initDeliveryDynamicAttributes(null, $asset); } $url = $urlManager->getFullAssetUrl($asset); $url = preg_replace('/^https?:\\/\\//', '', $url); $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt(); return $url; }
protected static function getAssetUrl(asset $asset) { $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId()); $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId()); $urlManager->setDomain($cdnHost); $url = $urlManager->getAssetUrl($asset); $url = $cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt(); return $url; }
protected static function addImportJob($dc, $entryUrl, asset $asset) { KalturaLog::debug("Importing asset [" . $asset->getId() . "] from dc [{$dc}] with URL [{$entryUrl}]"); $entryUrl = str_replace('//', '/', $entryUrl); $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl); $jobData = new kImportJobData(); $jobData->setCacheOnly(true); $jobData->setSrcFileUrl($entryUrl); $jobData->setFlavorAssetId($asset->getId()); $batchJob = new BatchJob(); $batchJob->setDc($dc); $batchJob->setEntryId($asset->getEntryId()); $batchJob->setPartnerId($asset->getPartnerId()); return kJobsManager::addJob($batchJob, $jobData, BatchJobType::IMPORT); }
public function fulfilled(asset $asset) { $propName = $this->propertyName; $propValue = $this->propertyValue; $customPropGetterCallback = array($asset, "get" . $propName); if (!is_callable($customPropGetterCallback)) { KalturaLog::info("asset (id = {$asset->getId()}) required property not found: Prop Name = {$propName}, Prop Value = {$propValue}"); return false; } if ($propValue != call_user_func($customPropGetterCallback)) { KalturaLog::info("asset (id = {$asset->getId()}) does not match distribution property condition: Prop Name = {$propName}, Prop Value = {$propValue}"); return false; } KalturaLog::info("asset (id = {$asset->getId()}) MATCHES distribution property condition: Prop Name = {$propName}, Prop Value = {$propValue}"); return true; }
private function setContextDataFlavorAssets($flavorTags) { $flavorParamsIds = null; $flavorParamsNotIn = false; if (!$this->isAdmin) { foreach ($this->contextDataResult->getActions() as $action) { if ($action->getType() == RuleActionType::BLOCK) { //in case of block action do not set the list of flavors return; } if ($action->getType() == RuleActionType::LIMIT_FLAVORS) { /* @var $action kAccessControlLimitFlavorsAction */ $flavorParamsIds = explode(',', $action->getFlavorParamsIds()); $flavorParamsNotIn = $action->getIsBlockedList(); } } } $flavorAssets = array(); if (is_null($this->asset)) { if (count($flavorParamsIds)) { $flavorAssets = assetPeer::retrieveReadyByEntryIdAndFlavorParams($this->entry->getId(), $flavorParamsIds, $flavorParamsNotIn); } else { $flavorAssets = assetPeer::retrieveFlavorsByEntryIdAndStatus($this->entry->getId(), null, array(flavorAsset::ASSET_STATUS_READY)); } } else { $flavorAllowed = true; if (count($flavorParamsIds)) { $flavorAllowed = $this->isFlavorAllowed($this->asset->getFlavorParamsId(), $flavorParamsIds, $flavorParamsNotIn); } if ($flavorAllowed) { $flavorAssets[] = $this->asset; } } $this->filterFlavorAssetsByTags($flavorAssets, $flavorTags); }
protected static function addImportJob($dc, $entryUrl, asset $asset) { $entryUrl = str_replace('//', '/', $entryUrl); $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl); $jobData = new kImportJobData(); $jobData->setCacheOnly(true); $jobData->setSrcFileUrl($entryUrl); $jobData->setFlavorAssetId($asset->getId()); $batchJob = new BatchJob(); $batchJob->setDc($dc); $batchJob->setEntryId($asset->getEntryId()); $batchJob->setPartnerId($asset->getPartnerId()); $batchJob->setObjectId($asset->getId()); $batchJob->setObjectType(BatchJobObjectType::ASSET); return kJobsManager::addJob($batchJob, $jobData, BatchJobType::IMPORT); }
private static function purgeAssetFromEdgeCast(asset $asset) { // get partner $partnerId = $asset->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err('Cannot find partner with id [' . $partnerId . ']'); return false; } $mediaType = $asset instanceof thumbAsset ? self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE : self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE; $mediaTypePathList = array(); try { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $asset->getDownloadUrl()); // asset download url } catch (Exception $e) { KalturaLog::err('Cannot get asset URL for asset id [' . $asset->getId() . '] - ' . $e->getMessage()); } if ($asset instanceof flavorAsset) { // get a list of all URLs leading to the asset for purging $subPartnerId = $asset->getentry()->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subPartnerId); $assetId = $asset->getId(); $serveFlavorUrl = "{$partnerPath}/serveFlavor/entryId/" . $asset->getEntryId() . "/flavorId/{$assetId}" . '*'; // * wildcard should delete all serveFlavor urls $hosts = array($partner->getCdnHost(), $partner->getRtmpUrl(), $partner->getIisHost()); foreach ($hosts as $host) { if (!empty($host)) { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $host . $serveFlavorUrl); } } } return self::purgeFromEdgeCast($mediaTypePathList, $partner); }
protected function assetFulfilled(asset $asset) { KalturaLog::info('Checking asset id ' . $asset->getId()); foreach ($this->getProperties() as $propName => $propValue) { KalturaLog::info('Comparing property ' . $propName . ' with value ' . $propValue); $getterCallback = array($asset, "get" . $propName); if (!is_callable($getterCallback)) { KalturaLog::info('Property not found on asset'); return false; } if ($propValue != call_user_func($getterCallback)) { KalturaLog::info('Property value does not match'); return false; } KalturaLog::info('Property value was matched'); } return true; }
/** * @param asset $asset * @param string $fileName * @param bool $forceProxy * @param int $version * @throws KalturaErrors::FILE_DOESNT_EXIST */ protected function serveAsset(asset $asset, $fileName, $forceProxy = false, $version = null) { $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $version); $fileSync = null; $serveRemote = false; $partner = PartnerPeer::retrieveByPK($asset->getPartnerId()); switch ($partner->getStorageServePriority()) { case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY: $serveRemote = true; $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } break; case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_FIRST: $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if ($fileSync && $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_READY) { $serveRemote = true; } break; case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST: $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); if ($fileSync) { break; } $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } $serveRemote = true; break; case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY: $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); if (!$fileSync) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } break; } if ($serveRemote && $fileSync) { header("Location: " . $fileSync->getExternalUrl($asset->getEntryId())); die; } return $this->serveFile($asset, asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $fileName, $asset->getEntryId(), $forceProxy); }
private function setContextDataFlavorAssets($flavorTags) { if ($this->entry->getType() == entryType::PLAYLIST && $this->entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_TEXT) { list($entryIds, $durations, $mediaEntry) = myPlaylistUtils::executeStitchedPlaylist($this->entry); if (!$mediaEntry) { return; } $mediaEntryId = $mediaEntry->getId(); $this->msDuration = array_sum($durations); } else { $mediaEntryId = $this->entry->getId(); $this->msDuration = $this->entry->getLengthInMsecs(); } $flavorParamsIds = null; $flavorParamsNotIn = false; if (!$this->isAdmin) { foreach ($this->contextDataResult->getActions() as $action) { if ($action->getType() == RuleActionType::BLOCK) { //in case of block action do not set the list of flavors return; } if ($action->getType() == RuleActionType::LIMIT_FLAVORS) { /* @var $action kAccessControlLimitFlavorsAction */ $flavorParamsIds = explode(',', $action->getFlavorParamsIds()); $flavorParamsNotIn = $action->getIsBlockedList(); } } } $flavorAssets = array(); if (is_null($this->asset)) { if (count($flavorParamsIds)) { $flavorAssets = assetPeer::retrieveReadyByEntryIdAndFlavorParams($mediaEntryId, $flavorParamsIds, $flavorParamsNotIn); } else { $flavorAssets = assetPeer::retrieveFlavorsByEntryIdAndStatus($mediaEntryId, null, array(flavorAsset::ASSET_STATUS_READY)); } if ($mediaEntryId != $this->entry->getId()) { // hack: setting the entry id of the flavors to the original playlist id // since the player uses it in the playManifest url foreach ($flavorAssets as $flavorAsset) { $flavorAsset->setEntryId($this->entry->getId()); } } } else { $flavorAllowed = true; if (count($flavorParamsIds)) { $flavorAllowed = $this->isFlavorAllowed($this->asset->getFlavorParamsId(), $flavorParamsIds, $flavorParamsNotIn); } if ($flavorAllowed) { $flavorAssets[] = $this->asset; } } $this->filterFlavorAssetsByTags($flavorAssets, $flavorTags); }
private function getObject($objectId, $isAsset) { if ($isAsset) { $this->flavorAsset = assetPeer::retrieveById($objectId); if (is_null($this->flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $this->entry = entryPeer::retrieveByPK($this->flavorAsset->getEntryId()); if (is_null($this->entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } return $this->flavorAsset; } else { $this->entry = entryPeer::retrieveByPK($objectId); if (is_null($this->entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } return $this->entry; } }
private static function purgeAssetFromEdgeCast(asset $asset) { // get partner $partnerId = $asset->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err('Cannot find partner with id [' . $partnerId . ']'); return false; } $mediaType = $asset instanceof thumbAsset ? self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE : self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE; $mediaTypePathList = array(); try { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $asset->getDownloadUrl()); // asset download url } catch (Exception $e) { KalturaLog::err('Cannot get asset URL for asset id [' . $asset->getId() . '] - ' . $e->getMessage()); } if ($asset instanceof flavorAsset) { // get a list of all URLs leading to the asset for purging $subPartnerId = $asset->getentry()->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subPartnerId); $assetId = $asset->getId(); $serveFlavorUrl = "{$partnerPath}/serveFlavor/entryId/" . $asset->getEntryId() . "/flavorId/{$assetId}" . '*'; // * wildcard should delete all serveFlavor urls $types = array(kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_HTTP), kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_RTMP)); $deliveryProfile = $partner->getDeliveryProfileIds(); $deliveryProfileIds = array(); foreach ($deliveryProfile as $key => $value) { $deliveryProfileIds = array_merge($deliveryProfileIds, $value); } $c = new Criteria(); $c->add(DeliveryProfilePeer::PARTNER_ID, $partnerId); $c->add(DeliveryProfilePeer::ID, $deliveryProfileIds, Criteria::IN); $c->addSelectColumn(DeliveryProfilePeer::HOST_NAME); $stmt = PermissionPeer::doSelectStmt($c); $hosts = $stmt->fetchAll(PDO::FETCH_COLUMN); foreach ($hosts as $host) { if (!empty($host)) { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $host . $serveFlavorUrl); } } } return self::purgeFromEdgeCast($mediaTypePathList, $partner); }
public function linkFromAsset(asset $fromAsset) { $this->setWidth($fromAsset->getWidth()); $this->setHeight($fromAsset->getHeight()); $this->setContainerFormat($fromAsset->getContainerFormat()); $this->setSize($fromAsset->getSize()); $this->setFileExt($fromAsset->getFileExt()); $this->setTags($fromAsset->getTags()); $this->setDescription($fromAsset->getDescription()); $this->incrementVersion(); $this->setStatusLocalReady(); }
public static function addImportJob(BatchJob $parentJob = null, $entryId, $partnerId, $entryUrl, asset $asset = null, $subType = null, kImportJobData $jobData = null, $keepCurrentVersion = false) { $entryUrl = str_replace('//', '/', $entryUrl); $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl); if (is_null($subType)) { if (stripos($entryUrl, 'sftp:') === 0) { $subType = kFileTransferMgrType::SFTP; } elseif (stripos($entryUrl, 'scp:') === 0) { $subType = kFileTransferMgrType::SCP; } elseif (stripos($entryUrl, 'ftp:') === 0) { $subType = kFileTransferMgrType::FTP; } elseif (stripos($entryUrl, 'https:') === 0) { $subType = kFileTransferMgrType::HTTPS; } else { $subType = kFileTransferMgrType::HTTP; } } if (!$jobData) { $jobData = new kImportJobData(); } $jobData->setSrcFileUrl($entryUrl); if ($asset) { if ($keepCurrentVersion) { if (!$asset->isLocalReadyStatus()) { $asset->setStatus(asset::FLAVOR_ASSET_STATUS_IMPORTING); } } else { $asset->incrementVersion(); $asset->setStatus(asset::FLAVOR_ASSET_STATUS_IMPORTING); } $asset->save(); $jobData->setFlavorAssetId($asset->getId()); } $entry = entryPeer::retrieveByPK($entryId); if ($entry) { $higherStatuses = array(entryStatus::PRECONVERT, entryStatus::READY); if (!in_array($entry->getStatus(), $higherStatuses)) { $entry->setStatus(entryStatus::IMPORT); $entry->save(); } } $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(BatchJobType::IMPORT, $subType); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($entryId); $batchJob->setPartnerId($partnerId); } $batchJob->setObjectId($jobData->getFlavorAssetId()); $batchJob->setObjectType(BatchJobObjectType::ASSET); return self::addJob($batchJob, $jobData, BatchJobType::IMPORT, $subType); }
private static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription, $rotate = null) { $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $errDescription = 'Source asset could has no valid file sync'; return false; } $srcPath = $fileSync->getFullPath(); $uniqid = uniqid('thumb_'); $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg'; $logPath = $destPath . '.log'; if (!file_exists($srcPath)) { $errDescription = "Source file [{$srcPath}] does not exist"; return false; } if (!is_file($srcPath)) { $errDescription = "Source file [{$srcPath}] is not a file"; return false; } try { if ($srcAsset->getType() == assetType::FLAVOR) { /* @var $srcAsset flavorAsset */ $dar = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); if ($mediaInfo) { $dar = $mediaInfo->getVideoDar(); } // generates the thumbnail $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg')); $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), null, null, $dar); if (!$created || !file_exists($destPath)) { $errDescription = "Thumbnail not captured"; return false; } $srcPath = $destPath; $uniqid = uniqid('thumb_'); $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . '.jpg'; } if ($srcAsset->getType() == assetType::THUMBNAIL) { $tempDir = kConf::get('cache_root_path') . DIRECTORY_SEPARATOR . 'thumb'; if (!file_exists($tempDir)) { mkdir($tempDir, 0700, true); } $destPath = $tempDir . DIRECTORY_SEPARATOR . $uniqid . "." . $srcAsset->getFileExt(); } $quality = $destThumbParamsOutput->getQuality(); $cropType = $destThumbParamsOutput->getCropType(); $cropX = $destThumbParamsOutput->getCropX(); $cropY = $destThumbParamsOutput->getCropY(); $cropWidth = $destThumbParamsOutput->getCropWidth(); $cropHeight = $destThumbParamsOutput->getCropHeight(); $bgcolor = $destThumbParamsOutput->getBackgroundColor(); $width = $destThumbParamsOutput->getWidth(); $height = $destThumbParamsOutput->getHeight(); $scaleWidth = $destThumbParamsOutput->getScaleWidth(); $scaleHeight = $destThumbParamsOutput->getScaleHeight(); $density = $destThumbParamsOutput->getDensity(); $stripProfiles = $destThumbParamsOutput->getStripProfiles(); $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true); $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $rotate, $stripProfiles); if (!$cropped || !file_exists($destPath)) { $errDescription = "Crop failed"; return false; } return $destPath; } catch (Exception $ex) { $errDescription = $ex->getMessage(); return false; } }
/** * Applies default values to this object. * This method should be called from the object's constructor (or * equivalent initialization method). * @see __construct() */ public function applyDefaultValues() { parent::applyDefaultValues(); $this->setFileExt('jpg'); $this->setType(assetType::THUMBNAIL); }
public function isPendingExport(asset $asset) { $key = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $c = FileSyncPeer::getCriteriaForFileSyncKey($key); $c->addAnd(FileSyncPeer::DC, $this->getId(), Criteria::EQUAL); $fileSync = FileSyncPeer::doSelectOne($c); if (!$fileSync) { return false; } return $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_PENDING; }
/** * Ensure the request for media arrived in a way approved by the partner. * this may include restricting to a specific cdn, enforcing token usage etc.. * Die in case of a breach. * * @param entry $entry * @param asset $asset */ public static function enforceDelivery($entry, $asset = null) { // block inactive partner $partnerId = $entry->getPartnerId(); self::blockInactivePartner($partnerId); // validate serve access control $flavorParamsId = $asset ? $asset->getFlavorParamsId() : null; $secureEntryHelper = new KSecureEntryHelper($entry, null, null, ContextType::SERVE); $secureEntryHelper->validateForServe($flavorParamsId); // enforce delivery $partner = PartnerPeer::retrieveByPK($partnerId); // Note: Partner was already loaded by blockInactivePartner, no need to check for null $restricted = DeliveryProfilePeer::isRequestRestricted($partner); if ($restricted) { KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]"); KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED); } }
private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null) { if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { return null; } if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) { if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) { // check if having file sync on kaltura dcs return null; } } $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId); if (!$fileSync) { return null; } $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return null; } if ($servePlayManifest) { // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) { $url = requestUtils::getApiCdnHost(); } else { $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host"); } $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId); } else { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId())); if ($urlManager) { $dynamicAttrs = new DeliveryProfileDynamicAttributes(); $dynamicAttrs->setFileExtension($asset->getFileExt()); $dynamicAttrs->setStorageId($fileSync->getDc()); $urlManager->setDynamicAttributes($dynamicAttrs); $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/'); if (strpos($url, "://") === false) { $url = rtrim($urlManager->getUrl(), "/") . "/" . $url; } } else { KalturaLog::debug("Couldn't determine delivery profile for storage id"); $url = null; } } return $url; }
/** * Declares an association between this object and a asset object. * * @param asset $v * @return mediaInfo The current object (for fluent API support) * @throws PropelException */ public function setasset(asset $v = null) { if ($v === null) { $this->setFlavorAssetId(NULL); } else { $this->setFlavorAssetId($v->getId()); } $this->aasset = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the asset object, it will not be re-added. if ($v !== null) { $v->addmediaInfo($this); } return $this; }
public function isAssetAllowed(asset $asset) { if ($this->ks && $this->ks->verifyPrivileges(ks::PRIVILEGE_DOWNLOAD_ASSET, $asset->getId())) { return true; } return $this->isFlavorParamsAllowed($asset->getFlavorParamsId()); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param asset $value A asset object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(asset $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getIntId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('assetPeer'); } } }
/** * @param asset $asset */ public static function onAssetReadyOrDeleted(asset $asset) { if (!ContentDistributionPlugin::isAllowedPartner($asset->getPartnerId())) { KalturaLog::log("Partner [" . $asset->getPartnerId() . "] is not allowed"); return true; } $entry = $asset->getentry(); if (!$entry) { KalturaLog::log("Entry [" . $asset->getEntryId() . "] not found"); return true; } $entryDistributions = EntryDistributionPeer::retrieveByEntryId($asset->getEntryId()); foreach ($entryDistributions as $entryDistribution) { $distributionProfileId = $entryDistribution->getDistributionProfileId(); $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId); if (!$distributionProfile) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] profile [{$distributionProfileId}] not found"); continue; } if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED || $entryDistribution->getStatus() == EntryDistributionStatus::PENDING) { $listChanged = kContentDistributionManager::assignFlavorAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignThumbAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignAssets($entryDistribution, $entry, $distributionProfile); if (!$listChanged) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] asset lists didn't change"); continue; } $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT); $entryDistribution->setValidationErrorsArray($validationErrors); $entryDistribution->save(); if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) { if ($entryDistribution->getDirtyStatus() != EntryDistributionDirtyStatus::SUBMIT_REQUIRED) { self::submitAddEntryDistribution($entryDistribution, $distributionProfile); } } } // submit if ($entryDistribution->getStatus() == EntryDistributionStatus::READY || $entryDistribution->getStatus() == EntryDistributionStatus::ERROR_UPDATING) { $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider not found"); continue; } if (!$distributionProvider->isUpdateEnabled() || !$distributionProvider->isMediaUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); continue; } $listChanged = kContentDistributionManager::assignFlavorAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignThumbAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignAssets($entryDistribution, $entry, $distributionProfile); if (!$listChanged) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] asset lists didn't change"); continue; } $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::UPDATE); $entryDistribution->setValidationErrorsArray($validationErrors); $entryDistribution->save(); if (!count($validationErrors) && $distributionProfile->getUpdateEnabled() == DistributionProfileActionStatus::AUTOMATIC) { self::submitUpdateEntryDistribution($entryDistribution, $distributionProfile); } else { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] should not be updated automatically"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::UPDATE_REQUIRED); $entryDistribution->save(); continue; } } // update } return true; }
public function applyDefaultValues() { parent::applyDefaultValues(); $this->setType(AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT)); }
/** * @param kOperationResource $resource * @param entry $dbEntry * @param asset $dbAsset * @return asset */ protected function attachOperationResource(kOperationResource $resource, entry $dbEntry, asset $dbAsset = null) { $isNewAsset = false; $isSource = false; if ($dbAsset) { if ($dbAsset instanceof flavorAsset) { $isSource = $dbAsset->getIsOriginal(); } } else { $isNewAsset = true; $isSource = true; $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId()); } if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } $operationAttributes = $resource->getOperationAttributes(); $internalResource = $resource->getResource(); if ($internalResource instanceof kLiveEntryResource) { $dbEntry->setOperationAttributes($operationAttributes); $dbEntry->save(); return $this->attachLiveEntryResource($internalResource, $dbEntry, $dbAsset, $operationAttributes); } $dbAsset = $this->attachResource($internalResource, $dbEntry, $dbAsset); $sourceType = $resource->getSourceType(); if ($sourceType) { $dbEntry->setSource($sourceType); $dbEntry->save(); } $errDescription = ''; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $resource->getAssetParamsId(), $errDescription, $dbAsset->getId(), $operationAttributes); if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset)); } kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset)); if ($isSource && $internalResource instanceof kFileSyncResource) { $srcEntryId = $internalResource->getEntryId(); if ($srcEntryId) { $srcEntry = entryPeer::retrieveByPKNoFilter($srcEntryId); if ($srcEntry) { $dbEntry->setSourceEntryId($srcEntryId); $dbEntry->setRootEntryId($srcEntry->getRootEntryId(true)); } } $dbEntry->setOperationAttributes($operationAttributes); $dbEntry->save(); } return $dbAsset; }
public function linkFromAsset(asset $fromAsset) { parent::linkFromAsset($fromAsset); $this->setBitrate($fromAsset->getBitrate()); $this->setFrameRate($fromAsset->getFrameRate()); $this->setVideoCodecId($fromAsset->getVideoCodecId()); }
public static function generateThumbnail(asset $srcAsset, thumbParamsOutput $destThumbParamsOutput, &$errDescription) { $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); if (!$fileSync || $fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $errDescription = 'Source asset could has no valid file sync'; return false; } $srcPath = $fileSync->getFullPath(); $uniqid = uniqid('thumb_'); $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg"; $logPath = $destPath . '.log'; if (!file_exists($srcPath)) { $errDescription = "Source file [{$srcPath}] does not exist"; return false; } if (!is_file($srcPath)) { $errDescription = "Source file [{$srcPath}] is not a file"; return false; } try { if ($srcAsset->getType() == assetType::FLAVOR) { // generates the thumbnail $thumbMaker = new KFFMpegThumbnailMaker($srcPath, $destPath, kConf::get('bin_path_ffmpeg')); $created = $thumbMaker->createThumnail($destThumbParamsOutput->getVideoOffset()); if (!$created || !file_exists($destPath)) { $errDescription = "Thumbnail not captured"; return false; } $srcPath = $destPath; $uniqid = uniqid('thumb_'); $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg"; } $quality = $destThumbParamsOutput->getQuality(); $cropType = $destThumbParamsOutput->getCropType(); $cropX = $destThumbParamsOutput->getCropX(); $cropY = $destThumbParamsOutput->getCropY(); $cropWidth = $destThumbParamsOutput->getCropWidth(); $cropHeight = $destThumbParamsOutput->getCropHeight(); $bgcolor = $destThumbParamsOutput->getBackgroundColor(); $width = $destThumbParamsOutput->getWidth(); $height = $destThumbParamsOutput->getHeight(); $scaleWidth = $destThumbParamsOutput->getScaleWidth(); $scaleHeight = $destThumbParamsOutput->getScaleHeight(); $cropper = new KImageMagickCropper($srcPath, $destPath, kConf::get('bin_path_imagemagick'), true); $cropped = $cropper->crop($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor); if (!$cropped || !file_exists($destPath)) { $errDescription = "Crop failed"; return false; } return $destPath; } catch (Exception $ex) { $errDescription = $ex->getMessage(); return false; } }
public function setFromAssetParams($dbAssetParams) { parent::setFromAssetParams($dbAssetParams); $this->setLanguage($dbAssetParams->getLanguage()); $this->setLabel($dbAssetParams->getLabel()); }
echo $referral['id']; ?> </strong> <p><?php echo $referral['forename']; ?> <?php echo $referral['surname']; ?> </p> <a class="button stats-view" href="/crm/ppi/referral/<?php echo $referral['id']; ?> " title="View Referral">View</a> </li> <?php } ?> </ul> </section> </article> </section> </article> <?php echo asset::js('ppi-referrals.js');
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param asset $value A asset object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(asset $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getIntId(); } // if key === null self::$instances[$key] = $obj; } }