/** * Handles xml bulk upload update * @param SimpleXMLElement $item * @throws KalturaException */ protected function handleItemUpdate(SimpleXMLElement $item) { KalturaLog::debug("xml [" . $item->asXML() . "]"); $entryId = null; $conversionProfileId = null; if (isset($item->entryId)) { $entryId = "{$item->entryId}"; $existingEntry = $this->getEntry($entryId); if (!$existingEntry) { throw new KalturaBatchException("Entry id [{$entryId}] not found", KalturaBatchJobAppErrors::BULK_ITEM_NOT_FOUND); } $conversionProfileId = $existingEntry->conversionProfileId; } elseif (isset($item->referenceId)) { $existingEntry = $this->getEntryFromReference("{$item->referenceId}"); if (!$existingEntry) { throw new KalturaBatchException("Reference id [{$item->referenceId}] not found", KalturaBatchJobAppErrors::BULK_ITEM_NOT_FOUND); } $entryId = $existingEntry->id; $conversionProfileId = $existingEntry->conversionProfileId; } else { throw new KalturaBatchException("Missing entry id element", KalturaBatchJobAppErrors::BULK_MISSING_MANDATORY_PARAMETER); } // Overwriting conversionProfileId if one is supplied in the XML if (isset($item->conversionProfileId) || isset($item->conversionProfile)) { $conversionProfileId = $this->getConversionProfileId($item); } KalturaLog::DEBUG("Conversion profile found within XML - setting to [ {$conversionProfileId} ]"); //Throw exception in case of max proccessed items and handle all exceptions there $updatedEntryBulkUploadResult = $this->createUploadResult($item, KalturaBulkUploadAction::UPDATE); if ($this->exceededMaxRecordsEachRun) { // exit if we have proccessed max num of items return; } $entry = $this->createEntryFromItem($item, $existingEntry->type); //Creates the entry from the item element $this->handleTypedElement($entry, $item); //Sets the typed element values (Mix, Media, ...) KalturaLog::debug("current entry is: " . print_r($entry, true)); $thumbAssets = array(); $thumbAssetsResources = array(); $flavorAssets = array(); $flavorAssetsResources = array(); $noParamsThumbAssets = array(); //Holds the no flavor params thumb assests $noParamsThumbResources = array(); //Holds the no flavor params resources assests $noParamsFlavorAssets = array(); //Holds the no flavor params flavor assests $noParamsFlavorResources = array(); //Holds the no flavor params flavor resources $flavorAssetsForUpdate = array(); $flavorResources = array(); $thumbAssetsForUpdate = array(); $thumbResources = array(); $resource = new KalturaAssetsParamsResourceContainers(); // holds all teh needed resources for the conversion $resource->resources = array(); if (isset($item->contentAssets->action) && isset($item->thumbnails->action)) { $contentAssetsAction = strtolower($item->contentAssets->action); $thumbnailsAction = strtolower($item->thumbnails->action); } elseif (isset($item->contentAssets->action)) { $contentAssetsAction = strtolower($item->contentAssets->action); $thumbnailsAction = strtolower($item->contentAssets->action); } elseif (isset($item->thumbnails->action)) { $contentAssetsAction = strtolower($item->thumbnails->action); $thumbnailsAction = strtolower($item->thumbnails->action); } else { //default action to perfom for assets and thumbnails is replace $contentAssetsAction = self::$actionsMap[KalturaBulkUploadAction::REPLACE]; $thumbnailsAction = self::$actionsMap[KalturaBulkUploadAction::REPLACE]; } if (isset($item->contentAssets->action) && isset($item->thumbnails->action) && $contentAssetsAction != $thumbnailsAction) { throw new KalturaBatchException("ContentAsset->action: {$contentAssetsAction} must be the same as thumbnails->action: {$thumbnailsAction}", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED); } //For each content in the item element we add a new flavor asset if (isset($item->contentAssets)) { foreach ($item->contentAssets->content as $contentElement) { KalturaLog::debug("contentElement [" . print_r($contentElement->asXml(), true) . "]"); if (empty($contentElement)) { continue; } $flavorAsset = $this->getFlavorAsset($contentElement, $conversionProfileId); $flavorAssetResource = $this->getResource($contentElement, $conversionProfileId); if (!$flavorAssetResource) { continue; } $assetParamsId = $flavorAsset->flavorParamsId; $assetId = kXml::getXmlAttributeAsString($contentElement, "assetId"); if ($assetId) { KalturaLog::debug("Asset id [ {$assetId}]"); $assetParamsId = $this->getAssetParamsIdFromAssetId($assetId, $entryId); } KalturaLog::debug("assetParamsId [{$assetParamsId}]"); if (is_null($assetParamsId)) { $noParamsFlavorAssets[] = $flavorAsset; $noParamsFlavorResources[] = $flavorAssetResource; continue; } else { $flavorAssetsResources[$flavorAsset->flavorParamsId] = $flavorAssetResource; } $flavorAssets[$flavorAsset->flavorParamsId] = $flavorAsset; $assetResource = new KalturaAssetParamsResourceContainer(); $assetResource->resource = $flavorAssetResource; $assetResource->assetParamsId = $assetParamsId; $resource->resources[] = $assetResource; } } //For each thumbnail in the item element we create a new thumb asset if (isset($item->thumbnails)) { foreach ($item->thumbnails->thumbnail as $thumbElement) { if (empty($thumbElement)) { continue; } KalturaLog::debug("thumbElement [" . print_r($thumbElement->asXml(), true) . "]"); $thumbAsset = $this->getThumbAsset($thumbElement, $conversionProfileId); $thumbAssetResource = $this->getResource($thumbElement, $conversionProfileId); if (!$thumbAssetResource) { continue; } $assetParamsId = $thumbAsset->thumbParamsId; $assetId = kXml::getXmlAttributeAsString($thumbElement, "assetId"); if ($assetId) { KalturaLog::debug("Asset id [ {$assetId}]"); $assetParamsId = $this->getAssetParamsIdFromAssetId($assetId, $entryId); } KalturaLog::debug("assetParamsId [{$assetParamsId}]"); if (is_null($assetParamsId)) { $noParamsThumbAssets[] = $thumbAsset; $noParamsThumbResources[] = $thumbAssetResource; continue; } else { $thumbAssetsResources[$thumbAsset->thumbParamsId] = $thumbAssetResource; } $thumbAssets[$thumbAsset->thumbParamsId] = $thumbAsset; $assetResource = new KalturaAssetParamsResourceContainer(); $assetResource->resource = $thumbAssetResource; $assetResource->assetParamsId = $assetParamsId; $resource->resources[] = $assetResource; } } if (!count($resource->resources)) { if (count($noParamsFlavorResources) == 1) { $resource = reset($noParamsFlavorResources); $noParamsFlavorResources = array(); $noParamsFlavorAssets = array(); } else { $resource = null; } } switch ($contentAssetsAction) { case self::$actionsMap[KalturaBulkUploadAction::UPDATE]: $entry = $this->sendItemUpdateData($entryId, $entry, $flavorAssets, $flavorAssetsResources, $thumbAssets, $thumbAssetsResources); break; case self::$actionsMap[KalturaBulkUploadAction::REPLACE]: $entry = $this->sendItemReplaceData($entryId, $entry, $resource, $noParamsFlavorAssets, $noParamsFlavorResources, $noParamsThumbAssets, $noParamsThumbResources); $entryId = $entry->id; break; default: throw new KalturaBatchException("Action: {$contentAssetsAction} is not supported", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED); } //Creates new category associations between the entry and the categories $updatedEntryBulkUploadResult = $this->createCategoryAssociations($entryId, $this->implodeChildElements($item->categories), $updatedEntryBulkUploadResult, true); //Adds the additional data for the flavors and thumbs $this->handleFlavorAndThumbsAdditionalData($entryId, $flavorAssets, $thumbAssets); //Handles the plugin added data $pluginsErrorResults = array(); $pluginsInstances = KalturaPluginManager::getPluginInstances('IKalturaBulkUploadXmlHandler'); foreach ($pluginsInstances as $pluginsInstance) { /* @var $pluginsInstance IKalturaBulkUploadXmlHandler */ try { $pluginsInstance->configureBulkUploadXmlHandler($this); $pluginsInstance->handleItemUpdated($entry, $item); } catch (Exception $e) { KalturaLog::err($pluginsInstance->getContainerName() . ' failed: ' . $e->getMessage()); $pluginsErrorResults[] = $pluginsInstance->getContainerName() . ' failed: ' . $e->getMessage(); } } if (count($pluginsErrorResults)) { throw new Exception(implode(', ', $pluginsErrorResults)); } //Updates the bulk upload result for the given entry (with the status and other data) $this->updateObjectsResults(array($entry), array($updatedEntryBulkUploadResult)); }
/** * @param assetParams $assetParam */ protected function assetParamDeleted(assetParams $assetParam) { //In Case Flavor Deleted Belongs To Partner 0 Exit Without Deleteing if ($assetParam->getPartnerId() == 0) { KalturaLog::DEBUG("Deleting Flavor Param Of Partner 0 Is Restricted"); return; } $c = new Criteria(); $c->setLimit(100); $c->add(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $assetParam->getId()); for (;;) { $flavorParamsConversionProfiles = flavorParamsConversionProfilePeer::doSelect($c); foreach ($flavorParamsConversionProfiles as $flavorParamsConversionProfile) { /* @var $flavorParamsConversionProfile flavorParamsConversionProfile */ $flavorParamsConversionProfile->delete(); } if (count($flavorParamsConversionProfiles) < 100) { break; } flavorParamsConversionProfilePeer::clearInstancePool(); } KalturaLog::DEBUG("Flavor Params Conversion Profile Relations were deleted for flavor param id [" . $assetParam->getId() . "]"); }
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); $entry = null; if ($ks_str) { try { kCurrentContext::initKsPartnerUser($ks_str); } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS); } } else { $entry = kCurrentContext::initPartnerByEntryId($entry_id); if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } kEntitlementUtils::initEntitlementEnforcement(); // 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 if (!$entry) { $entry = entryPeer::retrieveByPKNoFilter($entry_id); } else { if (!kEntitlementUtils::isEntryEntitled($entry)) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } } if (!$entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } KalturaMonitorClient::initApiMonitor(false, 'keditorservices.flvclipper', $entry->getPartnerId()); myPartnerUtils::blockInactivePartner($entry->getPartnerId()); if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_BLOCK_FLVCLIPPER_ACTION, $entry->getPartnerId())) { KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED); } // 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. KExternalErrors::dieGracefully(); } 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); kFileUtils::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 = assetPeer::retrieveBestEditByEntryId($entry->getId()); } elseif (!is_null($flavor)) { $flavorAsset = assetPeer::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 = assetPeer::retrieveByEntryIdAndParams($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 = assetPeer::retrieveOriginalByEntryId($entry->getId()); } else { $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId()); } if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryIdAndTag($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); } if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset); if (!$urlManager) { KalturaLog::log("Error - failed to find an HTTP delivery for storage profile [" . $fileSync->getDc() . "]"); KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND); } $url = rtrim($urlManager->getUrl(), '/') . '/' . ltrim($urlManager->getFileSyncUrl($fileSync), '/'); header('location: ' . $url); die; } $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}"); KExternalErrors::dieGracefully(); } 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}"); KExternalErrors::dieGracefully(); } // 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, ContextType::PLAY); 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"); KExternalErrors::dieGracefully(); } $ks = kSessionUtils::crackKs($ks_str); if (!$ks) { $this->logMessage("flvclipper - invalid ks [{$ks_str}]"); KExternalErrors::dieGracefully(); } $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}]"); KExternalErrors::dieGracefully(); } } 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}"); KExternalErrors::dieGracefully(); } 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}"); KExternalErrors::dieGracefully(); } } } // 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); KExternalErrors::dieGracefully(); } // mp4 if (!$isFlv) { $limit_file_size = 0; if ($clip_to != 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(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2); } } KalturaLog::DEBUG("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]"); kFileUtils::dumpFile($path, null, null, $limit_file_size); } $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}"); } KExternalErrors::terminateDispatch(); return sfView::SUCCESS; }
public static function deleteEntry(entry $entry, $partner_id = null, $onlyIfAllJobsDone = false) { if ($entry->getStatus() == entryStatus::DELETED || $entry->getStatus() == entryStatus::BLOCKED) { return; } // don't do this twice ! if ($onlyIfAllJobsDone) { KalturaLog::DEBUG("onlyIfAllJobsDone = " . (int) $onlyIfAllJobsDone); $dbEntryBatchJobLocks = BatchJobLockPeer::retrieveByEntryId($entry->getId()); foreach ($dbEntryBatchJobLocks as $jobLock) { /* @var $jobLock BatchJobLock */ $job = $jobLock->getBatchJob(); /* @var $job BatchJob */ KalturaLog::DEBUG("Entry [" . $entry->getId() . "] still has an unhandled batchjob [" . $job->getId() . "] with status [" . $job->getStatus() . "] - aborting deletion process."); //mark entry for later deletion $entry->setMarkedForDeletion(true); $entry->save(); return; } } KalturaLog::log("myEntryUtils::delete Entry [" . $entry->getId() . "] Partner [" . $entry->getPartnerId() . "]"); kJobsManager::abortEntryJobs($entry->getId()); $media_type = $entry->getMediaType(); $need_to_fix_roughcut = false; $thumb_template_file = "&deleted_image.jpg"; KalturaLog::log("media type [{$media_type}]"); switch ($media_type) { case entry::ENTRY_MEDIA_TYPE_AUDIO: $template_file = "&deleted_audio.flv"; $need_to_fix_roughcut = true; break; case entry::ENTRY_MEDIA_TYPE_IMAGE: $template_file = "&deleted_image.jpg"; $need_to_fix_roughcut = false; // no need to add a batch job for images break; case entry::ENTRY_MEDIA_TYPE_VIDEO: $template_file = "&deleted_video.flv"; $need_to_fix_roughcut = true; break; case entry::ENTRY_MEDIA_TYPE_SHOW: default: $template_file = "&deleted_rc.xml"; $need_to_fix_roughcut = false; break; } if ($entry->getType() == entryType::LIVE_STREAM) { kJobsManager::addProvisionDeleteJob(null, $entry); } // in this case we'll need some batch job to fix all related roughcuts for this entry // use the batch_job mechanism to indicate there is a deleted entry to handle if ($need_to_fix_roughcut) { // Should use a different job type // BatchJob::createDeleteEntryJob ( $entry ); } $entry->putInCustomData("deleted_original_data", $entry->getData()); $entry->putInCustomData("deleted_original_thumb", $entry->getThumbnail()); $content_path = myContentStorage::getFSContentRootPath(); // Remarked by Tan-Tan 27/09/2010 // Handled by kObjectDeleteHandler // $currentDataKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath // $currentDataEditKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA_EDIT); // replaced__getDataPathEdit // $currentThumbKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $entry->setData($entry->getData()); // once to increment the verions $entry->setData($template_file); // the other to set the template $entry->setThumbnail($entry->getThumbnail()); // once to increment the verions $entry->setThumbnail($thumb_template_file); // the other to set the template // Remarked by Tan-Tan 27/09/2010 // Handled by kObjectDeleteHandler // // move file so there will be no access to it // $deleted_content = kFileSyncUtils::deleteSyncFileForKey($currentDataKey); // $deleted_content .= "|" . kFileSyncUtils::deleteSyncFileForKey($currentDataEditKey,false); // for some entries there may not be an edit version // $deleted_content .= "|" . kFileSyncUtils::deleteSyncFileForKey($currentThumbKey,false); // for some entries (empty mix / audio) there may not be a thumb FileSync // Remarked by Tan-Tan 27/09/2010 // $deleted_content is always null anyway // $entry->putInCustomData( "deleted_file_path" , $deleted_content ? $deleted_content : serialize($currentDataKey) ) ; $entry->setStatus(entryStatus::DELETED); //$entry->setCategories(""); // make sure the moderation_status is set to moderation::MODERATION_STATUS_DELETE $entry->setModerationStatus(moderation::MODERATION_STATUS_DELETE); $entry->setModifiedAt(time()); $entry->save(); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_DELETE, $entry, null, null, null, null, $entry->getId()); }