예제 #1
0
 /**
  * @param thumbAsset $thumbAsset
  * @return string
  */
 protected function doGetThumbnailAssetUrl(thumbAsset $thumbAsset)
 {
     $thumbAssetId = $thumbAsset->getId();
     $partnerId = $thumbAsset->getPartnerId();
     $url = "/api_v3/service/thumbAsset/action/serve/partnerId/{$partnerId}/thumbAssetId/{$thumbAssetId}";
     return $url;
 }
예제 #2
0
 public function toInsertableObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new thumbAsset();
     }
     if (!is_null($this->thumbParamsId)) {
         $dbAssetParams = assetParamsPeer::retrieveByPK($this->thumbParamsId);
         if ($dbAssetParams) {
             $object_to_fill->setFromAssetParams($dbAssetParams);
         }
     }
     return parent::toInsertableObject($object_to_fill, $props_to_skip);
 }
예제 #3
0
파일: entry.php 프로젝트: AdiTal/server
 public function setCreateThumb($v, thumbAsset $thumbAsset = null)
 {
     if (!$v) {
         assetPeer::removeThumbAssetDeafultTags($this->getId(), $thumbAsset ? $thumbAsset->getId() : null);
     }
     $this->putInCustomData("createThumb", (bool) $v);
 }
예제 #4
0
 /**
  * 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;
 }
 /**
  * 
  * Sets the default thumb for the assets 
  * If others already exists then we don't set the asset as not default
  * @param thumbAsset $thumbAsset
  */
 protected static function setIsDefaultThumb(thumbAsset $thumbAsset)
 {
     $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId());
     foreach ($entryThumbAssets as $entryThumbAsset) {
         //if we found another asset with a defualt tag. we remove our default tag
         if ($entryThumbAsset->getId() !== $thumbAsset->getId() && $entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
             KalturaLog::debug("Found default tag on thumbAsset id[" . $entryThumbAsset->getId() . "]");
             $thumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB));
             KalturaLog::debug("Removed default tag from thumbAsset id[" . $thumbAsset->getId() . "]");
             return;
         }
     }
 }
예제 #6
0
 public static function createThumbnailAssetFromFile(entry $entry, $filePath)
 {
     $fileLocation = tempnam(sys_get_temp_dir(), $entry->getId());
     $res = KCurlWrapper::getDataFromFile($filePath, $fileLocation, kConf::get('thumb_size_limit'));
     if (!$res) {
         throw new Exception("thumbnail cannot be created from {$filePath} " . error_get_last());
     }
     $thumbAsset = new thumbAsset();
     $thumbAsset->setPartnerId($entry->getPartnerId());
     $thumbAsset->setEntryId($entry->getId());
     $thumbAsset->setStatus(thumbAsset::ASSET_STATUS_QUEUED);
     $thumbAsset->incrementVersion();
     $thumbAsset->save();
     $fileSyncKey = $thumbAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($fileLocation, $fileSyncKey);
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($fileSyncKey);
     $ext = pathinfo($finalPath, PATHINFO_EXTENSION);
     $thumbAsset->setFileExt($ext);
     list($width, $height, $type, $attr) = getimagesize($finalPath);
     $thumbAsset->setWidth($width);
     $thumbAsset->setHeight($height);
     $thumbAsset->setSize(filesize($finalPath));
     $thumbAsset->setStatus(thumbAsset::ASSET_STATUS_READY);
     $thumbAsset->save();
     kBusinessConvertDL::setAsDefaultThumbAsset($thumbAsset);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE_THUMBNAIL, $entry);
 }
 /**
  * @action addFromImage
  * @param string $entryId
  * @param file $fileData
  * @return KalturaThumbAsset
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @validateUser entry entryId edit
  */
 public function addFromImageAction($entryId, $fileData)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ext = pathinfo($fileData["name"], PATHINFO_EXTENSION);
     $dbThumbAsset = new thumbAsset();
     $dbThumbAsset->setPartnerId($dbEntry->getPartnerId());
     $dbThumbAsset->setEntryId($dbEntry->getId());
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_QUEUED);
     $dbThumbAsset->setFileExt($ext);
     $dbThumbAsset->incrementVersion();
     $dbThumbAsset->save();
     $syncKey = $dbThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($fileData["tmp_name"], $syncKey);
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     list($width, $height, $type, $attr) = getimagesize($finalPath);
     $dbThumbAsset->setWidth($width);
     $dbThumbAsset->setHeight($height);
     $dbThumbAsset->setSize(filesize($finalPath));
     $dbThumbAsset->setStatus(thumbAsset::ASSET_STATUS_READY);
     $dbThumbAsset->save();
     $dbEntryThumbs = assetPeer::retrieveThumbnailsByEntryId($entryId);
     //If the thums has the default tag or the entry is in no content and this is the first thumb
     if ($dbEntry->getCreateThumb() && ($dbThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB) || $dbEntry->getStatus() == KalturaEntryStatus::NO_CONTENT && count($dbEntryThumbs) == 1)) {
         $this->setAsDefaultAction($dbThumbAsset->getId());
     }
     $thumbAssets = new KalturaThumbAsset();
     $thumbAssets->fromObject($dbThumbAsset);
     return $thumbAssets;
 }
예제 #8
0
 public function applyDefaultValues()
 {
     parent::applyDefaultValues();
     $this->setType(ThumbCuePointPlugin::getAssetTypeCoreValue(timedThumbAssetType::TIMED_THUMB_ASSET));
 }
예제 #9
0
 /**
  * @action addFromImage
  * @param string $entryId
  * @param file $fileData
  * @return KalturaThumbAsset
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 public function addFromImageAction($entryId, $fileData)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $ext = pathinfo($fileData["name"], PATHINFO_EXTENSION);
     $dbThumbAsset = new thumbAsset();
     $dbThumbAsset->setPartnerId($dbEntry->getPartnerId());
     $dbThumbAsset->setEntryId($dbEntry->getId());
     $dbThumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_QUEUED);
     $dbThumbAsset->setFileExt($ext);
     $dbThumbAsset->incrementVersion();
     $dbThumbAsset->save();
     $syncKey = $dbThumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($fileData["tmp_name"], $syncKey);
     $finalPath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     list($width, $height, $type, $attr) = getimagesize($finalPath);
     $dbThumbAsset->setWidth($width);
     $dbThumbAsset->setHeight($height);
     $dbThumbAsset->setSize(filesize($finalPath));
     $dbThumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY);
     $dbThumbAsset->save();
     $thumbAssets = new KalturaThumbAsset();
     $thumbAssets->fromObject($dbThumbAsset);
     return $thumbAssets;
 }