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 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;
 }
 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);
 }
Esempio n. 5
0
 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);
 }
 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;
 }
 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();
     $srcWamsAssetId = $fileSync->getWamsAssetId();
     $uniqid = uniqid('thumb_');
     $destPath = kConf::get('temp_folder') . "/thumb/{$uniqid}.jpg";
     $logPath = $destPath . '.log';
     if (is_null($srcWamsAssetId)) {
         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
             if (!is_null($srcWamsAssetId)) {
                 $thumbMaker = new KWAMSThumbnailMaker($srcWamsAssetId, $destPath);
                 $created = $thumbMaker->createThumbnail($destThumbParamsOutput->getVideoOffset(), $srcAsset->getWidth(), $srcAsset->getHeight(), $dar);
             } else {
                 $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_');
             $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();
         $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;
     }
 }
 public function isAssetAllowed(asset $asset)
 {
     if ($this->ks && $this->ks->verifyPrivileges(ks::PRIVILEGE_DOWNLOAD_ASSET, $asset->getId())) {
         return true;
     }
     return $this->isFlavorParamsAllowed($asset->getFlavorParamsId());
 }
Esempio n. 9
0
 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);
 }
 /**
  * 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;
 }
Esempio n. 11
0
 /**
  * @param asset $asset
  */
 protected function assetDeleted(asset $asset)
 {
     $this->syncableDeleted($asset->getId(), FileSyncObjectType::FLAVOR_ASSET);
 }
 protected function shouldIngestFlavor(asset $flavorAsset)
 {
     // mediaFile array was not initialized meaning this is the first submit job
     if (!$this->_distributionJobData->mediaFiles instanceof KalturaDistributionRemoteMediaFileArray) {
         return true;
     }
     // find the mediaFile of our flavor
     $foundMediaFile = null;
     foreach ($this->_distributionJobData->mediaFiles as $mediaFile) {
         if ($mediaFile->assetId == $flavorAsset->getId()) {
             $foundMediaFile = $mediaFile;
             break;
         }
     }
     // this mediaFile was not sent yet
     if (is_null($foundMediaFile)) {
         return true;
     }
     return $foundMediaFile->version != $flavorAsset->getVersion();
 }
Esempio n. 13
0
 /**
  * 
  * @param asset $asset
  * @param $con
  * 
  * @return flavorParamsOutput
  */
 public static function retrieveByAsset(asset $asset, $con = null)
 {
     return self::retrieveByAssetId($asset->getId(), $asset->getVersion(), $con);
 }