public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = parent::validateForSubmission($entryDistribution, $action); $inListOrNullFields = array(FacebookDistributionField::CALL_TO_ACTION_TYPE_VALID_VALUES => explode(',', self::CALL_TO_ACTION_TYPE_VALID_VALUES)); if (count($entryDistribution->getFlavorAssetIds())) { $flavorAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFlavorAssetIds())); } else { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($entryDistribution->getEntryId()); } $validVideo = false; foreach ($flavorAssets as $flavorAsset) { $validVideo = $this->validateVideo($flavorAsset); if ($validVideo) { // even one valid video is enough break; } } if (!$validVideo) { KalturaLog::err("No valid video found for entry [" . $entryDistribution->getEntryId() . "]"); $validationErrors[] = $this->createCustomValidationError($action, DistributionErrorType::INVALID_DATA, 'flavorAsset', ' No valid flavor found'); } $allFieldValues = $this->getAllFieldValues($entryDistribution); if (!$allFieldValues || !is_array($allFieldValues)) { KalturaLog::err('Error getting field values from entry distribution id [' . $entryDistribution->getId() . '] profile id [' . $this->getId() . ']'); return $validationErrors; } if ($allFieldValues[FacebookDistributionField::SCHEDULE_PUBLISHING_TIME] && $allFieldValues[FacebookDistributionField::SCHEDULE_PUBLISHING_TIME] > time() && !dateUtils::isWithinTimeFrame($allFieldValues[FacebookDistributionField::SCHEDULE_PUBLISHING_TIME], FacebookConstants::FACEBOOK_MIN_POSTPONE_POST_IN_SECONDS, FacebookConstants::FACEBOOK_MAX_POSTPONE_POST_IN_SECONDS)) { KalturaLog::err("Scheduled time to publish defies the facebook restriction of six minute to six months from now got" . $allFieldValues[FacebookDistributionField::SCHEDULE_PUBLISHING_TIME]); $validationErrors[] = $this->createCustomValidationError($action, DistributionErrorType::INVALID_DATA, 'sunrise', 'Distribution sunrise is invalid (should be 6 minutes to 6 months from now)'); } $validationErrors = array_merge($validationErrors, $this->validateInListOrNull($inListOrNullFields, $allFieldValues, $action)); return $validationErrors; }
if ($lastCreatedAt) { $c->addAnd(entryPeer::CREATED_AT, $lastCreatedAt, Criteria::LESS_EQUAL); } $c->addDescendingOrderByColumn(entryPeer::CREATED_AT); $c->setLimit($curLimit); $entries = entryPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL3)); foreach ($entries as $entry) { if (in_array($entry->getId(), $processedIds)) { continue; } $processedIds[] = $entry->getId(); $lastCreatedAt = $entry->getCreatedAt(null); $keys = array(); $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); $keys[] = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); $flavors = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId()); foreach ($flavors as $flavor) { if (!$flavorParamsArr || in_array($flavor->getFlavorParamsId(), $flavorParamsArr)) { $keys[] = $flavor->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); } } foreach ($keys as $index => $key) { if (!kFileSyncUtils::fileSync_exists($key)) { unset($keys[$index]); continue; } if (kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageProfileId)) { unset($keys[$index]); } if (!kFileSyncUtils::getReadyInternalFileSyncForKey($key)) { echo 'file sync key does not have an internal file -' . serialize($key) . PHP_EOL;
/** * @param kLiveEntryResource $resource * @param entry $dbEntry * @param asset $dbAsset * @return array $operationAttributes * @return asset */ protected function attachLiveEntryResource(kLiveEntryResource $resource, entry $dbEntry, asset $dbAsset = null, array $operationAttributes = null) { $dbEntry->setRootEntryId($resource->getEntry()->getId()); $dbEntry->setSource(EntrySourceType::RECORDED_LIVE); $dbEntry->save(); if (!$dbAsset) { $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId()); } $offset = null; $duration = null; $requiredDuration = null; $clipAttributes = null; if (is_array($operationAttributes)) { foreach ($operationAttributes as $operationAttributesItem) { if ($operationAttributesItem instanceof kClipAttributes) { $clipAttributes = $operationAttributesItem; // convert milliseconds to seconds $offset = $operationAttributesItem->getOffset(); $duration = $operationAttributesItem->getDuration(); $requiredDuration = $offset + $duration; } } } $dbLiveEntry = $resource->getEntry(); $dbRecordedEntry = entryPeer::retrieveByPK($dbLiveEntry->getRecordedEntryId()); if (!$dbRecordedEntry || $requiredDuration && $requiredDuration > $dbRecordedEntry->getLengthInMsecs()) { $mediaServer = $dbLiveEntry->getMediaServer(true); if (!$mediaServer) { throw new KalturaAPIException(KalturaErrors::NO_MEDIA_SERVER_FOUND, $dbLiveEntry->getId()); } $mediaServerLiveService = $mediaServer->getWebService($mediaServer->getLiveWebServiceName()); if ($mediaServerLiveService && $mediaServerLiveService instanceof KalturaMediaServerLiveService) { $mediaServerLiveService->splitRecordingNow($dbLiveEntry->getId()); $dbLiveEntry->attachPendingMediaEntry($dbEntry, $requiredDuration, $offset, $duration); $dbLiveEntry->save(); } else { throw new KalturaAPIException(KalturaErrors::MEDIA_SERVER_SERVICE_NOT_FOUND, $mediaServer->getId(), $mediaServer->getLiveWebServiceName()); } return $dbAsset; } $dbRecordedAsset = assetPeer::retrieveOriginalReadyByEntryId($dbRecordedEntry->getId()); if (!$dbRecordedAsset) { $dbRecordedAssets = assetPeer::retrieveReadyFlavorsByEntryId($dbRecordedEntry->getId()); $dbRecordedAsset = array_pop($dbRecordedAssets); } /* @var $dbRecordedAsset flavorAsset */ $isNewAsset = false; if (!$dbAsset) { $isNewAsset = true; $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId()); } if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } $sourceSyncKey = $dbRecordedAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $dbAsset->setFileExt($dbRecordedAsset->getFileExt()); $dbAsset->save(); $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); try { kFileSyncUtils::createSyncFileLinkForKey($syncKey, $sourceSyncKey); } catch (Exception $e) { if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $dbAsset->save(); throw $e; } if ($requiredDuration) { $errDescription = ''; kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $clipAttributes->getAssetParamsId(), $errDescription, $dbAsset->getId(), array($clipAttributes)); } else { if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset)); } } kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset)); return $dbAsset; }
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(); }
protected function initFlavorAssetArray() { if (!$this->shouldInitFlavorAssetsArray()) { return; } $oneOnly = false; if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::HTTP || $this->deliveryAttributes->getFormat() == "url" || $this->deliveryAttributes->getFormat() == "rtsp") { $oneOnly = true; } // get initial flavor list by input $flavorAssets = array(); if ($this->flavorIds) { $flavorAssets = assetPeer::retrieveReadyByEntryId($this->entryId, $this->flavorIds); $flavorAssets = $this->removeNotAllowedFlavors($flavorAssets); $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets); } if (!$flavorAssets || !count($flavorAssets)) { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($this->entryId); $flavorAssets = $this->deliveryAttributes->filterFlavorsByTags($flavorAssets); $flavorAssets = $this->removeNotAllowedFlavors($flavorAssets); $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets); } if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::SILVER_LIGHT) { $this->initSilverLightManifest($flavorAssets); return; } if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::HDS || $this->deliveryAttributes->getFormat() == PlaybackProtocol::APPLE_HTTP) { // try to look for a smil manifest, if it was found, we will use it for hds and hls if ($this->initSmilManifest($flavorAssets)) { return; } } // get flavors availability $servePriority = $this->entry->getPartner()->getStorageServePriority(); $localFlavors = array(); $remoteFlavorsByDc = array(); $remoteFileSyncs = array(); foreach ($flavorAssets as $flavorAsset) { $flavorId = $flavorAsset->getId(); $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $c = new Criteria(); $c = FileSyncPeer::getCriteriaForFileSyncKey($key); $c->addAnd(FileSyncPeer::STATUS, FileSync::FILE_SYNC_STATUS_READY); switch ($servePriority) { case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY: $c->addAnd(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_URL, Criteria::NOT_EQUAL); break; case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY: $c->add(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_URL); break; } if ($this->deliveryAttributes->getStorageId()) { $c->addAnd(FileSyncPeer::DC, $this->deliveryAttributes->getStorageId()); } $fileSyncs = FileSyncPeer::doSelect($c); foreach ($fileSyncs as $fileSync) { if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $dc = $fileSync->getDc(); $remoteFlavorsByDc[$dc][$flavorId] = $flavorAsset; $remoteFileSyncs[$dc][$flavorId] = $fileSync; } else { $localFlavors[$flavorId] = $flavorAsset; } } } // filter out any invalid / disabled storage profiles if ($remoteFileSyncs) { $storageProfileIds = array_keys($remoteFileSyncs); $storageProfiles = StorageProfilePeer::retrieveExternalByPartnerId($this->entry->getPartnerId(), $storageProfileIds); $activeStorageProfileIds = array(); foreach ($storageProfiles as $storageProfile) { $activeStorageProfileIds[] = $storageProfile->getId(); } foreach ($storageProfileIds as $storageProfileId) { if (in_array($storageProfileId, $activeStorageProfileIds)) { continue; } unset($remoteFlavorsByDc[$storageProfileId]); unset($remoteFileSyncs[$storageProfileId]); } } // choose the storage profile with the highest number of flavors $maxDc = null; $maxDcFlavorCount = 0; $remoteFlavors = array(); foreach ($remoteFlavorsByDc as $dc => $curDcFlavors) { $curDcFlavorCount = count($curDcFlavors); if ($curDcFlavorCount <= $maxDcFlavorCount) { continue; } $maxDc = $dc; $maxDcFlavorCount = $curDcFlavorCount; $remoteFlavors = $curDcFlavors; } // choose the flavor set according to the serve priority if ($this->shouldUseLocalFlavors($localFlavors, $remoteFlavors)) { $this->deliveryAttributes->setStorageId(null); $this->deliveryAttributes->setFlavorAssets($localFlavors); } else { if ($maxDc) { $this->deliveryAttributes->setStorageId($maxDc); $this->deliveryAttributes->setFlavorAssets($remoteFlavors); $this->deliveryAttributes->setRemoteFileSyncs($remoteFileSyncs[$maxDc]); } } if (!$this->deliveryAttributes->getFlavorAssets()) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if ($oneOnly) { $flavorAssets = $this->deliveryAttributes->getFlavorAssets(); $this->deliveryAttributes->setFlavorAssets(array(reset($flavorAssets))); } }
/** * @param EntryDistribution $entryDistribution * @param int $action enum from DistributionAction * @return array<kDistributionValidationError> */ public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = array(); $distributionProvider = $this->getProvider(); if (!$distributionProvider) { KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $this->getProviderType() . "] not found"); return $validationErrors; } if ($action == DistributionAction::UPDATE || $entryDistribution->getStatus() == EntryDistributionStatus::READY || $entryDistribution->getStatus() == EntryDistributionStatus::ERROR_UPDATING) { if (!$distributionProvider->isUpdateEnabled() || !$distributionProvider->isMediaUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); return $validationErrors; } } $requiredFlavorParamsIds = $this->getRequiredFlavorParamsIdsArray(); KalturaLog::log("Required Flavor Params Ids [" . print_r($requiredFlavorParamsIds, true) . "]"); $entryFlavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($entryDistribution->getEntryId()); $requiredFlavorParamsIdsKeys = array_flip($requiredFlavorParamsIds); foreach ($entryFlavorAssets as $entryFlavorAsset) { $flavorParamsId = $entryFlavorAsset->getFlavorParamsId(); if (isset($requiredFlavorParamsIdsKeys[$flavorParamsId])) { unset($requiredFlavorParamsIds[$requiredFlavorParamsIdsKeys[$flavorParamsId]]); } } foreach ($requiredFlavorParamsIds as $requiredFlavorParamsId) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_FLAVOR, $requiredFlavorParamsId); } $requiredThumbDimensions = $this->getRequiredThumbDimensionsObjects(); KalturaLog::log("Required Thumb Dimensions [" . print_r($requiredThumbDimensions, true) . "]"); $entryThumbAssets = assetPeer::retrieveReadyThumbnailsByEntryId($entryDistribution->getEntryId()); $requiredThumbDimensionsWithKeys = array(); foreach ($requiredThumbDimensions as $requiredThumbDimension) { $key = $requiredThumbDimension->getKey(); $requiredThumbDimensionsWithKeys[$key] = $requiredThumbDimension; } foreach ($entryThumbAssets as $entryThumbAsset) { $key = $entryThumbAsset->getWidth() . 'x' . $entryThumbAsset->getHeight(); if (isset($requiredThumbDimensionsWithKeys[$key])) { unset($requiredThumbDimensionsWithKeys[$key]); } } foreach ($requiredThumbDimensionsWithKeys as $key => $requiredThumbDimension) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_THUMBNAIL, $key); } $entryAssets = assetPeer::retrieveReadyByEntryId($entryDistribution->getEntryId()); $requiredAssetDistributionRules = $this->getRequiredAssetDistributionRules(); foreach ($requiredAssetDistributionRules as $entryAssetDistributionRule) { $foundMatchingAsset = false; /* @var $entryAssetDistributionRule kAssetDistributionRule */ foreach ($entryAssets as $entryAsset) { /* @var $entryAsset asset */ if ($entryAssetDistributionRule->fulfilled($entryAsset)) { $foundMatchingAsset = true; break; } } if (!$foundMatchingAsset) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_ASSET, $entryAssetDistributionRule->getValidationError()); } } return $validationErrors; }
private function getValidVideoPath(KalturaDistributionJobData $distributionJobData) { $flavorAssets = array(); $videoAssetFilePath = null; $isValidVideo = false; if (count($distributionJobData->entryDistribution->flavorAssetIds)) { $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds)); } else { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($distributionJobData->entryDistribution->entryId); } foreach ($flavorAssets as $flavorAsset) { $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false); $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo) { try { FacebookGraphSdkUtils::validateVideoAttributes($videoAssetFilePath, $mediaInfo->getFileSize(), $mediaInfo->getVideoDuration()); $isValidVideo = true; } catch (Exception $e) { KalturaLog::debug('Asset [' . $flavorAsset->getId() . '] not valid for distribution: ' . $e->getMessage()); } } if ($isValidVideo) { break; } } } return $videoAssetFilePath; }
private static function handleLocalFileSyncDeletion($entryId, Partner $partner) { if ($partner && $partner->getStorageDeleteFromKaltura()) { $readyAssets = assetPeer::retrieveReadyFlavorsByEntryId($entryId); self::deleteAssetLocalFileSyncsByAssetArray($readyAssets); } }
private static function handleLocalFileSyncDeletion($entryId, Partner $partner) { if ($partner && $partner->getStorageDeleteFromKaltura()) { KalturaLog::debug("searching for exported assets of entry [{$entryId}] to delete local file syncs for"); $readyAssets = assetPeer::retrieveReadyFlavorsByEntryId($entryId); self::deleteAssetLocalFileSyncsByAssetArray($readyAssets); } }
/** * @param bool $oneOnly * @return array */ private function buildHttpFlavorAssetArray($oneOnly) { $flavorAssets = array(); if ($this->flavorId && ($flavorAsset = assetPeer::retrieveById($this->flavorId)) != null) { if ($this->assetMatchesTags($flavorAsset) && $flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAssets[] = $flavorAsset; } } elseif ($oneOnly) { $webFlavorAssets = $this->getReadyFlavorsByTags(); if (count($webFlavorAssets)) { $flavorAssets[] = reset($webFlavorAssets); } } else { if ($this->flavorIds) { $tmpFlavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($this->entryId); foreach ($tmpFlavorAssets as $flavorAsset) { if (in_array($flavorAsset->getId(), $this->flavorIds)) { $flavorAssets[] = $flavorAsset; } } } else { $flavorAssets = $this->getReadyFlavorsByTags(); } } return $flavorAssets; }