/** * Will forward to the regular swf player according to the widget_id */ public function execute() { $entryId = $this->getRequestParameter("entry_id"); $flavorId = $this->getRequestParameter("flavor"); $fileName = $this->getRequestParameter("file_name"); $ksStr = $this->getRequestParameter("ks"); $referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } // get entry $entry = entryPeer::retrieveByPK($entryId); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($entry->getPartnerId()); $securyEntryHelper = new KSecureEntryHelper($entry, $ksStr, $referrer); $securyEntryHelper->validateForDownload($entry, $ksStr); $flavorAsset = null; if ($flavorId) { // get flavor asset $flavorAsset = flavorAssetPeer::retrieveById($flavorId); if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } // the request flavor should belong to the requested entry if ($flavorAsset->getEntryId() != $entryId) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } } else { $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId()); } // Gonen 26-04-2010: in case entry has no flavor with 'mbr' tag - we return the source if (!$flavorAsset && ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_VIDEO || $entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO)) { $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId); } if ($flavorAsset) { $syncKey = $this->getSyncKeyAndForFlavorAsset($entry, $flavorAsset); } else { $syncKey = $this->getBestSyncKeyForEntry($entry); } list($fileBaseName, $fileExt) = $this->getFileName($entry, $flavorAsset); if (!$fileName) { $fileName = $fileBaseName; } if ($fileExt) { $fileName = $fileName . '.' . $fileExt; } if (is_null($syncKey)) { KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $this->handleFileSyncRedirection($syncKey); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $this->dumpFile($filePath, $fileName); die; // no view }
/** * Get base entry by flavor ID with no filters. * * @action getByFlavorId * @param string $flavorId * @param int $version Desired version of the data * @return KalturaBaseEntry The requested entry */ public function getByFlavorIdAction($flavorId, $version = -1) { $flavorAssetDb = flavorAssetPeer::retrieveById($flavorId); if (!$flavorAssetDb) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $flavorId); } return $this->getAction($flavorAssetDb->getEntryId(), $version); }
public function getEntryId(FileSync $fileSync) { if ($fileSync->getObjectType() == FileSyncObjectType::ENTRY) { return $fileSync->getObjectId(); } if ($fileSync->getObjectType() == FileSyncObjectType::BATCHJOB) { $job = BatchJobPeer::retrieveByPK($fileSync->getObjectId()); if ($job) { return $job->getEntryId(); } } if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET) { $flavor = flavorAssetPeer::retrieveById($fileSync->getObjectId()); if ($flavor) { return $flavor->getEntryId(); } } return null; }
/** * * @param int $objectType * @param string $objectId * @return ISyncableFile */ public static function retrieveObject($objectType, $objectId) { $object = null; switch ($objectType) { case FileSyncObjectType::ENTRY: entryPeer::setUseCriteriaFilter(false); $object = entryPeer::retrieveByPK($objectId); entryPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::UICONF: uiConfPeer::setUseCriteriaFilter(false); $object = uiConfPeer::retrieveByPK($objectId); uiConfPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::BATCHJOB: BatchJobPeer::setUseCriteriaFilter(false); $object = BatchJobPeer::retrieveByPK($objectId); BatchJobPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::FLAVOR_ASSET: flavorAssetPeer::setUseCriteriaFilter(false); $object = flavorAssetPeer::retrieveById($objectId); flavorAssetPeer::setUseCriteriaFilter(true); break; case FileSyncObjectType::SYNDICATION_FEED: syndicationFeedPeer::setUseCriteriaFilter(false); $object = syndicationFeedPeer::retrieveByPK($objectId); syndicationFeedPeer::setUseCriteriaFilter(true); break; } if ($object == null) { $object = KalturaPluginManager::loadObject('ISyncableFile', $objectType, array('objectId' => $objectId)); } if ($object == null) { $error = __METHOD__ . " Cannot find object type [" . $objectType . "] with object_id [" . $objectId . "]"; KalturaLog::err($error); throw new Exception($error); } return $object; }
/** * Copy flavor asset into new entry * * @action addFromFlavorAsset * @param string $sourceFlavorAssetId Flavor asset id to be used as the new entry source * @param KalturaMediaEntry $mediaEntry Media entry metadata * @return KalturaMediaEntry The new media entry * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::ORIGINAL_FLAVOR_ASSET_NOT_CREATED */ function addFromFlavorAssetAction($sourceFlavorAssetId, KalturaMediaEntry $mediaEntry = null) { $srcFlavorAsset = flavorAssetPeer::retrieveById($sourceFlavorAssetId); if (!$srcFlavorAsset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $sourceFlavorAssetId); } $sourceEntryId = $srcFlavorAsset->getEntryId(); $srcEntry = entryPeer::retrieveByPK($sourceEntryId); if (!$srcEntry || $srcEntry->getType() != entryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $sourceEntryId); } if ($mediaEntry === null) { $mediaEntry = new KalturaMediaEntry(); } $mediaEntry->mediaType = $srcEntry->getMediaType(); return $this->addEntryFromFlavorAsset($mediaEntry, $srcEntry, $srcFlavorAsset); }
/** * @param BatchJob $dbBatchJob * @param kConvertProfileJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handleConvertProfilePending(BatchJob $dbBatchJob, kConvertProfileJobData $data, BatchJob $twinJob = null) { KalturaLog::debug("Convert Profile created, with input file: " . $data->getInputFileSyncLocalPath()); if ($data->getExtractMedia()) { // creates extract media job kJobsManager::addExtractMediaJob($dbBatchJob, $data->getInputFileSyncLocalPath(), $data->getFlavorAssetId(), mediaInfo::ASSET_TYPE_ENTRY_INPUT); } else { $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $dbBatchJob); if ($conversionsCreated) { // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules $currentFlavorAsset = flavorAssetPeer::retrieveById($data->getFlavorAssetId()); if ($currentFlavorAsset) { $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } } } // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); return $dbBatchJob; }
public function execute() { requestUtils::handleConditionalGet(); $flavorId = $this->getRequestParameter("flavorId"); $shouldProxy = $this->getRequestParameter("forceproxy", false); $ks = $this->getRequestParameter("ks"); $fileParam = $this->getRequestParameter("file"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $flavorAsset = flavorAssetPeer::retrieveById($flavorId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId()); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($flavorAsset->getPartnerId()); myPartnerUtils::enforceDelivery($flavorAsset->getPartnerId()); //disabled enforce cdn because of rtmp delivery //requestUtils::enforceCdnDelivery($flavorAsset->getPartnerId()); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } // always dump remote urls so they will be cached by the cdn transparently $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFile::dumpUrl($remoteUrl, true, true); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); $flvWrapper = new myFlvHandler($path); $isFlv = $flvWrapper->isFlv(); $clipFrom = $this->getRequestParameter("clipFrom", 0); // milliseconds $clipTo = $this->getRequestParameter("clipTo", 2147483647); // milliseconds if ($clipTo == 0) { $clipTo = 2147483647; } if (is_dir($path) && $fileParam) { $path .= "/{$fileParam}"; //echo "path($path),file($fileParam)"; kFile::dumpFile($path, null, null); die; } else { if (!$isFlv) { $limit_file_size = 0; if ($clipTo != 2147483647) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $limit_file_size = floor(@filesize($path) * ($clipTo / $duration)); } } kFile::dumpFile($path, null, null, $limit_file_size); die; } } $audioOnly = $this->getRequestParameter("audioOnly"); // milliseconds if ($audioOnly === '0') { // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) { $audioOnly = true; } $seekFrom = $this->getRequestParameter("seekFrom", -1); if ($seekFrom <= 0) { $seekFrom = -1; } $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1); if ($seekFromBytes <= 0) { $seekFromBytes = -1; } $bytes = 0; if ($seekFrom !== -1 && $seekFrom !== 0) { list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly); list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly); $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte; } else { list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); } $metadataSize = $flvWrapper->getMetadataSize($audioOnly); $dataOffset = $metadataSize + myFlvHandler::getHeaderSize(); $totalLength = $dataOffset + $bytes; list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly); list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength); if ($totalLength < 1000) { // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache requestUtils::sendCdnHeaders("flv", $rangeLength, 0); } else { requestUtils::sendCdnHeaders("flv", $rangeLength); } header('Content-Disposition: attachment; filename="video.flv"'); // dont inject cuepoint into the stream $cuepointTime = 0; $cuepointPos = 0; try { Propel::close(); } catch (Exception $e) { $this->logMessage("serveFlavor: error closing db {$e}"); } header("Content-Type: video/x-flv"); $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos); die; }
protected function updatedVirusScanFailed(BatchJob $dbBatchJob, kVirusScanJobData $data, BatchJob $twinJob = null) { $entry = entryPeer::retrieveByPK($dbBatchJob->getEntryId()); if ($entry) { $entry->setStatus(VirusScanPlugin::getEntryStatusCoreValue(VirusScanEntryStatus::INFECTED)); $entry->save(); } else { KalturaLog::err('Entry not found with id [' . $dbBatchJob->getEntryId() . ']'); throw new Exception('Entry not found with id [' . $dbBatchJob->getEntryId() . ']'); } $flavorAsset = flavorAssetPeer::retrieveById($data->getFlavorAssetId()); if ($flavorAsset) { $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); } else { KalturaLog::err('Flavor asset not found with id [' . $data->getFlavorAssetId() . ']'); throw new Exception('Flavor asset not found with id [' . $data->getFlavorAssetId() . ']'); } // do not resume flavor asset added event consumption return $dbBatchJob; }
private function calculateId() { $dc = kDataCenterMgr::getCurrentDc(); for ($i = 0; $i < 10; $i++) { $id = $dc["id"] . '_' . kString::generateStringId(); $existingObject = flavorAssetPeer::retrieveById($id); if ($existingObject) { KalturaLog::log(__METHOD__ . ": id [{$id}] already exists"); } else { return $id; } } throw new Exception("Could not find unique id for flavorAsset"); }
private function serveRtmp() { switch ($this->entry->getType()) { case entryType::MEDIA_CLIP: $duration = $this->entry->getDurationInt(); $flavorAssets = array(); if ($this->flavorId) { $flavorAsset = flavorAssetPeer::retrieveById($this->flavorId); if (!$flavorAsset->hasTag(flavorParams::TAG_WEB)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if (!$flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $flavorAssets[] = $flavorAsset; } else { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_MBR); if (!count($flavorAssets)) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB); } } $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets); if (!$this->storageId) { $partner = $this->entry->getPartner(); $finalFlavors = array(); if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) { foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key); if ($fileSync) { $finalFlavors[] = $flavorAsset; } } } if (!count($finalFlavors) && $partner->getStorageServePriority() && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { $storages = StorageProfilePeer::retrieveExternalByPartnerId($partner->getId()); if (count($storages) == 1) { $this->storageId = $storages[0]->getId(); } elseif (count($storages)) { $storagesFlavors = array(); foreach ($storages as $storage) { $storagesFlavors[$storage->getId()] = array(); foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storage->getId()); if ($fileSync) { $storagesFlavors[$storage->getId()][] = $flavorAsset; } } } $maxCount = 0; foreach ($storagesFlavors as $storageId => $storageFlavors) { $count = count($storageFlavors); if ($count > $maxCount) { $maxCount = $count; $this->storageId = $storageId; $finalFlavors = $storageFlavors; } } $flavorAssets = $finalFlavors; } else { foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key); if ($fileSync) { $finalFlavors[] = $flavorAsset; } } } } } foreach ($flavorAssets as $flavorAsset) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $duration /= 1000; break; } } $baseUrl = null; $flavors = array(); if ($this->storageId) { $storage = StorageProfilePeer::retrieveByPK($this->storageId); if (!$storage) { die; } $baseUrl = $storage->getDeliveryRmpBaseUrl(); // get all flavors with external urls foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId); if (!$fileSync) { continue; } $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc()); $urlManager->setClipTo($this->clipTo); $urlManager->setFileExtension($flavorAsset->getFileExt()); $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP); $url = $urlManager->getFileSyncUrl($fileSync); $url = preg_replace('/^\\//', '', $url); $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight()); } } else { $partnerId = $this->entry->getPartnerId(); $subpId = $this->entry->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId); $baseUrl = myPartnerUtils::getRtmpUrl($partnerId); $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost); // get all flavors with kaltura urls foreach ($flavorAssets as $flavorAsset) { $urlManager->setClipTo($this->clipTo); $urlManager->setFileExtension($flavorAsset->getFileExt()); $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP); $url = $urlManager->getFlavorAssetUrl($flavorAsset); $url = preg_replace('/^\\//', '', $url); $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight()); } } if (!count($flavors)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if (strpos($this->protocol, "rtmp") === 0) { $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl); } return $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, $flavors, 'video/x-flv', $duration, $baseUrl); case entryType::LIVE_STREAM: $streamId = $this->entry->getStreamRemoteId(); $streamUsername = $this->entry->getStreamUsername(); $baseUrl = $this->entry->getStreamUrl(); $baseUrl = rtrim($baseUrl, '/'); $flavors = $this->entry->getStreamBitrates(); if (count($flavors)) { foreach ($flavors as $index => $flavor) { $brIndex = $index + 1; $flavors[$index]['url'] = str_replace('%i', $brIndex, $this->entry->getStreamName()); } } else { $flavors[0]['url'] = str_replace('%i', '1', $this->entry->getStreamName()); } if (strpos($this->protocol, "rtmp") === 0) { $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl); } return $this->buildXml(self::PLAY_STREAM_TYPE_LIVE, $flavors, 'video/x-flv', null, $baseUrl); } KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE); }
public function execute() { requestUtils::handleConditionalGet(); $entry_id = $this->getRequestParameter("entry_id"); $ks_str = $this->getRequestParameter("ks"); $base64_referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64_referrer); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ""; } $clip_from = $this->getRequestParameter("clip_from", 0); // milliseconds $clip_to = $this->getRequestParameter("clip_to", 2147483647); // milliseconds if ($clip_to == 0) { $clip_to = 2147483647; } $request = $_SERVER["REQUEST_URI"]; // remove dynamic fields from the url so we'll request a single url from the cdn $request = str_replace("/referrer/{$base64_referrer}", "", $request); $request = str_replace("/ks/{$ks_str}", "", $request); // workaround the filter which hides all the deleted entries - // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here $entry = entryPeer::retrieveByPKNoFilter($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } myPartnerUtils::blockInactivePartner($entry->getPartnerId()); // set the memory size to be able to serve big files in a single chunk ini_set("memory_limit", "64M"); // set the execution time to be able to serve big files in a single chunk ini_set("max_execution_time", 240); if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) { // because the fiter was turned off - a manual check for deleted entries must be done. die; } else { if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $version = $this->getRequestParameter("version", null); $width = $this->getRequestParameter("width", -1); $height = $this->getRequestParameter("height", -1); $crop_provider = $this->getRequestParameter("crop_provider", null); $bgcolor = $this->getRequestParameter("bgcolor", "ffffff"); $type = $this->getRequestParameter("type", 1); $quality = $this->getRequestParameter("quality", 0); $src_x = $this->getRequestParameter("src_x", 0); $src_y = $this->getRequestParameter("src_y", 0); $src_w = $this->getRequestParameter("src_w", 0); $src_h = $this->getRequestParameter("src_h", 0); $vid_sec = $this->getRequestParameter("vid_sec", -1); $vid_slice = $this->getRequestParameter("vid_slice", -1); $vid_slices = $this->getRequestParameter("vid_slices", -1); if ($width == -1 && $height == -1) { $width = 640; $height = 480; } else { if ($width == -1) { // if only either width or height is missing reset them to zero, and convertImage will handle them $width = 0; } else { if ($height == -1) { $height = 0; } } } $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices); kFile::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0); } } $audio_only = $this->getRequestParameter("audio_only"); // milliseconds $flavor = $this->getRequestParameter("flavor", 1); // $flavor_param_id = $this->getRequestParameter("flavor_param_id", null); // $streamer = $this->getRequestParameter("streamer"); // if (substr($streamer, 0, 4) == "rtmp") { // the fms may add .mp4 to the end of the url $streamer = "rtmp"; } // grab seek_from_bytes parameter and normalize url $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1); $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request); if ($seek_from_bytes <= 0) { $seek_from_bytes = -1; } // grab seek_from parameter and normalize url $seek_from = $this->getRequestParameter("seek_from", -1); $request = str_replace("/seek_from/{$seek_from}", "", $request); if ($seek_from <= 0) { $seek_from = -1; } $this->dump_from_byte = 0; // reset accurate seek from timestamp $seek_from_timestamp = -1; // backward compatibility if ($flavor === "0") { // for edit version $flavor = "edit"; } if ($flavor === "1" || $flavor === 1) { // for play version $flavor = null; } // when flavor is null, we will get a default flavor if ($flavor == "edit") { $flavorAsset = flavorAssetPeer::retrieveBestEditByEntryId($entry->getId()); } elseif (!is_null($flavor)) { $flavorAsset = flavorAssetPeer::retrieveById($flavor); // when specific asset was request, we don't validate its tags if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) { $flavorAsset = null; } // we will throw an error later } elseif (is_null($flavor) && !is_null($flavor_param_id)) { $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entry->getId(), $flavor_param_id); if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { $flavorAsset = null; } // we will throw an error later } else { if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) { $flavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); } else { $flavorAsset = flavorAssetPeer::retrieveBestPlayByEntryId($entry->getId()); } if (!$flavorAsset) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB); if (count($flavorAssets) > 0) { $flavorAsset = $flavorAssets[0]; } } } if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); if (kFileSyncUtils::file_exists($syncKey, false)) { $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); } else { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); $this->redirect($remoteUrl); } $flv_wrapper = new myFlvHandler($path); $isFlv = $flv_wrapper->isFlv(); // scrubbing is not allowed within mp4 files if (!$isFlv) { $seek_from = $seek_from_bytes = -1; } if ($seek_from !== -1 && $seek_from !== 0) { if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only); list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only); $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte; } // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath(); $extStorageUrl = $entry->getExtStorageUrl(); if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $request_host = parse_url($extStorageUrl, PHP_URL_HOST); $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl); $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); die; } elseif ($extStorageUrl) { // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$extStorageUrl}"); die; } // use headers to detect cdn $cdn_name = ""; $via_header = @$_SERVER["HTTP_VIA"]; if (strpos($via_header, "llnw.net") !== false) { $cdn_name = "limelight"; } else { if (strpos($via_header, "akamai") !== false) { $cdn_name = "akamai"; } else { if (strpos($via_header, "Level3") !== false) { $cdn_name = "level3"; } } } // setting file extension - first trying frrom flavor asset $ext = $flavorAsset->getFileExt(); // if failed, set extension according to file type (isFlv) if (!$ext) { $ext = $isFlv ? "flv" : "mp4"; } $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0"; // dont check for rtmp / and for an already redirect url if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // check security using ks $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer); if ($securyEntryHelper->shouldPreview()) { $this->checkForPreview($securyEntryHelper, $clip_to); } else { $securyEntryHelper->validateForPlay($entry, $ks_str); } } else { // if needs security check using cdn authentication mechanism // for now assume this is a cdn request and don't check for security } // use limelight mediavault if either security policy requires it or if we're trying to seek within the video if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) { // we have three options: // arrived through limelight mediavault url - the url is secured // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url // didnt use limelight - enforce ks // the cdns are configured to authenticate request for /s/.... // check if we're already in a redirected secure link using the "/s/" prefix $secure_request = substr($request, 0, 3) == "/s/"; if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) { // request was validated by cdn let it through } else { // extract ks $ks_str = $this->getRequestParameter("ks", ""); if ($entry->getSecurityPolicy()) { if (!$ks_str) { $this->logMessage("flvclipper - no KS"); die; } $ks = kSessionUtils::crackKs($ks_str); if (!$ks) { $this->logMessage("flvclipper - invalid ks [{$ks_str}]"); die; } $matched_privs = $ks->verifyPrivileges("sview", $entry_id); $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]"); if (!$matched_privs) { $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]"); die; } } if ($cdn_name == "limelight") { $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension; $secret = kConf::get("limelight_madiavault_password"); $expire = "&e=" . (time() + 120); $ll_url .= $expire; $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}"; $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs; //header("Location: $ll_url"); $this->redirect($ll_url); } else { if ($cdn_name == "level3") { $level3_url = $request . $flv_extension; if ($entry->getSecurityPolicy()) { $level3_url = "/s{$level3_url}"; // set expire time in GMT hence the date("Z") offset $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30); $level3_url .= $expire; $secret = kConf::get("level3_authentication_key"); $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20); $level3_url .= "&h={$hash}"; } $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}"; header("Location: {$level3_url}"); die; } else { if ($cdn_name == "akamai") { $akamai_url = $request . $flv_extension; // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from if ($seek_from_timestamp == -1) { $seek_from_timestamp = $seek_from; } $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000); header("Location: {$akamai_url}"); die; } } } // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $this->dump_from_byte = $seek_from_bytes; } } } // always add the file suffix to the request (needed for scrubbing by some cdns, // and also breaks without extension on some corporate antivirus). // we add the the novar paramter since a leaving a trailing "?" will be trimmed // and then the /seek_from request will result in another url which level3 // will try to refetch from the origin // note that for streamer we dont add the file extension if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) { // a seek request without a supporting cdn - we need to send the answer from our server if ($seek_from_bytes !== -1 && $via_header === null) { $request .= "/seek_from_bytes/{$seek_from_bytes}"; } requestUtils::sendCdnHeaders("flv", 0); header("Location: {$request}" . $flv_extension); die; } // mp4 if (!$isFlv) { kFile::dumpFile($path); } $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning"); if ($audio_only === '0') { // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) { $audio_only = true; } //$start = microtime(true); list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only); $metadata_size = $flv_wrapper->getMetadataSize($audio_only); $this->from_byte = $from_byte; $this->to_byte = $to_byte; //$end1 = microtime(true); //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]"); $data_offset = $metadata_size + myFlvHandler::getHeaderSize(); // if we're returning a partial file adjust the total size: // substract the metadata and bytes which are not delivered if ($this->dump_from_byte >= $data_offset && !$audio_only) { $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset); } $this->total_length = $data_offset + $bytes; //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die; $this->cuepoint_time = 0; $this->cuepoint_pos = 0; if ($streamer == "chunked" && $clip_to != 2147483647) { $this->cuepoint_time = $clip_to - 1; $this->cuepoint_pos = $cuepoint_pos; $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE; } //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" ); $this->flv_wrapper = $flv_wrapper; $this->audio_only = $audio_only; try { Propel::close(); } catch (Exception $e) { $this->logMessage("flvclipperAction: error closing db {$e}"); } return sfView::SUCCESS; }
/** * Will forward to the regular swf player according to the widget_id */ public function execute() { // where file is {entryId/flavorId}.{ism,ismc,ismv} $objectId = $type = null; $objectIdStr = $this->getRequestParameter("objectId"); list($objectId, $type) = @explode(".", $objectIdStr); if (!$type || !$objectId) { die; } $ks = $this->getRequestParameter("ks"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } if ($type == "ism" || $type == "ismc") { // backward compatiblity - to be removed once ismc is created with pure objectId.ext instead of entryId_flavorId_version.ext if (strlen($objectId) != 10) { $version = substr($objectId, 13); $objectId = substr($objectId, 0, 10); } else { $version = null; } $entry = entryPeer::retrieveByPK($objectId); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } $syncKey = $entry->getSyncKey($type == "ism" ? entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM : entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC, $version); } else { if ($type == "ismv") { // backward compatiblity - to be removed once ismc is created with pure objectId.ext instead of entryId_flavorId_version.ext if (strlen($objectId) != 10) { $version = substr($objectId, 22); $objectId = substr($objectId, 11, 10); } else { $version = null; } $flavorAsset = flavorAssetPeer::retrieveById($objectId); if (is_null($flavorAsset)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId()); if (is_null($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version); } else { die; } } if (!kFileSyncUtils::file_exists($syncKey, false)) { list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if (is_null($fileSync)) { KalturaLog::log("Error - no FileSync for type [{$type}] objectId [{$objectId}]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); kFile::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); kFile::dumpFile($path); }
/** * Get download URL for the Flavor Asset * * @action getDownloadUrl * @param string $id * @param bool $useCdn * @return string */ public function getDownloadUrlAction($id, $useCdn = false) { $flavorAssetDb = flavorAssetPeer::retrieveById($id); if (!$flavorAssetDb) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $id); } if ($flavorAssetDb->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { throw new KalturaAPIEXception(KalturaErrors::FLAVOR_ASSET_IS_NOT_READY); } return $flavorAssetDb->getDownloadUrl($useCdn); }
/** * @param BatchJob $batchJob * @param entry $entry * @param string $flavorAssetId * @param string $inputFileSyncLocalPath * @return BatchJob */ public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath) { // if file size is 0, do not create conversion profile and set entry status as error converting if (filesize($inputFileSyncLocalPath) == 0) { $entry->setStatus(entryStatus::ERROR_CONVERTING); $entry->save(); $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->setDescription('Entry of size 0 should not be converted'); $flavorAsset->save(); KalturaLog::err('Entry of size 0 should not be converted'); return null; } if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) { $entry->setStatus(entryStatus::PENDING); $entry->save(); KalturaLog::notice('Entry should not be converted'); return null; } if ($entry->getStatus() != entryStatus::READY) { $entry->setStatus(entryStatus::PRECONVERT); $entry->save(); } $jobData = new kConvertProfileJobData(); $jobData->setFlavorAssetId($flavorAssetId); $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath); $jobData->setExtractMedia(true); if ($entry->getType() != entryType::MEDIA_CLIP) { $jobData->setExtractMedia(false); $jobData->setCreateThumb(false); } $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($entry->getId()); $batchJob->setPartnerId($entry->getPartnerId()); } return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE); }
/** * @param BaseObject $object */ protected function setRelatedObject(AuditTrail $auditTrail, BaseObject $object) { if (class_exists('Metadata') && $object instanceof Metadata) { $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getMetadataProfileId()); } if ($auditTrail->getAction() == AuditTrail::AUDIT_TRAIL_ACTION_FILE_SYNC_CREATED) { $peer = $object->getPeer(); $objectType = $peer->getOMClass(false, null); $auditTrail->setRelatedObjectType($objectType); $auditTrail->setRelatedObjectId($object->getId()); } if ($object instanceof FileSync) { switch ($object->getObjectType()) { case FileSyncObjectType::ENTRY: $auditTrail->setRelatedObjectType(AuditTrailObjectType::ENTRY); $auditTrail->setRelatedObjectId($object->getObjectId()); $auditTrail->setEntryId($object->getObjectId()); break; case FileSyncObjectType::UICONF: $auditTrail->setRelatedObjectType(AuditTrailObjectType::UI_CONF); $auditTrail->setRelatedObjectId($object->getObjectId()); break; case FileSyncObjectType::BATCHJOB: $auditTrail->setRelatedObjectType(AuditTrailObjectType::BATCH_JOB); $auditTrail->setRelatedObjectId($object->getObjectId()); $batchJob = BatchJobPeer::retrieveByPK($object->getObjectId()); if ($batchJob) { $auditTrail->setEntryId($batchJob->getEntryId()); } break; case FileSyncObjectType::FLAVOR_ASSET: $auditTrail->setRelatedObjectType(AuditTrailObjectType::FLAVOR_ASSET); $auditTrail->setRelatedObjectId($object->getObjectId()); $flavorAsset = flavorAssetPeer::retrieveById($object->getObjectId()); if ($flavorAsset) { $auditTrail->setEntryId($flavorAsset->getEntryId()); } break; case FileSyncObjectType::METADATA: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA); $auditTrail->setRelatedObjectId($object->getObjectId()); if (class_exists('Metadata')) { $metadata = MetadataPeer::retrieveByPK($object->getObjectId()); if ($metadata && $metadata->getObjectType() == Metadata::TYPE_ENTRY) { $auditTrail->setEntryId($metadata->getObjectId()); } } break; case FileSyncObjectType::METADATA_PROFILE: $auditTrail->setRelatedObjectType(AuditTrailObjectType::METADATA_PROFILE); $auditTrail->setRelatedObjectId($object->getObjectId()); break; } } }
/** * Add the data to the flavor asset conversion log, creates it if doesn't exists * * @action logConversion * @param string $flavorAssetId * @param string $data */ function logConversionAction($flavorAssetId, $data) { $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $flavorAsset->incLogFileVersion(); $flavorAsset->save(); $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); $log = kFileSyncUtils::file_get_contents($syncKey, true, false); $log .= $data; kFileSyncUtils::file_put_contents($syncKey, $log, false); }
/** * Scan flavor asset according to virus scan profile * * @action scan * @param int $virusScanProfileId * @param string $flavorAssetId * @return int job id * * @throws KalturaErrors::INVALID_OBJECT_ID * @throws KalturaErrors::INVALID_FLAVOR_ASSET_ID * @throws KalturaErrors::INVALID_FILE_SYNC_ID */ function scanAction($flavorAssetId, $virusScanProfileId = null) { $dbFlavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); if (!$dbFlavorAsset) { throw new KalturaAPIException(KalturaErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } if ($virusScanProfileId) { $dbVirusScanProfile = VirusScanProfilePeer::retrieveByPK($virusScanProfileId); } else { $dbVirusScanProfile = VirusScanProfilePeer::getSuitableProfile($dbFlavorAsset->getEntryId()); } if (!$dbVirusScanProfile) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $virusScanProfileId); } $syncKey = $dbFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey); if (!$srcFilePath) { throw new KalturaAPIException(KalturaErrors::INVALID_FILE_SYNC_ID, $syncKey); } $job = kVirusScanJobsManager::addVirusScanJob(null, $dbFlavorAsset->getPartnerId(), $dbFlavorAsset->getEntryId(), $dbFlavorAsset->getId(), $srcFilePath, $dbVirusScanProfile->getEngineType(), $dbVirusScanProfile->getActionIfInfected()); return $job->getId(); }
public static function handleConvertFailed(BatchJob $dbBatchJob, $engineType, $flavorAssetId, $flavorParamsOutputId, $mediaInfoId) { $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$flavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); // try to create a convert job with the next engine if (!is_null($engineType)) { $data = $dbBatchJob->getData(); if ($data instanceof kConvartableJobData) { $data->incrementOperationSet(); $dbBatchJob->setData($data); $dbBatchJob->save(); } $newDbBatchJob = kBusinessPreConvertDL::redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, $dbBatchJob, $engineType); if ($newDbBatchJob) { return true; } } // find the root job $rootBatchJob = $dbBatchJob->getRootJob(); if (!$rootBatchJob) { return false; } // the root is already failed if ($rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED || $rootBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FATAL) { return false; } // failing a remote root job if ($rootBatchJob->getJobType() == BatchJobType::REMOTE_CONVERT) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } // bulk download root job no need to handle if ($rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) { kJobsManager::failBatchJob($rootBatchJob, "Convert job " . $dbBatchJob->getId() . " failed"); return false; } if (is_null($flavorParamsOutputId)) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_CONVERTING); return false; } $readyBehavior = $dbBatchJob->getData()->getReadyBehavior(); if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) { kJobsManager::failBatchJob($rootBatchJob, "Job " . $dbBatchJob->getId() . " failed"); kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_CONVERTING); return false; } // failing the root profile job if all child jobs failed if ($rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) { return false; } $siblingJobs = $rootBatchJob->getChildJobs(); foreach ($siblingJobs as $siblingJob) { // not conversion job and should be ignored if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) { continue; } // found child flavor asset that hasn't failed, no need to fail the root job $siblingFlavorAssetId = $siblingJob->getData()->getFlavorAssetId(); $siblingFlavorAsset = flavorAssetPeer::retrieveById($siblingFlavorAssetId); if ($siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_ERROR && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE && $siblingFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return false; } } // all conversions failed, should fail the root job kJobsManager::failBatchJob($rootBatchJob, "All conversions failed"); kBatchManager::updateEntry($dbBatchJob, entryStatus::ERROR_CONVERTING); return false; }
/** * batch addMediaInfo adds a media info and updates the flavor asset * * @param mediaInfo $mediaInfoDb * @return mediaInfo */ public static function addMediaInfo(mediaInfo $mediaInfoDb) { $mediaInfoDb->save(); KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]"); if (!$mediaInfoDb->getFlavorAssetId()) { return $mediaInfoDb; } $flavorAsset = flavorAssetPeer::retrieveById($mediaInfoDb->getFlavorAssetId()); if (!$flavorAsset) { return $mediaInfoDb; } if ($flavorAsset->getIsOriginal()) { KalturaLog::log("Media info is for the original flavor asset"); $tags = null; $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId()); if ($profile) { $tags = $profile->getInputTagsMap(); } KalturaLog::log("Flavor asset tags from profile [{$tags}]"); if (!is_null($tags)) { $tagsArray = explode(',', $tags); // support for old migrated profiles if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) { if (!KDLWrap::CDLIsFLV($mediaInfoDb)) { $key = array_search(flavorParams::TAG_MBR, $tagsArray); unset($tagsArray[$key]); } } $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray); $finalTags = join(',', $finalTagsArray); KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]"); $flavorAsset->setTags($finalTags); } } KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");"); KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset); $flavorAsset->save(); // if(!$flavorAsset->hasTag(flavorParams::TAG_MBR)) // return $mediaInfoDb; $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId()); if (!$entry) { return $mediaInfoDb; } $contentDuration = $mediaInfoDb->getContainerDuration(); if (!$contentDuration) { $contentDuration = $mediaInfoDb->getVideoDuration(); if (!$contentDuration) { $contentDuration = $mediaInfoDb->getAudioDuration(); } } $entry->setLengthInMsecs($contentDuration); if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) { $entry->setDimensions($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight()); } $entry->save(); return $mediaInfoDb; }