Exemple #1
0
 /**
  * This helps create special entries in a kshow - the show_entry & intro
  * $type can be either entry::ENTRY_MEDIA_TYPE_SHOW (for the show_entry) or  entry::ENTRY_MEDIA_TYPE_VIDEO  (for the intro)
  */
 public function createEntry($type, $kuser_id, $thumbnail = null, $entry_name = null)
 {
     // for invites we use the default invites from the kaltura gallery show
     if ($type != entry::ENTRY_MEDIA_TYPE_SHOW) {
         $kshow_type = $this->getType();
         $intros = array(kshow::KSHOW_TYPE_MASHUP, kshow::KSHOW_TYPE_MUSIC_VIDEO, kshow::KSHOW_TYPE_HOWTO, kshow::KSHOW_TYPE_CALL_FOR_ACTION, kshow::KSHOW_TYPE_CONTEST, kshow::KSHOW_TYPE_GROUP_GREETING, kshow::KSHOW_TYPE_SPORTS, kshow::KSHOW_TYPE_DIGITAL_STORY, kshow::KSHOW_TYPE_GROUP_TRAVELOGUE);
         $id = 0;
         if (in_array($kshow_type, $intros)) {
             $id = $kshow_type;
         }
         $id = 120 + $id;
         $entry = entryPeer::retrieveByPK($id);
         if ($entry) {
             $this->setIntroId($entry->getId());
             $this->m_intro = $entry;
         }
         return $entry;
     }
     $kshow = $this;
     $entry = new entry();
     $entry->setKshowId($kshow->getId());
     $entry->setKuserId($kuser_id);
     $entry->setCreatorKuserId($kuser_id);
     if ($this->getPartnerId() !== null) {
         $entry->setPartnerId($this->getPartnerId());
     }
     // inherit partner_id from kshow
     if ($this->getSubpId() !== null) {
         $entry->setSubpId($this->getSubpId());
     }
     // inherit subp_id from kshow
     $entry->setStatus(entryStatus::READY);
     if ($entry_name) {
         $type_text = $entry_name;
     } else {
         $type_text = "Kaltura Video";
     }
     //$entry->setData ( "&kal_show.flv");
     $entry->setThumbnail($thumbnail ? $thumbnail : "&kal_show.jpg");
     $entry->setCreateThumb(false);
     $entry->setType(entryType::MIX);
     $entry->setMediaType(entry::ENTRY_MEDIA_TYPE_SHOW);
     $entry->setEditorType(myMetadataUtils::METADATA_EDITOR_SIMPLE);
     $entry->setName($type_text);
     $entry->setTags($type_text . "," . $kshow->getTags());
     $entry->save();
     $this->setShowEntryId($entry->getId());
     $this->m_show_entry = $entry;
     return $entry;
 }
 /**
  * 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)
 {
     if (is_null($srcAsset)) {
         $srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $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);
     if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) {
         $destThumbParamsOutput->setVideoOffset($entry->getThumbOffset());
     }
     $destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration()));
     if (!$destThumbParamsOutput->getDensity()) {
         $partner = $entry->getPartner();
         if (!is_null($partner)) {
             $destThumbParamsOutput->setDensity($partner->getDefThumbDensity());
         }
     }
     $thumbAsset = assetPeer::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->setTags($destThumbParamsOutput->getTags());
     $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt());
     if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) {
         $thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING);
     }
     //Sets the default thumb if this the only default thumb
     kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset);
     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, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput);
         return $thumbAsset;
     }
     $errDescription = null;
     // Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo.
     $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null);
     // 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->setCreateThumb(false);
         $entry->save();
         $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey);
         if ($syncFile) {
             // removes the DEFAULT_THUMB tag from all other thumb assets
             $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($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;
 }
 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;
 }
Exemple #4
0
 /**
  * @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);
 }
 protected function executeImpl(kshow $kshow, entry &$entry)
 {
     $this->res = "";
     $likuser_id = $this->getLoggedInUserId();
     // if we allow multiple rouchcuts - there is no reason for one suer to override someone else's thumbnail
     if ($this->allowMultipleRoughcuts()) {
         if ($likuser_id != $entry->getKuserId()) {
             // ERROR - attempting to update an entry which doesnt belong to the user
             return "<xml>!!</xml>";
             //$this->securityViolation( $kshow->getId() );
         }
     }
     $debug = @$_GET["debug"];
     /*
     $kshow_id = @$_GET["kshow_id"];
     $debug = @$_GET["debug"];
     
     $this->kshow_id = $kshow_id;
     
     if ( $kshow_id == NULL || $kshow_id == 0 ) return;
     
     $kshow = kshowPeer::retrieveByPK( $kshow_id );
     
     if ( ! $kshow ) 
     {
     	$this->res = "No kshow " . $kshow_id ;
     	return;	
     }
     
     // is the logged-in-user is not an admin or the producer - check if show can be published	
     $likuser_id = $this->getLoggedInUserId();
     $viewer_type = myKshowUtils::getViewerType($kshow, $likuser_id);
     if ( $viewer_type != KshowKuser::KSHOWKUSER_VIEWER_PRODUCER && ( ! $kshow->getCanPublish() ) ) 
     {
     	// ERROR - attempting to publish a non-publishable show
     	return "<xml>!</xml>";//$this->securityViolation( $kshow->getId() );
     }
     
     
     // ASSUME - the kshow & roughcut already exist
     $show_entry_id = $kshow->getShowEntryId();
     $roughcut = entryPeer::retrieveByPK( $show_entry_id );
     
     $roughcut = entryPeer::retrieveByPK( $entry_id );
     
      
     if ( ! $roughcut)
     {
     	$this->res = "No roughcut for kshow " . $kshow->getId() ;
     	return;	
     }
     */
     //		echo "for entry: $show_entry_id current thumb path: " . $entry->getThumbnail() ;
     $entry->setThumbnail(".jpg");
     $entry->setCreateThumb(false);
     $entry->save();
     //$thumb_data = $_REQUEST["ThumbData"];
     if (isset($HTTP_RAW_POST_DATA)) {
         $thumb_data = $HTTP_RAW_POST_DATA;
     } else {
         $thumb_data = file_get_contents("php://input");
     }
     //		$thumb_data = $GLOBALS["HTTP_RAW_POST_DATA"];
     $thumb_data_size = strlen($thumb_data);
     $bigThumbPath = myContentStorage::getFSContentRootPath() . $entry->getBigThumbnailPath();
     kFile::fullMkdir($bigThumbPath);
     kFile::setFileContent($bigThumbPath, $thumb_data);
     $path = myContentStorage::getFSContentRootPath() . $entry->getThumbnailPath();
     kFile::fullMkdir($path);
     myFileConverter::createImageThumbnail($bigThumbPath, $path);
     $roughcutPath = myContentStorage::getFSContentRootPath() . $entry->getDataPath();
     $xml_doc = new KDOMDocument();
     $xml_doc->load($roughcutPath);
     if (myMetadataUtils::updateThumbUrl($xml_doc, $entry->getBigThumbnailUrl())) {
         $xml_doc->save($roughcutPath);
     }
     $this->res = $entry->getBigThumbnailUrl();
 }