/** * @param AttachmentAsset $attachmentAsset * @param IRemoteStorageResource $contentResource * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(AttachmentAsset $attachmentAsset, IRemoteStorageResource $contentResource) { $resources = $contentResource->getResources(); $attachmentAsset->setFileExt($contentResource->getFileExt()); $attachmentAsset->incrementVersion(); $attachmentAsset->setStatus(AttachmentAsset::ASSET_STATUS_READY); $attachmentAsset->save(); $syncKey = $attachmentAsset->getSyncKey(AttachmentAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } }
/** * @param IRemoteStorageResource $resource * @param entry $dbEntry * @param asset $dbAsset * @return asset * @throws KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(IRemoteStorageResource $resource, entry $dbEntry, asset $dbAsset = null) { $resources = $resource->getResources(); $fileExt = $resource->getFileExt(); $dbEntry->setSource(KalturaSourceType::URL); // TODO - move image handling to media service if ($dbEntry->getMediaType() == KalturaMediaType::IMAGE) { $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } $dbEntry->setStatus(entryStatus::READY); $dbEntry->save(); return null; } $dbEntry->save(); $isNewAsset = false; if (!$dbAsset) { $isNewAsset = true; $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId()); } if (!$dbAsset) { KalturaLog::err("Flavor asset not created for entry [" . $dbEntry->getId() . "]"); if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) { $dbEntry->setStatus(entryStatus::ERROR_CONVERTING); $dbEntry->save(); } throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED); } $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } $dbAsset->setFileExt($fileExt); if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) { $dbAsset->setStatus(asset::FLAVOR_ASSET_STATUS_READY); } $dbAsset->save(); if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset)); } kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset)); if ($dbAsset instanceof flavorAsset && !$dbAsset->getIsOriginal()) { kBusinessPostConvertDL::handleConvertFinished(null, $dbAsset); } return $dbAsset; }
/** * * Allows to create additional files in the conversion process in addition to flavor asset */ private static function handleAdditionalFilesConvertFinished(flavorAsset $flavorAsset, BatchJob $dbBatchJob, kConvertJobData $data) { if (!$flavorAsset->getVersion() || !kFileSyncUtils::fileSync_exists($flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET))) { $flavorAsset->incrementVersion(); $flavorAsset->save(); } foreach ($data->getExtraDestFileSyncs() as $destFileSyncDesc) { $syncKey = $flavorAsset->getSyncKey($destFileSyncDesc->getFileSyncObjectSubType()); $flavorParamsOutput = $data->getFlavorParamsOutput(); $storageProfileId = $flavorParamsOutput->getSourceRemoteStorageProfileId(); if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) { kFileSyncUtils::moveFromFile($destFileSyncDesc->getFileSyncLocalPath(), $syncKey, false); } elseif ($flavorParamsOutput->getRemoteStorageProfileIds()) { $remoteStorageProfileIds = explode(',', $flavorParamsOutput->getRemoteStorageProfileIds()); foreach ($remoteStorageProfileIds as $remoteStorageProfileId) { $storageProfile = StorageProfilePeer::retrieveByPK($remoteStorageProfileId); kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $destFileSyncDesc->getFileSyncLocalPath(), $storageProfile); } } } }
/** * @param flavorAsset $flavorAsset * @param IRemoteStorageResource $contentResource * @throws KalturaErrors::STORAGE_PROFILE_ID_NOT_FOUND */ protected function attachRemoteStorageResource(flavorAsset $flavorAsset, IRemoteStorageResource $contentResource) { $resources = $contentResource->getResources(); $flavorAsset->setFileExt($contentResource->getFileExt()); $flavorAsset->incrementVersion(); $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); foreach ($resources as $currentResource) { $storageProfile = StorageProfilePeer::retrieveByPK($currentResource->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $currentResource->getUrl(), $storageProfile); } if ($flavorAsset->getIsOriginal()) { $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); } else { $flavorAsset->setStatusLocalReady(); } $flavorAsset->save(); kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset); }
protected function attachRemoteAssetResource(entry $entry, kDistributionSubmitJobData $data) { $distributionProfile = DistributionProfilePeer::retrieveByPK($data->getDistributionProfileId()); /* @var $distributionProfile UnicornDistributionProfile */ $domainGuid = $distributionProfile->getDomainGuid(); $applicationGuid = $distributionProfile->getAdFreeApplicationGuid(); $assetParamsId = $distributionProfile->getRemoteAssetParamsId(); $mediaItemGuid = $data->getRemoteId(); $url = "{$domainGuid}/{$applicationGuid}/{$mediaItemGuid}/content.m3u8"; $entry->setSource(KalturaSourceType::URL); $entry->save(); $isNewAsset = false; $asset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $assetParamsId); if (!$asset) { $isNewAsset = true; $assetParams = assetParamsPeer::retrieveByPK($assetParamsId); $asset = assetPeer::getNewAsset($assetParams->getType()); $asset->setPartnerId($entry->getPartnerId()); $asset->setEntryId($entry->getId()); $asset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); $asset->setFlavorParamsId($assetParamsId); $asset->setFromAssetParams($assetParams); if ($assetParams->hasTag(assetParams::TAG_SOURCE)) { $asset->setIsOriginal(true); } } $asset->incrementVersion(); $asset->setFileExt('m3u8'); $asset->setStatus(asset::FLAVOR_ASSET_STATUS_READY); $asset->save(); $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $storageProfile = StorageProfilePeer::retrieveByPK($distributionProfile->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $url, $storageProfile); if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($asset)); } kEventsManager::raiseEvent(new kObjectDataChangedEvent($asset)); kBusinessPostConvertDL::handleConvertFinished(null, $asset); }
/** * @param BatchJob $dbBatchJob * @param kConvertJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handleConvertFinished(BatchJob $dbBatchJob, kConvertJobData $data, BatchJob $twinJob = null) { KalturaLog::debug("Convert finished with destination file: " . $data->getDestFileSyncLocalPath()); if ($dbBatchJob->getAbort()) { kWAMS::getInstance($dbBatchJob->getPartnerId())->deleteAssetById($data->getDestFileSyncWamsAssetId()); return $dbBatchJob; } // verifies that flavor asset created if (!$data->getFlavorAssetId()) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId()); } $flavorAsset = assetPeer::retrieveById($data->getFlavorAssetId()); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId()); } $flavorAsset->incrementVersion(); $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $flavorParamsOutput = $data->getFlavorParamsOutput(); $storageProfileId = $flavorParamsOutput->getSourceRemoteStorageProfileId(); if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) { $destFileSyncWamsAssetId = $data->getDestFileSyncWamsAssetId(); if (!empty($destFileSyncWamsAssetId)) { kFileSyncUtils::addFromWAMS($destFileSyncWamsAssetId, $syncKey); } else { kFileSyncUtils::moveFromFile($data->getDestFileSyncLocalPath(), $syncKey); } } elseif ($flavorParamsOutput->getRemoteStorageProfileIds()) { $remoteStorageProfileIds = explode(',', $flavorParamsOutput->getRemoteStorageProfileIds()); foreach ($remoteStorageProfileIds as $remoteStorageProfileId) { $storageProfile = StorageProfilePeer::retrieveByPK($remoteStorageProfileId); kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $data->getDestFileSyncLocalPath(), $storageProfile); } } // creats the file sync if (file_exists($data->getLogFileSyncLocalPath())) { $logSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); try { kFileSyncUtils::moveFromFile($data->getLogFileSyncLocalPath(), $logSyncKey); } catch (Exception $e) { $err = 'Saving conversion log: ' . $e->getMessage(); KalturaLog::err($err); $desc = $dbBatchJob->getDescription() . "\n" . $err; $dbBatchJob->getDescription($desc); } } if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) { $data->setDestFileSyncLocalPath(kFileSyncUtils::getLocalFilePathForKey($syncKey)); KalturaLog::debug("Convert archived file to: " . $data->getDestFileSyncLocalPath()); // save the data changes to the db $dbBatchJob->setData($data); $dbBatchJob->save(); } $entry = $dbBatchJob->getEntry(); if (!$entry) { throw new APIException(APIErrors::INVALID_ENTRY, $dbBatchJob, $dbBatchJob->getEntryId()); } $offset = $entry->getThumbOffset(); // entry getThumbOffset now takes the partner DefThumbOffset into consideration $createThumb = $entry->getCreateThumb(); $extractMedia = true; if ($entry->getType() != entryType::MEDIA_CLIP) { // e.g. document $extractMedia = false; } $rootBatchJob = $dbBatchJob->getRootJob(); if ($extractMedia && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) { $rootBatchJobData = $rootBatchJob->getData(); if ($rootBatchJobData instanceof kConvertProfileJobData) { $extractMedia = $rootBatchJobData->getExtractMedia(); } } // For apple http flavors do not attempt to get thumbs and media info, // It is up to the operator to provide that kind of data, rather than hardcoded check // To-fix if ($flavorParamsOutput->getFormat() == assetParams::CONTAINER_FORMAT_APPLEHTTP) { $createThumb = false; $extractMedia = false; } if ($createThumb && in_array($flavorParamsOutput->getVideoCodec(), self::$thumbUnSupportVideoCodecs)) { $createThumb = false; } $operatorSet = new kOperatorSets(); $operatorSet->setSerialized(stripslashes($flavorParamsOutput->getOperators())); // KalturaLog::debug("Operators: ".$flavorParamsOutput->getOperators() // ."\ngetCurrentOperationSet:".$data->getCurrentOperationSet() // ."\ngetCurrentOperationIndex:".$data->getCurrentOperationIndex()); // KalturaLog::debug("Operators set: " . print_r($operatorSet, true)); $nextOperator = $operatorSet->getOperator($data->getCurrentOperationSet(), $data->getCurrentOperationIndex() + 1); $nextJob = null; if ($nextOperator) { // KalturaLog::debug("Found next operator"); $nextJob = kJobsManager::addFlavorConvertJob($syncKey, $flavorParamsOutput, $data->getFlavorAssetId(), $data->getMediaInfoId(), $dbBatchJob, $dbBatchJob->getJobSubType()); } if (!$nextJob) { if ($createThumb || $extractMedia) { $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR; if ($flavorAsset->getIsOriginal()) { $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_SOURCE; } kJobsManager::addPostConvertJob($dbBatchJob, $postConvertAssetType, $data->getDestFileSyncLocalPath(), $data->getFlavorAssetId(), $flavorParamsOutput->getId(), $createThumb, $offset, $data->getCustomData(), $data->getDestFileSyncWamsAssetId()); } else { $flavorAsset = kBusinessPostConvertDL::handleFlavorReady($dbBatchJob, $data->getFlavorAssetId()); if ($flavorAsset) { if ($flavorAsset->hasTag(flavorParams::TAG_SOURCE)) { kBusinessPreConvertDL::continueProfileConvert($dbBatchJob); } if ($flavorAsset->getType() == assetType::FLAVOR) { $flavorAsset->setBitrate($flavorParamsOutput->getVideoBitrate() + $flavorParamsOutput->getAudioBitrate()); $flavorAsset->setWidth($flavorParamsOutput->getWidth()); $flavorAsset->setHeight($flavorParamsOutput->getHeight()); $flavorAsset->setFrameRate($flavorParamsOutput->getFrameRate()); $flavorAsset->setIsOriginal(0); $flavorAsset->save(); } kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $flavorAsset); } } } // this logic decide when a thumbnail should be created if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { $localPath = kFileSyncUtils::getLocalFilePathForKey($syncKey); $downloadUrl = $flavorAsset->getDownloadUrl(); $notificationData = array("puserId" => $entry->getPuserId(), "entryId" => $entry->getId(), "entryIntId" => $entry->getIntId(), "entryVersion" => $entry->getVersion(), "fileFormat" => $flavorAsset->getFileExt(), "archivedFile" => $localPath, "downoladPath" => $localPath, "conversionQuality" => $entry->getConversionQuality(), "downloadUrl" => $downloadUrl); $extraData = array("data" => json_encode($notificationData), "partner_id" => $entry->getPartnerId(), "puser_id" => $entry->getPuserId(), "entry_id" => $entry->getId(), "entry_int_id" => $entry->getIntId(), "entry_version" => $entry->getVersion(), "file_format" => $flavorAsset->getFileExt(), "archived_file" => $localPath, "downolad_path" => $localPath, "target" => $localPath, "conversion_quality" => $entry->getConversionQuality(), "download_url" => $downloadUrl, "status" => $entry->getStatus(), "abort" => $dbBatchJob->getAbort(), "progress" => $dbBatchJob->getProgress(), "message" => $dbBatchJob->getMessage(), "description" => $dbBatchJob->getDescription(), "updates_count" => $dbBatchJob->getUpdatesCount(), "job_type" => BatchJobType::DOWNLOAD, "status" => BatchJob::BATCHJOB_STATUS_FINISHED, "progress" => 100, "debug" => __LINE__); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_BATCH_JOB_SUCCEEDED, $dbBatchJob, $dbBatchJob->getPartnerId(), null, null, $extraData, $dbBatchJob->getEntryId()); } return $dbBatchJob; }