/** * @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; }
/** * Request a new conversion job, this can be used to convert the media entry to a different format * * @action requestConversion * @param string $entryId Media entry id * @param string $fileFormat Format to convert * @return int The queued job id * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ public function requestConversionAction($entryId, $fileFormat) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } if ($dbEntry->getMediaType() == KalturaMediaType::AUDIO) { // for audio - force format flv regardless what the user really asked for $fileFormat = "flv"; } // $job = myBatchDownloadVideoServer::addJob($this->getKuser()->getPuserId(), $dbEntry, null, $fileFormat); $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($this->getPartnerId(), $fileFormat); $err = null; $job = kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParams->getId(), $err); if ($job) { return $job->getId(); } else { return null; } }
/** * @param BatchJob $dbBatchJob * @param kConvertProfileJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handleConvertProfilePending(BatchJob $dbBatchJob, kConvertProfileJobData $data, BatchJob $twinJob = null) { KalturaLog::debug("Convert Profile created, with input file: " . $data->getInputFileSyncLocalPath()); if ($data->getExtractMedia()) { // creates extract media job kJobsManager::addExtractMediaJob($dbBatchJob, $data->getInputFileSyncLocalPath(), $data->getFlavorAssetId(), mediaInfo::ASSET_TYPE_ENTRY_INPUT); } else { $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $dbBatchJob); if ($conversionsCreated) { // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules $currentFlavorAsset = flavorAssetPeer::retrieveById($data->getFlavorAssetId()); if ($currentFlavorAsset) { $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } } } // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); return $dbBatchJob; }
/** * request conversion for all entries that doesnt have the required flavor param * returns a comma-separated ids of conversion jobs * * @action requestConversion * @param string $feedId * @return string */ public function requestConversionAction($feedId) { // find entry ids that already converted to the flavor $feedRendererWithTheFlavor = new KalturaSyndicationFeedRenderer($feedId); $feedRendererWithTheFlavor->addFlavorParamsAttachedFilter(); $entriesWithTheFlavor = $feedRendererWithTheFlavor->getEntriesIds(); // create filter of the entries that not converted $entryFilter = new entryFilter(); $entryFilter->setIdNotIn($entriesWithTheFlavor); // create feed with the new filter $feedRendererToConvert = new KalturaSyndicationFeedRenderer($feedId); $feedRendererToConvert->addFilter($entryFilter); $createdJobsIds = array(); $flavorParamsId = $feedRendererToConvert->syndicationFeed->flavorParamId; while ($entry = $feedRendererToConvert->getNextEntry()) { $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); if (!is_null($originalFlavorAsset)) { $err = ""; $job = kBusinessPreConvertDL::decideAddEntryFlavor(null, $entry->getId(), $flavorParamsId, $err); if ($job && is_object($job)) { $createdJobsIds[] = $job->getId(); } } } return implode(',', $createdJobsIds); }
/** * 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; }
/** * @param BatchJob $parentJob * @param int $flavorParamsId * @param string $puserId * @return int job id */ public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null) { $job = null; if ($this->getType() == entryType::MIX) { // if flavor params == SOURCE, or no format defined for flavor params, default to 'flv' $flattenFormat = null; if ($flavorParamsId != 0) { $flattenFormat = assetParamsPeer::retrieveByPK($flavorParamsId)->getFormat(); } if (!$flattenFormat) { $flattenFormat = 'flv'; } $job = myBatchFlattenClient::addJob($puserId, $this, $this->getVersion(), $flattenFormat); } else { $err = ''; $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err); } if ($job) { return $job->getId(); } return null; }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } /* * On Webex error, roll back the inter-src asset version in order to allow the retry to get ARF as a source, * rather than the invlaid WMV file (product of bad nbrplayer session) */ if ($dbBatchJob->getErrNumber() == BatchJobAppErrors::BLACK_OR_SILENT_CONTENT) { $prevVer = $flavorAsset->getPreviousVersion(); $currVer = $flavorAsset->getVersion(); KalturaLog::log("Webex conversion - Garbled Audio or Black frame or Silence. Rolling back asset/file-sync version - curr({$currVer}), prev({$prevVer})"); if (isset($prevVer)) { $syncKey = $flavorAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $currVer); if (isset($syncKey)) { kFileSyncUtils::deleteSyncFileForKey($syncKey, false, true); $flavorAsset->setVersion($prevVer); $flavorAsset->setPreviousVersion(null); KalturaLog::log("Webex conversion - Rolled back"); } } } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { /* @var $siblingJob BatchJob */ // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } $jobData = $siblingJob->getData(); if (!$jobData || !$jobData instanceof kConvertJobData && !$jobData instanceof kPostConvertJobData) { KalturaLog::err("Job id [" . $siblingJob->getId() . "] has no valid job data"); continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $jobData->getFlavorAssetId(); $siblingFlavorAsset = assetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING); return false; }
/** * Add and convert new Flavor Asset for Entry with specific Flavor Params * * @action convert * @param string $entryId * @param int $flavorParamsId */ public function convertAction($entryId, $flavorParamsId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $flavorParamsDb = flavorParamsPeer::retrieveByPK($flavorParamsId); flavorParamsPeer::setDefaultCriteriaFilter(); if (!$flavorParamsDb) { throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId); } $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY); if (!in_array($dbEntry->getStatus(), $validStatuses)) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS); } $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); if (is_null($originalFlavorAsset) || $originalFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $err = ""; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err); }
/** * @action regenerate * @param string $thumbAssetId * @return KalturaThumbAsset * * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED * @throws KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED * @throws KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND * @throws KalturaErrors::INVALID_ENTRY_STATUS * @validateUser asset::entry thumbAssetId edit */ public function regenerateAction($thumbAssetId) { $thumbAsset = assetPeer::retrieveById($thumbAssetId); if (!$thumbAsset || !$thumbAsset instanceof thumbAsset) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $thumbAssetId); } if (is_null($thumbAsset->getFlavorParamsId())) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, null); } $destThumbParams = assetParamsPeer::retrieveByPK($thumbAsset->getFlavorParamsId()); if (!$destThumbParams) { throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_PARAMS_ID_NOT_FOUND, $thumbAsset->getFlavorParamsId()); } $entry = $thumbAsset->getentry(); if (!in_array($entry->getType(), $this->mediaTypes)) { throw new KalturaAPIException(KalturaErrors::ENTRY_TYPE_NOT_SUPPORTED, $entry->getType()); } if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO) { throw new KalturaAPIException(KalturaErrors::ENTRY_MEDIA_TYPE_NOT_SUPPORTED, $entry->getMediaType()); } $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY); if (!in_array($entry->getStatus(), $validStatuses)) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS); } $dbThumbAsset = kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams); if (!$dbThumbAsset) { return null; } $thumbAsset = new KalturaThumbAsset(); $thumbAsset->fromObject($dbThumbAsset); return $thumbAsset; }
/** * This will queue a batch job for converting the document file to swf * Returns the URL where the new swf will be available * * @action convertPptToSwf * @param string $entryId * @return string */ function convertPptToSwf($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $sync_key = null; $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($sync_key)) { // if not found local file - perhaps wasn't created here and wasn't synced yet // try to see if remote exists - and proxy the request if it is. list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true); if (!$local) { $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrl($fileSync); kFileUtils::dumpApiRequest($remoteDCHost); } KalturaLog::log("convertPptToSwf sync key doesn't exists"); return; } $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF); $flavorParamsId = $flavorParams->getId(); $puserId = $this->getKuser()->getPuserId(); $err = ""; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err); $downloadPath = $dbEntry->getDownloadUrl(); //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3 return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf'; }
/** * @param BatchJob $dbBatchJob * @param kConvertProfileJobData $data * @return BatchJob */ public static function handleConvertProfilePending(BatchJob $dbBatchJob, kConvertProfileJobData $data) { if ($data->getExtractMedia()) { // creates extract media job kJobsManager::addExtractMediaJob($dbBatchJob, $data->getInputFileSyncLocalPath(), $data->getFlavorAssetId()); } else { try { $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $dbBatchJob); } catch (kCoreException $ex) { //This was added so the all the assets prior to reaching the limit would still be created if ($ex->getCode() != kCoreException::MAX_ASSETS_PER_ENTRY) { throw $ex; } KalturaLog::err("Max assets per entry was reached continuing with normal flow"); } if ($conversionsCreated) { // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules $currentFlavorAsset = assetPeer::retrieveById($data->getFlavorAssetId()); if ($currentFlavorAsset) { $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } } } // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); return $dbBatchJob; }
/** * This will queue a batch job for converting the document file to swf * Returns the URL where the new swf will be available * * @action convertPptToSwf * @param string $entryId * @return string */ function convertPptToSwf($entryId) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } assetPeer::resetInstanceCriteriaFilter(); $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $sync_key = null; $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($sync_key)) { // if not found local file - perhaps wasn't created here and wasn't synced yet // try to see if remote exists - and proxy the request if it is. list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true); if (!$local) { // take input params and add to URL $queryArr = array('service' => 'document', 'action' => 'convertPptToSwf', 'entryId' => $entryId, 'format' => $this->params["format"], 'ks' => $this->getKs()->toSecureString()); $get_query = http_build_query($queryArr, '', '&'); $remote_url = kDataCenterMgr::getRedirectExternalUrl($fileSync, $_SERVER['REQUEST_URI']); $url = strpos($remote_url, '?') === FALSE ? $remote_url . '?' . $get_query : $remote_url . '&' . $get_query; // prxoy request to other DC KalturaLog::log(__METHOD__ . ": redirecting to [{$url}]"); kFile::dumpUrl($url); } KalturaLog::log("convertPptToSwf sync key doesn't exists"); return; } $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF); $flavorParamsId = $flavorParams->getId(); $puserId = $this->getKuser()->getPuserId(); $err = ""; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err); $downloadPath = $dbEntry->getDownloadUrl(); //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3 return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf'; }
/** * Add and convert new Flavor Asset for Entry with specific Flavor Params * * @action convert * @param string $entryId * @param int $flavorParamsId * @param int $priority * @validateUser entry entryId edit */ public function convertAction($entryId, $flavorParamsId, $priority = 0) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $flavorParamsDb = assetParamsPeer::retrieveByPK($flavorParamsId); assetParamsPeer::setUseCriteriaFilter(false); if (!$flavorParamsDb) { throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId); } $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY); if (!in_array($dbEntry->getStatus(), $validStatuses)) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS); } $conversionProfile = $dbEntry->getconversionProfile2(); if (!$conversionProfile) { throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $dbEntry->getConversionProfileId()); } $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId); if (is_null($originalFlavorAsset) || !$originalFlavorAsset->isLocalReadyStatus()) { throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING); } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false); /* @var $fileSync FileSync */ if (!$fileSync) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } if (!$local && $fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) { kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync)); } $err = ""; $dynamicFlavorAttributes = $dbEntry->getDynamicFlavorAttributesForAssetParams($flavorParamsDb->getId()); kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err, null, $dynamicFlavorAttributes, $priority); }
/** * @param EntryDistribution $entryDistribution * @param DistributionProfile $distributionProfile * @param bool $submitWhenReady * @return BatchJob */ public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true) { if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) { KalturaLog::debug("Submission is not enabled"); return null; } $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED); if (!in_array($entryDistribution->getStatus(), $validStatus)) { KalturaLog::notice("Wrong entry distribution status [" . $entryDistribution->getStatus() . "]"); return null; } $returnValue = false; $validationErrors = $entryDistribution->getValidationErrors(); if (!count($validationErrors)) { KalturaLog::debug("No validation errors found"); $returnValue = true; $sunrise = $entryDistribution->getSunrise(null); if ($sunrise) { KalturaLog::debug("Applying sunrise [{$sunrise}]"); $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) { $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise(); if ($sunrise > time()) { KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED); $entryDistribution->save(); $returnValue = null; } } } if ($returnValue) { $returnValue = self::addSubmitAddJob($entryDistribution, $distributionProfile); } } if (!$returnValue && $submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) { $entryDistribution->setStatus(EntryDistributionStatus::QUEUED); $entryDistribution->save(); KalturaLog::debug("Will be submitted when ready"); } if (!count($validationErrors)) { return $returnValue; } KalturaLog::log("Validation errors found"); $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId()); if (!$entry) { KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found"); return null; } $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray(); $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray(); foreach ($validationErrors as $validationError) { if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) { $errDescription = null; KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription); if ($errDescription) { KalturaLog::log($errDescription); } } if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && count($autoCreateThumbs)) { list($requiredWidth, $requiredHeight) = explode('x', $validationError->getData()); $foundThumbParams = false; $thumbParamsObjects = assetParamsPeer::retrieveByPKs($autoCreateThumbs); foreach ($thumbParamsObjects as $thumbParams) { /* @var $thumbParams thumbParams */ if ($thumbParams->getWidth() == intval($requiredWidth) && $thumbParams->getHeight() == intval($requiredHeight)) { $foundThumbParams = true; KalturaLog::log("Adding thumbnail [" . $thumbParams->getId() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams); break; } } if (!$foundThumbParams) { KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]"); } } } return null; }
public static function checkForPendingLiveClips(entry $entry) { if ($entry->getSource() != EntrySourceType::RECORDED_LIVE) { KalturaLog::notice("Entry [" . $entry->getId() . "] is not a recorded live"); return; } $liveEntry = entryPeer::retrieveByPKNoFilter($entry->getRootEntryId()); if (!$liveEntry || $liveEntry->getStatus() == entryStatus::DELETED || !$liveEntry instanceof LiveEntry) { KalturaLog::notice("Entry root [" . $entry->getRootEntryId() . "] is not a valid live entry"); return; } /* @var $liveEntry LiveEntry */ $pendingMediaEntries = $liveEntry->getAttachedPendingMediaEntries(); foreach ($pendingMediaEntries as $pendingMediaEntry) { /* @var $pendingMediaEntry kPendingMediaEntry */ if ($pendingMediaEntry->getRequiredDuration() && $pendingMediaEntry->getRequiredDuration() > $entry->getLengthInMsecs()) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] required duration [" . $pendingMediaEntry->getRequiredDuration() . "] while entry duration [" . $entry->getLengthInMsecs() . "] is too short"); continue; } $liveEntry->dettachPendingMediaEntry($pendingMediaEntry->getEntryId()); $pendingEntry = entryPeer::retrieveByPK($pendingMediaEntry->getEntryId()); if (!$pendingEntry) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] not found"); continue; } $sourceAsset = assetPeer::retrieveOriginalByEntryId($entry->getId()); if (!$sourceAsset) { $sourceAssets = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId()); $sourceAsset = array_pop($sourceAssets); } if (!$sourceAsset) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] source asset not found"); continue; } /* @var $sourceAsset flavorAsset */ $operationAttributes = new kClipAttributes(); $operationAttributes->setOffset($pendingMediaEntry->getOffset()); $operationAttributes->setDuration($pendingMediaEntry->getDuration()); $targetAsset = assetPeer::retrieveOriginalByEntryId($pendingMediaEntry->getEntryId()); if (!$targetAsset) { $targetAsset = kFlowHelper::createOriginalFlavorAsset($entry->getPartnerId(), $pendingMediaEntry->getEntryId()); } $targetAsset->setFileExt($sourceAsset->getFileExt()); $targetAsset->save(); $sourceSyncKey = $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $targetSyncKey = $targetAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($targetSyncKey, $sourceSyncKey); $errDescription = ''; kBusinessPreConvertDL::decideAddEntryFlavor(null, $pendingMediaEntry->getEntryId(), $operationAttributes->getAssetParamsId(), $errDescription, $targetAsset->getId(), array($operationAttributes)); } $liveEntry->save(); }
/** * @param BatchJob $parentJob * @param int $flavorParamsId * @param string $puserId * @return int job id */ public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null) { $job = null; if ($this->getType() == entryType::MIX) { KalturaLog::err("Entry ID [" . $this->getId() . "] is of type mix. The batch job for flattening a mix is no longer supported"); } else { $err = ''; $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err); } if ($job) { return $job->getId(); } return null; }
/** * @param EntryDistribution $entryDistribution * @param DistributionProfile $distributionProfile * @param bool $submitWhenReady * @return BatchJob */ public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true) { if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) { return null; } $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED); if (!in_array($entryDistribution->getStatus(), $validStatus)) { KalturaLog::notice("wrong entry distribution status [" . $entryDistribution->getStatus() . "]"); return null; } if ($submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) { $entryDistribution->setStatus(EntryDistributionStatus::QUEUED); $entryDistribution->save(); } $validationErrors = $entryDistribution->getValidationErrors(); if (!count($validationErrors)) { $sunrise = $entryDistribution->getSunrise(null); if ($sunrise) { $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) { $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise(); if ($sunrise > time()) { KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED); $entryDistribution->save(); return null; } } } return self::addSubmitAddJob($entryDistribution, $distributionProfile); } KalturaLog::log("Validation errors found"); $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId()); if (!$entry) { KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found"); return null; } $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray(); $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray(); foreach ($validationErrors as $validationError) { if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) { $errDescription = null; KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription); if ($errDescription) { KalturaLog::log($errDescription); } } if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && in_array($validationError->getData(), $autoCreateThumbs)) { $destThumbParams = thumbParamsPeer::retrieveByPK($validationError->getData()); if ($destThumbParams) { KalturaLog::log("Adding thumbnail [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]"); kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams); } else { KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]"); } } } return null; }