public function updatedJob(BatchJob $dbBatchJob) { $data = $dbBatchJob->getData(); $providerData = $data->getProviderData(); $entryId = $providerData->getEntryId(); $partnerId = $dbBatchJob->getPartnerId(); $spokenLanguage = $providerData->getSpokenLanguage(); if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_DONT_PROCESS) { $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true); if (!$transcript) { $transcript = new TranscriptAsset(); $transcript->setType(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)); $transcript->setEntryId($entryId); $transcript->setPartnerId($partnerId); $transcript->setLanguage($spokenLanguage); $transcript->setContainerFormat(AttachmentType::TEXT); $transcript->setAccuracy(self::DEFAULT_ACCURACY); } $transcript->setStatus(AttachmentAsset::ASSET_STATUS_QUEUED); $transcript->save(); return true; } $formatsString = $providerData->getCaptionAssetFormats(); if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) { $clientHelper = VoicebasePlugin::getClientHelper($providerData->getApiKey(), $providerData->getApiPassword()); $externalEntryExists = $clientHelper->checkExistingExternalContent($entryId); if (!$externalEntryExists) { KalturaLog::err('remote content does not exist'); return true; } $formatsArray = explode(',', $formatsString); $formatsArray[] = "TXT"; $contentsArray = $clientHelper->getRemoteTranscripts($entryId, $formatsArray); KalturaLog::debug('contents are - ' . print_r($contentsArray, true)); $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true); $captions = $this->getAssetsByLanguage($entryId, array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)), $spokenLanguage); $this->setObjectContent($transcript, $contentsArray["TXT"], null, true); unset($contentsArray["TXT"]); foreach ($contentsArray as $format => $content) { $captionFormatConst = constant("KalturaCaptionType::" . $format); if (isset($captions[$captionFormatConst])) { $caption = $captions[$captionFormatConst]; } else { $caption = new CaptionAsset(); $caption->setEntryId($entryId); $caption->setPartnerId($partnerId); $caption->setLanguage($spokenLanguage); $caption->setContainerFormat($captionFormatConst); $caption->setAccuracy(self::DEFAULT_ACCURACY); $caption->setStatus(CaptionAsset::ASSET_STATUS_QUEUED); $caption->save(); } $this->setObjectContent($caption, $content, $format); } } return true; }
/** * @param CaptionAsset $captionAsset * @param BatchJob $parentJob * @throws kCoreException FILE_NOT_FOUND * @return BatchJob */ public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null) { $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); if (!$fileSync) { if (!PermissionPeer::isValidForPartner(CaptionPermissionName::IMPORT_REMOTE_CAPTION_FOR_INDEXING, $captionAsset->getPartnerId())) { throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND); } $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if (!$fileSync) { throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND); } $fullPath = myContentStorage::getFSUploadsPath() . '/' . $captionAsset->getId() . '.tmp'; if (!kFile::downloadUrlToFile($fileSync->getExternalUrl($captionAsset->getEntryId()), $fullPath)) { throw new kCoreException("File sync not found: {$syncKey}", kCoreException::FILE_NOT_FOUND); } kFileSyncUtils::moveFromFile($fullPath, $syncKey, true, false, true); } $jobData = new kParseCaptionAssetJobData(); $jobData->setCaptionAssetId($captionAsset->getId()); $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($captionAsset->getEntryId()); $batchJob->setPartnerId($captionAsset->getPartnerId()); } return kJobsManager::addJob($batchJob, $jobData, CaptionSearchPlugin::getBatchJobTypeCoreValue(CaptionSearchBatchJobType::PARSE_CAPTION_ASSET)); }
/** * @param CaptionAsset $captionAsset * @param IRemoteStorageResource $contentResource * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(CaptionAsset $captionAsset, IRemoteStorageResource $contentResource) { $resources = $contentResource->getResources(); $captionAsset->setFileExt($contentResource->getFileExt()); $captionAsset->incrementVersion(); $captionAsset->setStatus(CaptionAsset::ASSET_STATUS_READY); $captionAsset->save(); $syncKey = $captionAsset->getSyncKey(CaptionAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } }
/** * @param CaptionAsset $captionAsset * @param SimpleXMLElement $mrss * @return SimpleXMLElement */ public function contributeCaptionAssets(CaptionAsset $captionAsset, SimpleXMLElement $mrss) { $subTitle = $mrss->addChild('subTitle'); $subTitle->addAttribute('href', $captionAsset->getDownloadUrl(true)); $subTitle->addAttribute('captionAssetId', $captionAsset->getId()); $subTitle->addAttribute('isDefault', $captionAsset->getDefault() ? 'true' : 'false'); $subTitle->addAttribute('format', $captionAsset->getContainerFormat()); $subTitle->addAttribute('lang', $captionAsset->getLanguage()); if ($captionAsset->getFlavorParamsId()) { $subTitle->addAttribute('captionParamsId', $captionAsset->getFlavorParamsId()); } $tags = $subTitle->addChild('tags'); foreach (explode(',', $captionAsset->getTags()) as $tag) { $tags->addChild('tag', kMrssManager::stringToSafeXml($tag)); } }
/** * @param CaptionAsset $captionAsset * @param int $expiry * @return string */ protected static function generateKsForCaptionServe($captionAsset, $expiry = 86400) { $partnerId = $captionAsset->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); $secret = $partner->getSecret(); $privilege = self::KS_PRIVILEGE_CAPTION . ":" . $captionAsset->getEntryId(); $ksStr = ''; kSessionUtils::startKSession($partnerId, $secret, null, $ksStr, $expiry, false, "", $privilege); return $ksStr; }
public function updatedJob(BatchJob $dbBatchJob) { $data = $dbBatchJob->getData(); $providerData = $data->getProviderData(); $entryId = $providerData->getEntryId(); $partnerId = $dbBatchJob->getPartnerId(); $spokenLanguage = $providerData->getSpokenLanguage(); $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true); if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED) { if ($transcript) { $transcript->setStatus(AttachmentAsset::FLAVOR_ASSET_STATUS_ERROR); $transcript->save(); } } if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_DONT_PROCESS) { if (!$transcript) { $transcript = new TranscriptAsset(); $transcript->setType(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)); $transcript->setEntryId($entryId); $transcript->setPartnerId($partnerId); $transcript->setLanguage($spokenLanguage); $transcript->setContainerFormat(AttachmentType::TEXT); } $transcript->setStatus(AttachmentAsset::ASSET_STATUS_QUEUED); $transcript->save(); return true; } $formatsString = $providerData->getCaptionAssetFormats(); if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) { $clientHelper = Cielo24Plugin::getClientHelper($providerData->getUsername(), $providerData->getPassword()); $remoteJobId = $clientHelper->getRemoteFinishedJobId($entryId); if (!$remoteJobId) { KalturaLog::err('remote content does not exist'); return true; } $formatsArray = explode(',', $formatsString); $transcriptContent = $clientHelper->getRemoteTranscript($remoteJobId); KalturaLog::debug("transcript content - {$transcriptContent}"); $captionsContentArray = $clientHelper->getRemoteCaptions($remoteJobId, $formatsArray); KalturaLog::debug("captions content - " . print_r($captionsContentArray, true)); $captions = $this->getAssetsByLanguage($entryId, array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)), $spokenLanguage); switch ($providerData->getFidelity()) { case KalturaCielo24Fidelity::MECHANICAL: $accuracyRate = self::MECHNICAL_TRANSCRIPTION_ACCURACY_VALUE; break; case KalturaCielo24Fidelity::PREMIUM: $accuracyRate = self::PREMIUM_TRANSCRIPTION_ACCURACY_VALUE; break; case KalturaCielo24Fidelity::PROFESSIONAL: $accuracyRate = self::PROFESSIONAL_TRANSCRIPTION_ACCURACY_VALUE; break; } $this->setObjectContent($transcript, $transcriptContent, $accuracyRate, null, true); foreach ($captionsContentArray as $format => $content) { $captionFormatConst = constant("KalturaCaptionType::" . $format); if (isset($captions[$captionFormatConst])) { $caption = $captions[$captionFormatConst]; } else { $caption = new CaptionAsset(); $caption->setEntryId($entryId); $caption->setPartnerId($partnerId); $caption->setLanguage($spokenLanguage); $caption->setContainerFormat($captionFormatConst); $caption->setStatus(CaptionAsset::ASSET_STATUS_QUEUED); $caption->save(); } $this->setObjectContent($caption, $content, $accuracyRate, $format); } } return true; }