private function handleConcatJobFinished(BatchJob $dbBatchJob, kConcatJobData $data) { $convertJobData = $dbBatchJob->getParentJob()->getData(); $files = self::getAssetDataFilesArray($convertJobData); $lastFileIndex = $convertJobData->getFileIndex(); $segmentDuration = 0; $amfArray = array(); foreach ($files as $file) { KalturaLog::debug('file is: ' . $file); if (self::getSegmentIndexFromFileName($file) <= $lastFileIndex) { $arr = unserialize(file_get_contents($files[0])); $currentSegmentDuration = $arr[0]; array_shift($arr); $amfArray = array_merge($amfArray, self::parseAmfArrayAndShift($arr, $segmentDuration)); $segmentDuration += $currentSegmentDuration; if (!unlink($file)) { KalturaLog::warning("failed to delete file " . $file); } } } self::copyCuePointsFromLiveToVodEntry($dbBatchJob->getParentJob()->getEntry()->getRecordedEntryId(), $data->getConcatenatedDuration(), $segmentDuration, $amfArray); }
/** * @param BatchJob $parentJob * @param flavorAsset $asset * @param array $files * @return BatchJob */ public static function addConcatJob(BatchJob $parentJob = null, flavorAsset $asset, array $files, $offset = null, $duration = null) { $jobData = new kConcatJobData(); $jobData->setSrcFiles($files); $jobData->setFlavorAssetId($asset->getId()); $jobData->setOffset($offset); $jobData->setDuration($duration); $entry = $asset->getentry(); if ($entry && $entry->getStatus() != entryStatus::READY) { $entry->setStatus(entryStatus::PRECONVERT); $entry->save(); } $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(BatchJobType::CONCAT); } else { $batchJob = new BatchJob(); $batchJob->setPartnerId($asset->getPartnerId()); } $batchJob->setEntryId($asset->getEntryId()); $batchJob->setObjectId($jobData->getFlavorAssetId()); $batchJob->setObjectType(BatchJobObjectType::ASSET); return self::addJob($batchJob, $jobData, BatchJobType::CONCAT); }
/** * @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; }