private function addCaptionsData(KalturaDistributionJobData $distributionJobData) { $assetIdsArray = explode(',', $distributionJobData->entryDistribution->assetIds); if (empty($assetIdsArray)) { return; } $this->captionsInfo = new KalturaCaptionDistributionInfoArray(); foreach ($assetIdsArray as $assetId) { $asset = assetPeer::retrieveByIdNoFilter($assetId); if (!$asset) { KalturaLog::err("Asset [{$assetId}] not found"); continue; } if ($asset->getType() != CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)) { KalturaLog::debug("Asset [{$assetId}] is not a caption"); continue; } if ($asset->getStatus() == asset::ASSET_STATUS_READY) { $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $captionInfo = $this->getCaptionInfo($asset, $distributionJobData, KalturaDistributionAction::SUBMIT); if ($captionInfo) { $captionInfo->filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false); $this->captionsInfo[] = $captionInfo; } } } elseif ($asset->getStatus() == asset::ASSET_STATUS_DELETED) { $captionInfo = $this->getCaptionInfo($asset, $distributionJobData, KalturaDistributionAction::DELETE); if ($captionInfo) { $this->captionsInfo[] = $captionInfo; } } else { KalturaLog::err("Asset [{$assetId}] has status [" . $asset->getStatus() . "]. not added to provider data"); } } }
public function shouldConsumeJobStatusEvent(BatchJob $dbBatchJob) { $jobType = $dbBatchJob->getJobType(); $data = $dbBatchJob->getData(); // copy cue points only if it's the first file and this is the primary server if ($jobType == BatchJobType::CONVERT_LIVE_SEGMENT && $dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED && $data->getFileIndex() == 0 && $data->getMediaServerIndex() == MediaServerIndex::PRIMARY) { $asset = assetPeer::retrieveByIdNoFilter($data->getAssetId()); if ($asset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { return true; } } elseif ($jobType == BatchJobType::CONCAT && $dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) { $convertLiveSegmentJobData = $dbBatchJob->getParentJob()->getData(); $asset = assetPeer::retrieveByIdNoFilter($convertLiveSegmentJobData->getAssetId()); if ($asset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { return true; } } return false; }
private function addCaptionsData(KalturaDistributionJobData $distributionJobData) { /* @var $mediaFile KalturaDistributionRemoteMediaFile */ $assetIdsArray = explode(',', $distributionJobData->entryDistribution->assetIds); if (empty($assetIdsArray)) { return; } $assets = array(); $this->captionsInfo = new KalturaDailymotionDistributionCaptionInfoArray(); foreach ($assetIdsArray as $assetId) { $asset = assetPeer::retrieveByIdNoFilter($assetId); if (!$asset) { KalturaLog::err("Asset [{$assetId}] not found"); continue; } if ($asset->getStatus() == asset::ASSET_STATUS_READY) { $assets[] = $asset; } elseif ($asset->getStatus() == asset::ASSET_STATUS_DELETED) { $captionInfo = new KalturaDailymotionDistributionCaptionInfo(); $captionInfo->action = KalturaDailymotionDistributionCaptionAction::DELETE_ACTION; $captionInfo->assetId = $assetId; //getting the asset's remote id foreach ($distributionJobData->mediaFiles as $mediaFile) { if ($mediaFile->assetId == $assetId) { $captionInfo->remoteId = $mediaFile->remoteId; $this->captionsInfo[] = $captionInfo; break; } } } else { KalturaLog::err("Asset [{$assetId}] has status [" . $asset->getStatus() . "]. not added to provider data"); } } foreach ($assets as $asset) { $assetType = $asset->getType(); switch ($assetType) { case CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION): $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $captionInfo = $this->getCaptionInfo($asset, $syncKey, $distributionJobData); if ($captionInfo) { $captionInfo->language = $this->getLanguageCode($asset->getLanguage()); $captionInfo->format = $this->getCaptionFormat($asset); if ($captionInfo->language) { $this->captionsInfo[] = $captionInfo; } else { KalturaLog::err('The caption [' . $asset->getId() . '] has unrecognized language [' . $asset->getLanguage() . ']'); } } } break; case AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT): $syncKey = $asset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::fileSync_exists($syncKey)) { $captionInfo = $this->getCaptionInfo($asset, $syncKey, $distributionJobData); if ($captionInfo) { //language code should be set in the attachments title $captionInfo->language = $asset->getTitle(); $captionInfo->format = $this->getCaptionFormat($asset); $languageCodeReflector = KalturaTypeReflectorCacher::get('KalturaLanguageCode'); //check if the language code exists if ($languageCodeReflector && $languageCodeReflector->getConstantName($captionInfo->language)) { $this->captionsInfo[] = $captionInfo; } else { KalturaLog::err('The attachment [' . $asset->getId() . '] has unrecognized language [' . $asset->getTitle() . ']'); } } } break; } } }
/** * batch addMediaInfoAction action saves a media info object * * @action addMediaInfo * @param KalturaMediaInfo $mediaInfo * @return KalturaMediaInfo * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND */ function addMediaInfoAction(KalturaMediaInfo $mediaInfo) { $mediaInfoDb = null; $flavorAsset = null; if ($mediaInfo->flavorAssetId) { $flavorAsset = assetPeer::retrieveByIdNoFilter($mediaInfo->flavorAssetId); if (!$flavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $mediaInfo->flavorAssetId); } $mediaInfoDb = mediaInfoPeer::retrieveByFlavorAssetId($mediaInfo->flavorAssetId); if ($mediaInfoDb && $mediaInfoDb->getFlavorAssetVersion() == $flavorAsset->getVersion()) { $mediaInfoDb = $mediaInfo->toUpdatableObject($mediaInfoDb); } else { $mediaInfoDb = null; } } if (!$mediaInfoDb) { $mediaInfoDb = $mediaInfo->toInsertableObject(); } if ($flavorAsset) { $mediaInfoDb->setFlavorAssetVersion($flavorAsset->getVersion()); } $mediaInfoDb = kBatchManager::addMediaInfo($mediaInfoDb); $mediaInfo->fromObject($mediaInfoDb); return $mediaInfo; }
private function calculateId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; $i++) { $id = $dc["id"] . '_' . kString::generateStringId(); $existingObject = assetPeer::retrieveByIdNoFilter($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for flavorAsset"); }
public static function initPartnerByAssetId($assetId) { KalturaCriterion::disableTags(array(KalturaCriterion::TAG_ENTITLEMENT_ENTRY, KalturaCriterion::TAG_WIDGET_SESSION)); $asset = assetPeer::retrieveByIdNoFilter($assetId); KalturaCriterion::restoreTags(array(KalturaCriterion::TAG_ENTITLEMENT_ENTRY, KalturaCriterion::TAG_WIDGET_SESSION)); if (!$asset) { return null; } kCurrentContext::$ks = null; kCurrentContext::$ks_object = null; kCurrentContext::$ks_hash = null; kCurrentContext::$ks_partner_id = $asset->getPartnerId(); kCurrentContext::$ks_uid = null; kCurrentContext::$master_partner_id = null; kCurrentContext::$partner_id = $asset->getPartnerId(); kCurrentContext::$uid = null; kCurrentContext::$is_admin_session = false; return $asset; }
/** * @param BatchJob $dbBatchJob * @param kConcatJobData $data * @return BatchJob */ public static function handleConcatFinished(BatchJob $dbBatchJob, kConcatJobData $data) { if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) { return $dbBatchJob; } if (!file_exists($data->getDestFilePath())) { throw new APIException(APIErrors::INVALID_FILE_NAME, $data->getDestFilePath()); } $flavorAsset = assetPeer::retrieveByIdNoFilter($data->getFlavorAssetId()); if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId()); } if ($flavorAsset->getStatus() == asset::ASSET_STATUS_DELETED) { return $dbBatchJob; } $flavorAsset->incrementVersion(); $ext = pathinfo($data->getDestFilePath(), PATHINFO_EXTENSION); if ($ext) { $flavorAsset->setFileExt($ext); } $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($data->getDestFilePath(), $syncKey); kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset, $dbBatchJob)); return $dbBatchJob; }