/** * @param entry $entry * @return bool true if cuepoints should be copied to given entry */ public function hasPermissionToCopyToEntry(entry $entry) { if (!$entry->getIsTemporary() && PermissionPeer::isValidForPartner(AnnotationCuePointPermissionName::COPY_ANNOTATIONS_TO_CLIP, $entry->getPartnerId())) { return true; } if ($entry->getIsTemporary() && !PermissionPeer::isValidForPartner(AnnotationCuePointPermissionName::DO_NOT_COPY_ANNOTATIONS_TO_TRIMMED_ENTRY, $entry->getPartnerId())) { return true; } return false; }
public function copyAssets(entry $toEntry, ThumbCuePoint $toCuePoint, $adjustedStartTime = null) { $timedThumbAsset = assetPeer::retrieveById($this->getAssetId()); if (!$timedThumbAsset) { KalturaLog::debug("Can't retrieve timedThumbAsset with id: {$this->getAssetId()}"); return; } // Offset the startTime according to the duration gap between the live and VOD entries if (!is_null($adjustedStartTime)) { $toCuePoint->setStartTime($adjustedStartTime); } $toCuePoint->save(); // Must save in order to produce an id $timedThumbAsset->setCuePointID($toCuePoint->getId()); // Set the destination cue point's id $timedThumbAsset->setCustomDataObj(); // Write the cached custom data object into the thumb asset // Make a copy of the current thumb asset // copyToEntry will create a filesync softlink to the original filesync $toTimedThumbAsset = $timedThumbAsset->copyToEntry($toEntry->getId(), $toEntry->getPartnerId()); $toCuePoint->setAssetId($toTimedThumbAsset->getId()); $toCuePoint->save(); // Restore the thumb asset's prev. cue point id (for good measures) $timedThumbAsset->setCuePointID($this->getId()); $timedThumbAsset->setCustomDataObj(); // Save the destination entry's thumb asset $toTimedThumbAsset->setCuePointID($toCuePoint->getId()); $toTimedThumbAsset->save(); KalturaLog::log("Saved cue point [{$toCuePoint->getId()}] and timed thumb asset [{$toTimedThumbAsset->getId()}]"); }
protected function validateKs() { if ($this->_ksStr) { try { // todo need to check if partner is within a partner group $ks = kSessionUtils::crackKs($this->_ksStr); // if entry is "display_in_search=2" validate partner ID from the KS // => meaning it will alwasy pass on partner_id if ($this->_entry->getDisplayInSearch() != mySearchUtils::DISPLAY_IN_SEARCH_KALTURA_NETWORK) { $valid = $ks->isValidForPartner($this->_entry->getPartnerId()); } else { $valid = $ks->isValidForPartner($ks->partner_id); } if ($valid === ks::EXPIRED) { die("This URL is expired"); } else { if ($valid === ks::INVALID_PARTNER) { if ($this->hasRestrictions()) { // todo - for now if the entry doesnt have restrictions any way disregard a partner group check die("Invalid session [" . $valid . "]"); } } else { if ($valid !== ks::OK) { die("Invalid session [" . $valid . "]"); } } } $this->_ks = $ks; } catch (Exception $ex) { KExternalErrors::dieError(KExternalErrors::INVALID_KS_SRT); } } }
protected function handleEntry($context, $feed, entry $entry, Entrydistribution $entryDistribution) { $fields = $this->profile->getAllFieldValues($entryDistribution); $flavorAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getFlavorAssetIds())); $thumbAssets = assetPeer::retrieveByIds(explode(',', $entryDistribution->getThumbAssetIds())); $captionAssets = null; if ($this->profile instanceof ComcastMrssDistributionProfile && $this->profile->getShouldIncludeCaptions()) { KalturaLog::info("Adding entry captions."); $captionAssets = $this->getCaptions($entry->getPartnerId(), $entry->getId()); } $cuePoints = null; if ($this->profile instanceof ComcastMrssDistributionProfile && $this->profile->getShouldIncludeCuePoints()) { KalturaLog::info("Adding entry cue points."); $cuePoints = $this->getCuePoints($entry->getPartnerId(), $entry->getId()); } return $feed->getItemXml($fields, $flavorAssets, $thumbAssets, $captionAssets, $cuePoints); }
public static function updateAdminTags(entry $entry) { // be ready to update the admin_tags if the admin_tags OR the status was modified if ($entry->isColumnModified(entryPeer::ADMIN_TAGS) || $entry->isColumnModified(entryPeer::STATUS)) { $partner_id = $entry->getPartnerId(); $admin_tags_str = self::getAdminTags($partner_id, null, true, $entry->getId()); $admin_tags = explode(self::TAG_SEPARATOR, $admin_tags_str); $admin_tags = self::mergeAdminTags($admin_tags, $entry->getAdminTags()); $after_change = self::sortAndSetAdminTags($partner_id, $admin_tags); } }
private static function purgeEntryFromEdgeCast(entry $entry) { // get partner $partnerId = $entry->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err('Cannot find partner with id [' . $partnerId . ']'); return false; } $mediaTypePathList = array(array('MediaType' => self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE, 'MediaPath' => $entry->getDownloadUrl()), array('MediaType' => self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE, 'MediaPath' => $entry->getThumbnailUrl())); return self::purgeFromEdgeCast($mediaTypePathList, $partner); }
/** * 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"); if ($objectIdStr) { list($objectId, $type) = @explode(".", $objectIdStr); } if (!$type || !$objectId) { KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER); } $ks = $this->getRequestParameter("ks"); $referrer = base64_decode($this->getRequestParameter("referrer")); if (!is_string($referrer)) { // base64_decode can return binary data $referrer = ''; } $syncKey = $this->getFileSyncKey($objectId, $type); KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveIsm', $this->entry->getPartnerId()); myPartnerUtils::enforceDelivery($this->entry, $this->flavorAsset); 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); kFileUtils::dumpUrl($remoteUrl); } $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if ($type == 'ism') { $fileData = $this->fixIsmManifestForReplacedEntry($path); $renderer = new kRendererString($fileData, 'image/ism'); $renderer->output(); KExternalErrors::dieGracefully(); } else { kFileUtils::dumpFile($path); } }
public function execute() { $this->entryId = $this->getRequestParameter("entryId", null); $this->flavorId = $this->getRequestParameter("flavorId", null); $this->storageId = $this->getRequestParameter("storageId", null); $this->maxBitrate = $this->getRequestParameter("maxBitrate", null); $flavorIdsStr = $this->getRequestParameter("flavorIds", null); if ($flavorIdsStr) { $this->flavorIds = explode(",", $flavorIdsStr); } $this->entry = entryPeer::retrieveByPKNoFilter($this->entryId); if (!$this->entry) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND); } if (!$this->flavorId) { $flavorParamId = $this->getRequestParameter("flavorParamId", null); if ($flavorParamId) { $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entry->getId(), $flavorParamId); if (!$flavorAsset) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $this->flavorId = $flavorAsset->getId(); } } $this->validateStorageId(); $this->protocol = $this->getRequestParameter("protocol", null); if (!$this->protocol) { $this->protocol = StorageProfile::PLAY_FORMAT_HTTP; } $this->format = $this->getRequestParameter("format"); if (!$this->format) { $this->format = StorageProfile::PLAY_FORMAT_HTTP; } $this->cdnHost = $this->getRequestParameter("cdnHost", null); $partner = $this->entry->getPartner(); if (!$this->cdnHost || $partner->getForceCdnHost()) { $this->cdnHost = myPartnerUtils::getCdnHost($this->entry->getPartnerId(), $this->protocol); } if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) { KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE); } $ksStr = $this->getRequestParameter("ks"); $base64Referrer = $this->getRequestParameter("referrer"); $referrer = base64_decode($base64Referrer); if (!is_string($referrer)) { $referrer = ""; } // base64_decode can return binary data $securyEntryHelper = new KSecureEntryHelper($this->entry, $ksStr, $referrer); if ($securyEntryHelper->shouldPreview()) { $this->clipTo = $securyEntryHelper->getPreviewLength() * 1000; } else { $securyEntryHelper->validateForPlay($this->entry, $ksStr); } // grab seekFrom parameter and normalize url $this->seekFrom = $this->getRequestParameter("seekFrom", -1); if ($this->seekFrom <= 0) { $this->seekFrom = -1; } if ($this->entry->getStatus() == entryStatus::DELETED) { // because the fiter was turned off - a manual check for deleted entries must be done. die; } $xml = null; switch ($this->format) { case StorageProfile::PLAY_FORMAT_HTTP: $xml = $this->serveHttp(); break; case StorageProfile::PLAY_FORMAT_RTMP: $xml = $this->serveRtmp(); break; case StorageProfile::PLAY_FORMAT_SILVER_LIGHT: $xml = $this->serveSilverLight(); break; case StorageProfile::PLAY_FORMAT_APPLE_HTTP: $xml = $this->serveAppleHttp(); break; case "url": return $this->serveUrl(); break; case "hdnetworksmil": $xml = $this->serveHDNetwork(); break; case "hdnetwork": $duration = $this->entry->getDurationInt(); $mediaUrl = "<media url=\"" . requestUtils::getHost() . str_replace("f4m", "smil", str_replace("hdnetwork", "hdnetworksmil", $_SERVER["REQUEST_URI"])) . "\"/>"; $xml = $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, array(), 'video/x-flv', $duration, null, $mediaUrl); break; } if ($this->format == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { header("Content-Type: text/plain; charset=UTF-8"); } else { header("Content-Type: text/xml; charset=UTF-8"); header("Content-Disposition: inline; filename=manifest.xml"); } echo $xml; die; }
/** * @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) { KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]"); if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) { $entry->setStatus(entryStatus::PENDING); $entry->save(); KalturaLog::notice('Entry should not be converted'); return null; } $importingSources = false; // if file size is 0, do not create conversion profile and set entry status as error converting if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) { KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist"); $partner = $entry->getPartner(); $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId()); // load the asset params to the instance pool $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId()); assetParamsPeer::retrieveByPKs($flavorIds); $conversionRequired = false; $sourceFileRequiredStorages = array(); $sourceIncludedInProfile = false; $flavorAsset = assetPeer::retrieveById($flavorAssetId); $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId()); KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]"); foreach ($flavors as $flavor) { /* @var $flavor flavorParamsConversionProfile */ if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source"); $sourceIncludedInProfile = true; continue; } $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId()); if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested"); continue; } if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) { $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId()); if ($siblingFlavorAsset) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested"); continue; } } $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId(); $conversionRequired = true; break; } if ($conversionRequired) { foreach ($sourceFileRequiredStorages as $storageId) { if ($storageId == StorageProfile::STORAGE_KALTURA_DC) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false); if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) { KalturaLog::debug("Creates import job for remote file sync"); $url = $syncFile->getExternalUrl($entry->getId()); kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true); $importingSources = true; continue; } } elseif ($flavorAsset->getExternalUrl($storageId)) { continue; } kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING); $flavorAsset = assetPeer::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; } } else { if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) { if ($sourceIncludedInProfile) { $flavorAsset->setStatusLocalReady(); } else { $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED); $flavorAsset->setDeletedAt(time()); } $flavorAsset->save(); if ($sourceIncludedInProfile) { kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset); } } return null; } } if ($entry->getStatus() != entryStatus::READY) { $entry->setStatus(entryStatus::PRECONVERT); } $jobData = new kConvertProfileJobData(); $jobData->setFlavorAssetId($flavorAssetId); $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath); $jobData->setExtractMedia(true); if ($entry->getType() != entryType::MEDIA_CLIP) { $jobData->setExtractMedia(false); $entry->setCreateThumb(false); } $entry->save(); $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($entry->getId()); $batchJob->setPartnerId($entry->getPartnerId()); $batchJob->setUseNewRoot(true); } $batchJob->setObjectId($entry->getId()); $batchJob->setObjectType(BatchJobObjectType::ENTRY); if ($importingSources) { $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS); } return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE); }
public static function deleteEntry(entry $entry, $partner_id = null) { if ($entry->getStatus() == entryStatus::DELETED || $entry->getStatus() == entryStatus::BLOCKED) { return; } // don't do this twice ! 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_LIVE_STREAM_FLASH: case entry::ENTRY_MEDIA_TYPE_LIVE_STREAM_WINDOWS_MEDIA: case entry::ENTRY_MEDIA_TYPE_LIVE_STREAM_REAL_MEDIA: case entry::ENTRY_MEDIA_TYPE_LIVE_STREAM_QUICKTIME: kJobsManager::addProvisionDeleteJob(null, $entry); break; case entry::ENTRY_MEDIA_TYPE_SHOW: default: $template_file = "&deleted_rc.xml"; $need_to_fix_roughcut = false; break; } // 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()); }
public static function checkForPendingLiveClips(entry $entry) { if ($entry->getSource() != EntrySourceType::RECORDED_LIVE) { KalturaLog::notice("Entry [" . $entry->getId() . "] is not a recorded live"); return; } $liveEntry = entryPeer::retrieveByPKNoFilter($entry->getRootEntryId()); if (!$liveEntry || $liveEntry->getStatus() == entryStatus::DELETED || !$liveEntry instanceof LiveEntry) { KalturaLog::notice("Entry root [" . $entry->getRootEntryId() . "] is not a valid live entry"); return; } /* @var $liveEntry LiveEntry */ $pendingMediaEntries = $liveEntry->getAttachedPendingMediaEntries(); foreach ($pendingMediaEntries as $pendingMediaEntry) { /* @var $pendingMediaEntry kPendingMediaEntry */ if ($pendingMediaEntry->getRequiredDuration() && $pendingMediaEntry->getRequiredDuration() > $entry->getLengthInMsecs()) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] required duration [" . $pendingMediaEntry->getRequiredDuration() . "] while entry duration [" . $entry->getLengthInMsecs() . "] is too short"); continue; } $liveEntry->dettachPendingMediaEntry($pendingMediaEntry->getEntryId()); $pendingEntry = entryPeer::retrieveByPK($pendingMediaEntry->getEntryId()); if (!$pendingEntry) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] not found"); continue; } $sourceAsset = assetPeer::retrieveOriginalByEntryId($entry->getId()); if (!$sourceAsset) { $sourceAssets = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId()); $sourceAsset = array_pop($sourceAssets); } if (!$sourceAsset) { KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] source asset not found"); continue; } /* @var $sourceAsset flavorAsset */ $operationAttributes = new kClipAttributes(); $operationAttributes->setOffset($pendingMediaEntry->getOffset()); $operationAttributes->setDuration($pendingMediaEntry->getDuration()); $targetAsset = assetPeer::retrieveOriginalByEntryId($pendingMediaEntry->getEntryId()); if (!$targetAsset) { $targetAsset = kFlowHelper::createOriginalFlavorAsset($entry->getPartnerId(), $pendingMediaEntry->getEntryId()); } $targetAsset->setFileExt($sourceAsset->getFileExt()); $targetAsset->save(); $sourceSyncKey = $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $targetSyncKey = $targetAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($targetSyncKey, $sourceSyncKey); $errDescription = ''; kBusinessPreConvertDL::decideAddEntryFlavor(null, $pendingMediaEntry->getEntryId(), $operationAttributes->getAssetParamsId(), $errDescription, $targetAsset->getId(), array($operationAttributes)); } $liveEntry->save(); }
/** * @param entry $entry */ public static function onEntryReady(entry $entry) { if (!ContentDistributionPlugin::isAllowedPartner($entry->getPartnerId())) { return true; } //no temp entries should be handled if ($entry->getDisplayInSearch() == mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM && $entry->getReplacedEntryId()) { return true; } $distributionProfiles = DistributionProfilePeer::retrieveByPartnerId($entry->getPartnerId()); foreach ($distributionProfiles as $distributionProfile) { $entryDistribution = EntryDistributionPeer::retrieveByEntryAndProfileId($entry->getId(), $distributionProfile->getId()); if ($entryDistribution) { KalturaLog::info("Found entry distribution object with id [" . $entryDistribution->getId() . "] for distrinution profle [" . $distributionProfile->getId() . "]"); self::onEntryDistributionUpdateRequired($entryDistribution); continue; } if ($distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::AUTOMATIC) { self::addEntryDistribution($entry, $distributionProfile, true); } } return true; }
/** * Ensure the request for media arrived in a way approved by the partner. * this may include restricting to a specific cdn, enforcing token usage etc.. * Die in case of a breach. * * @param entry $entry * @param asset $asset */ public static function enforceDelivery($entry, $asset = null) { // block inactive partner $partnerId = $entry->getPartnerId(); self::blockInactivePartner($partnerId); // validate serve access control $flavorParamsId = $asset ? $asset->getFlavorParamsId() : null; $secureEntryHelper = new KSecureEntryHelper($entry, null, null, ContextType::SERVE); $secureEntryHelper->validateForServe($flavorParamsId); // enforce delivery $partner = PartnerPeer::retrieveByPK($partnerId); // Note: Partner was already loaded by blockInactivePartner, no need to check for null $restricted = DeliveryProfilePeer::isRequestRestricted($partner); if ($restricted) { KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]"); KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED); } }
/** * decideThumbGenerate is the decision layer for a single thumbnail generation * * @param entry $entry * @param thumbParams $destThumbParams * @param BatchJob $parentJob * @return thumbAsset */ public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false, $srcAsset = null) { if (is_null($srcAsset)) { $srcAsset = self::getSourceAssetForGenerateThumbnail($sourceAssetId, $destThumbParams->getSourceParamsId(), $entry->getId()); if (is_null($srcAsset)) { throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY); } } $errDescription = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription); if ($srcAsset->getType() == assetType::FLAVOR && is_null($destThumbParamsOutput->getVideoOffset())) { $destThumbParamsOutput->setVideoOffset($entry->getThumbOffset()); } $destThumbParamsOutput->setVideoOffset(min($destThumbParamsOutput->getVideoOffset(), $entry->getDuration())); if (!$destThumbParamsOutput->getDensity()) { $partner = $entry->getPartner(); if (!is_null($partner)) { $destThumbParamsOutput->setDensity($partner->getDefThumbDensity()); } } $thumbAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId()); if ($thumbAsset) { $description = $thumbAsset->getDescription() . "\n" . $errDescription; $thumbAsset->setDescription($description); } else { $thumbAsset = new thumbAsset(); $thumbAsset->setPartnerId($entry->getPartnerId()); $thumbAsset->setEntryId($entry->getId()); $thumbAsset->setDescription($errDescription); $thumbAsset->setFlavorParamsId($destThumbParams->getId()); } $thumbAsset->incrementVersion(); $thumbAsset->setTags($destThumbParamsOutput->getTags()); $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt()); if ($thumbAsset->getStatus() != asset::ASSET_STATUS_READY) { $thumbAsset->setStatus(asset::ASSET_STATUS_CONVERTING); } //Sets the default thumb if this the only default thumb kBusinessPreConvertDL::setIsDefaultThumb($thumbAsset); if (!$destThumbParamsOutput) { $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); return null; } $thumbAsset->save(); // save flavor params $destThumbParamsOutput->setPartnerId($entry->getPartnerId()); $destThumbParamsOutput->setEntryId($entry->getId()); $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId()); $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion()); $destThumbParamsOutput->save(); $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcAssetType = $srcAsset->getType(); if (!$runSync) { $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAsset->getId(), $srcAssetType, $destThumbParamsOutput); return $thumbAsset; } $errDescription = null; // Since this method is called when trying to crop an existing thumbnail, need to add this check - thumbAssets have no mediaInfo. $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription, $mediaInfo ? $mediaInfo->getVideoRotation() : null); // failed if (!$capturedPath) { $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}"); $thumbAsset->save(); return $thumbAsset; } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); if (file_exists($capturedPath)) { list($width, $height, $type, $attr) = getimagesize($capturedPath); $thumbAsset->setWidth($width); $thumbAsset->setHeight($height); $thumbAsset->setSize(filesize($capturedPath)); } $logPath = $capturedPath . '.log'; if (file_exists($logPath)) { $thumbAsset->incLogFileVersion(); $thumbAsset->save(); // creats the file sync $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); kFileSyncUtils::moveFromFile($logPath, $logSyncKey); KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey)); } else { $thumbAsset->save(); } $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($capturedPath, $syncKey); KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { // increment thumbnail version $entry->setThumbnail(".jpg"); $entry->setCreateThumb(false); $entry->save(); $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey); if ($syncFile) { // removes the DEFAULT_THUMB tag from all other thumb assets $entryThumbAssets = assetPeer::retrieveThumbnailsByEntryId($thumbAsset->getEntryId()); foreach ($entryThumbAssets as $entryThumbAsset) { if ($entryThumbAsset->getId() == $thumbAsset->getId()) { continue; } if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { continue; } $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB)); $entryThumbAsset->save(); } } } if (!is_null($thumbAsset->getFlavorParamsId())) { kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId()); } return $thumbAsset; }
/** * @param entry $entry */ protected function entryDeleted(entry $entry) { $this->syncableDeleted($entry->getId(), FileSyncObjectType::ENTRY); // delete flavor assets $c = new Criteria(); $c->add(assetPeer::ENTRY_ID, $entry->getId()); $c->add(assetPeer::STATUS, asset::FLAVOR_ASSET_STATUS_DELETED, Criteria::NOT_EQUAL); $c->add(assetPeer::DELETED_AT, null, Criteria::ISNULL); $assets = assetPeer::doSelect($c); foreach ($assets as $asset) { $asset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED); $asset->setDeletedAt(time()); $asset->save(); } $c = new Criteria(); $c->add(assetParamsOutputPeer::ENTRY_ID, $entry->getId()); $c->add(assetParamsOutputPeer::DELETED_AT, null, Criteria::ISNULL); $flavorParamsOutputs = assetParamsOutputPeer::doSelect($c); foreach ($flavorParamsOutputs as $flavorParamsOutput) { $flavorParamsOutput->setDeletedAt(time()); $flavorParamsOutput->save(); } $filter = new categoryEntryFilter(); $filter->setEntryIdEqual($entry->getId()); $c = new Criteria(); $c->add(categoryEntryPeer::ENTRY_ID, $entry->getId()); if (!categoryEntryPeer::doSelectOne($c)) { return; } kJobsManager::addDeleteJob($entry->getPartnerId(), DeleteObjectType::CATEGORY_ENTRY, $filter); }
public static function copyEntryData(entry $entry, entry $targetEntry) { // for any type that does not require assets: $shouldCopyDataForNonClip = true; if ($entry->getType() == entryType::MEDIA_CLIP) { $shouldCopyDataForNonClip = false; } if ($entry->getType() == entryType::PLAYLIST) { $shouldCopyDataForNonClip = false; } $shouldCopyDataForClip = false; // only images get their data copied if ($entry->getType() == entryType::MEDIA_CLIP) { if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) { $shouldCopyDataForClip = true; } } if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) { // copy the data $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); if (kFileSyncUtils::fileSync_exists($ismFrom)) { $ismTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]"); kFileSyncUtils::softCopy($ismFrom, $ismTo); } $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); if (kFileSyncUtils::fileSync_exists($ismcFrom)) { $ismcTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]"); kFileSyncUtils::softCopy($ismcFrom, $ismcTo); } $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $considerCopyThumb = true; // if entry is image - data is thumbnail, and it was copied if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $considerCopyThumb = false; } // if entry is not clip, and there is no file in both DCs - nothing to copy if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) { $considerCopyThumb = false; } if ($considerCopyThumb) { $skipThumb = false; // don't attempt to copy a thumbnail for images - it's the same as the data which was just created if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { // check if audio entry has real thumb, if not - don't copy thumb. $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false); if (!$originalFileSync) { $skipThumb = true; } } if (!$skipThumb) { $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } } // added by Tan-Tan 12/01/2010 to support falvors copy $sourceAssets = assetPeer::retrieveByEntryId($entry->getId()); foreach ($sourceAssets as $sourceAsset) { $sourceAsset->copyToEntry($targetEntry->getId(), $targetEntry->getPartnerId()); } }
/** * Sets the valid user for the entry * Throws an error if the session user is trying to add entry to another user and not using an admin session * * @param KalturaBaseEntry $entry * @param entry $dbEntry */ protected function checkAndSetValidUser(KalturaBaseEntry $entry, entry $dbEntry) { KalturaLog::debug("DB puser id [" . $dbEntry->getPuserId() . "] kuser id [" . $dbEntry->getKuserId() . "]"); // for new entry, puser ID is null - set it from service scope if ($dbEntry->getPuserId() === null) { KalturaLog::debug("Set kuser id [" . $this->getKuser()->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($this->getKuser()->getId()); return; } // get puser ID from entry to compare to userId on the updated entry object $entryPuserId = $dbEntry->getPuserId(); $kuser = null; if ($dbEntry->getKuserId()) { // get kuser object from entry kuserId $kuser = kuserPeer::retrieveByPK($dbEntry->getKuserId()); if (!$kuser || $kuser->getPuserId() != $dbEntry->getPuserId()) { $kuser = null; } } else { // get kuser object from entry puserId $kuser = kuserPeer::getKuserByPartnerAndUid($dbEntry->getPartnerId(), $dbEntry->getPuserId()); } if ($kuser) { KalturaLog::debug("Set kuser id [" . $kuser->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($kuser->getId()); return; } // userID doesn't require change (it is null or the same as the db entry) - do nothing if ($entry->userId === null || $entry->userId === $entryPuserId) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - no need to change - quitting'); return; } // db user is going to be changed, only admin allowed - otherwise, throw exception if (!$this->getKs() || !$this->getKs()->isAdmin()) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - change required but KS is not admin'); throw new KalturaAPIException(KalturaErrors::INVALID_KS, "", ks::INVALID_TYPE, ks::getErrorStr(ks::INVALID_TYPE)); } // passed previous conditions, need to change userID on entry // first step is to make sure the user exists $puserKuser = PuserKuserPeer::createPuserKuser($this->getPartnerId(), $this->getPartnerId() * 100, $dbEntry->getPuserId(), $dbEntry->getPuserId(), $dbEntry->getPuserId(), true); // second step is simply changing the userID on the entry $dbEntry->setKuserId($puserKuser->getKuserId()); KalturaLog::debug("Set kuser id [" . $puserKuser->getKuserId() . "] line [" . __LINE__ . "]"); }
private function setContextDataStreamerTypeAndMediaProtocol(accessControlScope $scope, $flavorTags) { if ($this->streamerType && $this->streamerType != PlaybackProtocol::AUTO) { $this->mediaProtocol = $this->mediaProtocol ? $this->mediaProtocol : $this->streamerType; } elseif ($this->entry instanceof LiveEntry) { $protocols = array(); if (!in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) { $protocols[] = PlaybackProtocol::AKAMAI_HDS; } $protocols[] = PlaybackProtocol::HDS; if ($this->entry->getStreamName()) { $this->streamerType = PlaybackProtocol::RTMP; } foreach ($protocols as $protocol) { $config = $this->entry->getLiveStreamConfigurationByProtocol($protocol, requestUtils::getProtocol()); if ($config) { $this->streamerType = $protocol; break; } } if (in_array($this->entry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) { $this->streamerType = PlaybackProtocol::HDS; } if ($this->entry->getSource() == EntrySourceType::AKAMAI_LIVE) { $this->streamerType = PlaybackProtocol::RTMP; } if ($this->entry->getSource() == EntrySourceType::AKAMAI_UNIVERSAL_LIVE) { $this->streamerType = PlaybackProtocol::AKAMAI_HDS; } } else { $this->isSecured = $this->isSecured || PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT_USED, $this->entry->getPartnerId()); $forcedDeliveryTypeKey = kDeliveryUtils::getForcedDeliveryTypeKey($this->selectedTag); if ($forcedDeliveryTypeKey) { $defaultDeliveryTypeKey = $forcedDeliveryTypeKey; } else { $defaultDeliveryTypeKey = $this->partner->getDefaultDeliveryType(); } if (!$defaultDeliveryTypeKey || $defaultDeliveryTypeKey == PlaybackProtocol::AUTO) { $deliveryType = $this->selectDeliveryTypeForAuto(); } else { $deliveryType = kDeliveryUtils::getDeliveryTypeFromConfig($defaultDeliveryTypeKey); } if (!$deliveryType) { $deliveryType = array(); } $this->streamerType = kDeliveryUtils::getStreamerType($deliveryType); $this->mediaProtocol = kDeliveryUtils::getMediaProtocol($deliveryType); } $httpStreamerTypes = array(PlaybackProtocol::HTTP, PlaybackProtocol::HDS, PlaybackProtocol::HLS, PlaybackProtocol::SILVER_LIGHT, PlaybackProtocol::MPEG_DASH); if (in_array($this->streamerType, $httpStreamerTypes)) { $this->mediaProtocol = infraRequestUtils::getProtocol(); } if ($this->streamerType == PlaybackProtocol::AKAMAI_HD || $this->streamerType == PlaybackProtocol::AKAMAI_HDS) { $this->mediaProtocol = PlaybackProtocol::HTTP; } //If a plugin can determine the streamerType and mediaProtocol, prefer plugin result $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaContextDataHelper'); foreach ($pluginInstances as $pluginInstance) { /* @var $pluginInstance IKalturaContextDataHelper */ $this->streamerType = $pluginInstance->getContextDataStreamerType($scope, $flavorTags, $this->streamerType); $this->mediaProtocol = $pluginInstance->getContextDataMediaProtocol($scope, $flavorTags, $this->streamerType, $this->mediaProtocol); } }
/** * @param entry $entry */ public static function onEntryReady(entry $entry) { if (!ContentDistributionPlugin::isAllowedPartner($entry->getPartnerId())) { return true; } $distributionProfiles = DistributionProfilePeer::retrieveByPartnerId($entry->getPartnerId()); foreach ($distributionProfiles as $distributionProfile) { if ($distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::AUTOMATIC) { self::addEntryDistribution($entry, $distributionProfile, true); } } return true; }
public static function getEntrySearchValues(entry $entry) { if (!ContentDistributionPlugin::isAllowedPartner($entry->getPartnerId())) { return null; } $entryDistributions = EntryDistributionPeer::retrieveByEntryId($entry->getId()); if (!count($entryDistributions)) { return self::getSearchStringNoDistributionProfiles(); } $searchValues = array(); foreach ($entryDistributions as $entryDistribution) { $distributionProfileId = $entryDistribution->getDistributionProfileId(); $searchValues[] = self::getSearchStringDistributionProfile($distributionProfileId); $searchValues[] = self::getSearchStringDistributionStatus($entryDistribution->getStatus(), $distributionProfileId); $searchValues[] = self::getSearchStringDistributionFlag($entryDistribution->getDirtyStatus(), $distributionProfileId); $searchValues[] = self::getSearchStringDistributionSunStatus($entryDistribution->getSunStatus(), $distributionProfileId); $validationErrors = $entryDistribution->getValidationErrors(); if (count($validationErrors)) { $searchValues[] = self::getSearchStringDistributionHasValidationError($distributionProfileId); } foreach ($validationErrors as $validationError) { $searchValues[] = self::getSearchStringDistributionValidationError($validationError->getErrorType(), $distributionProfileId); } } return implode(' ', $searchValues); }
public static function syncEntriesCategories(entry $entry, $isCategoriesModified) { self::$skipEntrySave = true; if ($entry->getNewCategories() != null && $entry->getNewCategories() !== "") { $newCats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategories()); } else { $newCats = array(); } if (!$isCategoriesModified) { if ($entry->getNewCategoriesIds() != null && $entry->getNewCategoriesIds() !== "") { $newCatsIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategoriesIds()); } else { $newCatsIds = array(); } KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $dbCategories = categoryPeer::retrieveByPKs($newCatsIds); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); foreach ($dbCategories as $dbCategory) { //skip categoy with privacy contexts. if ($dbCategory->getPrivacyContexts() != null && $dbCategory->getPrivacyContexts() != '') { continue; } $newCats[] = $dbCategory->getFullName(); } } $newCats = array_unique($newCats); $allIds = array(); $allCats = array(); $allIdsWithParents = array(); $addedCats = array(); $removedCats = array(); $remainingCats = array(); $oldCats = array(); $oldCatsIds = array(); $dbOldCategoriesEntry = categoryEntryPeer::selectByEntryId($entry->getId()); foreach ($dbOldCategoriesEntry as $dbOldCategoryEntry) { $oldCatsIds[] = $dbOldCategoryEntry->getCategoryId(); } $oldCategoris = categoryPeer::retrieveByPKsNoFilter($oldCatsIds); foreach ($oldCategoris as $category) { if ($category->getPrivacyContexts() != '' && $category->getPrivacyContexts() != null) { continue; } $oldCats[] = $category->getFullName(); } foreach ($oldCats as $cat) { if (array_search($cat, $newCats) === false) { $removedCats[] = $cat; } } foreach ($newCats as $cat) { if (array_search($cat, $oldCats) === false) { $addedCats[] = $cat; } else { $remainingCats[] = $cat; } } foreach ($remainingCats as $cat) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $allIdsWithParents[] = $category->getId(); $allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds()); } } $alreadyAddedCatIds = $allIdsWithParents; foreach ($addedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if (!$category) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $unentitedCategory = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if (!$unentitedCategory) { $category = category::createByPartnerAndFullName($entry->getPartnerId(), $cat); //it is possible to add on an entry a few new categories on the same new parent - //and we need to sync sphinx once we add so the category will not be duplicated kEventsManager::flushEvents(); } } else { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($category->getId(), kCurrentContext::$ks_kuser_id); if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //user is not entitled to add entry to this category $category = null; } } if (!$category) { continue; } //when use caetgoryEntry->add categoryEntry object was alreay created - and no need to create it. //when using baseEntry->categories = 'my category' will need to add the new category. $categoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if (!$categoryEntry) { $categoryEntry = new categoryEntry(); $categoryEntry->setEntryId($entry->getId()); $categoryEntry->setCategoryId($category->getId()); $categoryEntry->setEntryCategoriesAddedIds($alreadyAddedCatIds); $categoryEntry->setPartnerId($entry->getPartnerId()); $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE); $categoryEntry->save(); } if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { // only categories with no context should be set on entry->categories and entry->categoriesIds $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $alreadyAddedCatIds[] = $category->getId(); $alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds()); } $alreadyRemovedCatIds = $allIdsWithParents; foreach ($removedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if ($category) { $categoryEntryToDelete = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if ($categoryEntryToDelete) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntryToDelete->getCategoryId(), kCurrentContext::$ks_kuser_id); if ($category->getPrivacyContexts() && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //not entiteld to delete - should be set back on the entry. $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } else { $categoryEntryToDelete->setEntryCategoriesRemovedIds($alreadyRemovedCatIds); $categoryEntryToDelete->setStatus(CategoryEntryStatus::DELETED); $categoryEntryToDelete->save(); } } $alreadyRemovedCatIds[] = $category->getId(); $alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds()); } else { //category was not found - it could be that user is not entitled to remove it KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } } } self::$skipEntrySave = false; $entry->parentSetCategories(implode(",", $allCats)); $entry->parentSetCategoriesIds(implode(',', $allIds)); }
public static function toQueryString(entry $playlist, $should_append_filter_to_url = false) { $query = "playlist_id={$playlist->getId()}"; if ($playlist->getMediaType() != entry::ENTRY_MEDIA_TYPE_XML) { return $query; } if (!$should_append_filter_to_url) { return $query; } $xml = $playlist->getDataContent(); list($total_results, $list_of_filters) = self::getPlaylistFilterListStruct($xml); $entry_filters = array(); $partner_id = $playlist->getPartnerId(); // add ks=_KS_ for the playlist to replace it before hitting the executePlaylist $query .= "&fp=f"; // make sure the filter prefix is short if (!$list_of_filters) { return $query; } $i = 1; // the extra_filter is 1-based foreach ($list_of_filters as $entry_filter_xml) { $prefix = "f{$i}_"; // in general this service can fetch entries from kaltura networks. // for each filter we should decide if thie assumption is true... $allow_partner_only = true; // compile all the filters - only then execute them if not yet reached the total_results // TODO - optimize - maybe create them only when needed. - For now it's safer to compile all even if not needed. $entry_filter = new entryFilter(); // add the desired prefix "_" because the XML is not expected to have it while the entryFilter class expects it $entry_filter->fillObjectFromXml($entry_filter_xml, "_"); // make sure there is alway a limit for each filter - if not an explicit one - the system limit should be used if ($entry_filter->getLimit() == null || $entry_filter->getLimit() < 1) { $entry_filter->setLimit(self::TOTAL_RESULTS); } $entry_filter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE); self::updateEntryFilter($entry_filter, $partner_id); //$entry_filters[] = $entry_filter; $fields = $entry_filter->fields; foreach ($fields as $field => $value) { if ($value) { $query .= "&" . $prefix . $field . "=" . $value; } } $i++; } return $query; }
public static function updateAdminTags(entry $entry) { // be ready to update the admin_tags if the admin_tags OR the status was modified if ($entry->isColumnModified(entryPeer::ADMIN_TAGS) || $entry->isColumnModified(entryPeer::STATUS)) { $partner_id = $entry->getPartnerId(); // TODO - add the delta of the tags to the cache $admin_tags_str = self::getAdminTags($partner_id, null, true, $entry->getId()); //KalturaLog::log( "1 adminTags for partner [$partner_id]\n$admin_tags_str"); $admin_tags = explode(self::TAG_SEPARATOR, $admin_tags_str); $admin_tags = self::mergeAdminTags($admin_tags, $entry->getAdminTags()); $after_change = self::sortAndSetAdminTags($partner_id, $admin_tags); //KalturaLog::log( "2 adminTags for partner [$partner_id]\n$after_change"); } }
public static function getPrivacyContextForEntry(entry $entry) { $privacyContexts = array(); $entryPrivacy = null; $categories = array(); if (count($entry->getAllCategoriesIds(true))) { $c = KalturaCriteria::create(categoryPeer::OM_CLASS); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $c->add(categoryPeer::ID, $entry->getAllCategoriesIds(true), Criteria::IN); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $categories = categoryPeer::doSelect($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); foreach ($categories as $category) { $categoryPrivacy = $category->getPrivacy(); $categoryPrivacyContexts = $category->getPrivacyContexts(); if (!$categoryPrivacyContexts) { $categoryPrivacyContexts = self::DEFAULT_CONTEXT . $entry->getPartnerId(); } $categoryPrivacyContexts = explode(',', $categoryPrivacyContexts); foreach ($categoryPrivacyContexts as $categoryPrivacyContext) { if (trim($categoryPrivacyContext) == '') { $categoryPrivacyContext = self::DEFAULT_CONTEXT . $entry->getPartnerId(); } if (!isset($privacyContexts[$categoryPrivacyContext]) || $privacyContexts[$categoryPrivacyContext] > $categoryPrivacy) { $privacyContexts[trim($categoryPrivacyContext)] = $categoryPrivacy; } } } } //Entry That doesn't assinged to any category is public. if (!count($categories)) { $privacyContexts[self::DEFAULT_CONTEXT . $entry->getPartnerId()] = PrivacyType::ALL; } $entryPrivacyContexts = array(); foreach ($privacyContexts as $categoryPrivacyContext => $Privacy) { $entryPrivacyContexts[] = $categoryPrivacyContext . '_' . $Privacy; } KalturaLog::debug('Privacy by context: ' . print_r($entryPrivacyContexts, true)); return $entryPrivacyContexts; }
/** * Sets the valid user for the entry * Throws an error if the session user is trying to update entry to another user and not using an admin session * * @param KalturaBaseEntry $entry * @param entry $dbEntry */ protected function checkAndSetValidUserUpdate(KalturaBaseEntry $entry, entry $dbEntry) { KalturaLog::debug("DB puser id [" . $dbEntry->getPuserId() . "] kuser id [" . $dbEntry->getKuserId() . "]"); // user id not being changed if ($entry->userId === null) { KalturaLog::log("entry->userId is null, not changing user"); return; } if (!$this->getKs() || !$this->getKs()->isAdmin()) { $entryPuserId = $dbEntry->getPuserId(); // non admin cannot change the owner of an existing entry if (strtolower($entry->userId) != strtolower($entryPuserId)) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - change required but KS is not admin'); throw new KalturaAPIException(KalturaErrors::INVALID_KS, "", ks::INVALID_TYPE, ks::getErrorStr(ks::INVALID_TYPE)); } } // need to create kuser if this is an admin changing the owner of the entry to a different user $kuser = kuserPeer::createKuserForPartner($dbEntry->getPartnerId(), $entry->userId); KalturaLog::debug("Set kuser id [" . $kuser->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($kuser->getId()); }
private function ingestAsset(entry $entry, $dbAsset, $filename) { $flavorParamsId = $dbAsset->getFlavorParamsId(); $flavorParams = assetParamsPeer::retrieveByPKNoFilter($flavorParamsId); // is first chunk $recordedAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavorParamsId); if ($recordedAsset) { KalturaLog::info("Asset [" . $recordedAsset->getId() . "] of flavor params id [{$flavorParamsId}] already exists"); return; } // create asset $recordedAsset = assetPeer::getNewAsset(assetType::FLAVOR); $recordedAsset->setPartnerId($entry->getPartnerId()); $recordedAsset->setEntryId($entry->getId()); $recordedAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); $recordedAsset->setFlavorParamsId($flavorParams->getId()); $recordedAsset->setFromAssetParams($flavorParams); if ($dbAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { $recordedAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR)); } if ($flavorParams->hasTag(assetParams::TAG_SOURCE)) { $recordedAsset->setIsOriginal(true); } $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext) { $recordedAsset->setFileExt($ext); } $recordedAsset->save(); // create file sync $recordedAssetKey = $recordedAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($filename, $recordedAssetKey, true, true); kEventsManager::raiseEvent(new kObjectAddedEvent($recordedAsset)); }
/** * decideThumbGenerate is the decision layer for a single thumbnail generation * * @param entry $entry * @param thumbParams $destThumbParams * @param BatchJob $parentJob * @return thumbAsset */ public static function decideThumbGenerate(entry $entry, thumbParams $destThumbParams, BatchJob $parentJob = null, $sourceAssetId = null, $runSync = false) { $srcAsset = null; assetPeer::resetInstanceCriteriaFilter(); if ($sourceAssetId) { $srcAsset = assetPeer::retrieveById($sourceAssetId); } else { if ($destThumbParams->getSourceParamsId()) { KalturaLog::debug("Look for flavor params [" . $destThumbParams->getSourceParamsId() . "]"); $srcAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getSourceParamsId()); } if (is_null($srcAsset)) { KalturaLog::debug("Look for original flavor"); $srcAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId()); } if (is_null($srcAsset) || $srcAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::debug("Look for highest bitrate flavor"); $srcAsset = flavorAssetPeer::retrieveHighestBitrateByEntryId($entry->getId()); } } if (is_null($srcAsset)) { throw new APIException(APIErrors::FLAVOR_ASSET_IS_NOT_READY); } $errDescription = null; $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($srcAsset->getId()); $destThumbParamsOutput = self::validateThumbAndMediaInfo($destThumbParams, $mediaInfo, $errDescription); $thumbAsset = thumbAssetPeer::retrieveByEntryIdAndParams($entry->getId(), $destThumbParams->getId()); if ($thumbAsset) { $description = $thumbAsset->getDescription() . "\n" . $errDescription; $thumbAsset->setDescription($description); } else { $thumbAsset = new thumbAsset(); $thumbAsset->setPartnerId($entry->getPartnerId()); $thumbAsset->setEntryId($entry->getId()); $thumbAsset->setDescription($errDescription); $thumbAsset->setFlavorParamsId($destThumbParams->getId()); } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); $thumbAsset->setTags($destThumbParamsOutput->getTags()); $thumbAsset->setFileExt($destThumbParamsOutput->getFileExt()); if (!$destThumbParamsOutput) { $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->save(); return null; } $thumbAsset->save(); // save flavor params $destThumbParamsOutput->setPartnerId($entry->getPartnerId()); $destThumbParamsOutput->setEntryId($entry->getId()); $destThumbParamsOutput->setFlavorAssetId($thumbAsset->getId()); $destThumbParamsOutput->setFlavorAssetVersion($thumbAsset->getVersion()); $destThumbParamsOutput->save(); $srcSyncKey = $srcAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $srcAssetType = $srcAsset->getType(); if (!$runSync) { $job = kJobsManager::addCapturaThumbJob($parentJob, $entry->getPartnerId(), $entry->getId(), $thumbAsset->getId(), $srcSyncKey, $srcAssetType, $destThumbParamsOutput); return $thumbAsset; } $errDescription = null; $capturedPath = self::generateThumbnail($srcAsset, $destThumbParamsOutput, $errDescription); // failed if (!$capturedPath) { $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_ERROR); $thumbAsset->setDescription($thumbAsset->getDescription() . "\n{$errDescription}"); $thumbAsset->save(); return $thumbAsset; } $thumbAsset->incrementVersion(); $thumbAsset->setStatus(thumbAsset::FLAVOR_ASSET_STATUS_READY); if (file_exists($capturedPath)) { list($width, $height, $type, $attr) = getimagesize($capturedPath); $thumbAsset->setWidth($width); $thumbAsset->setHeight($height); $thumbAsset->setSize(filesize($capturedPath)); } $logPath = $capturedPath . '.log'; if (file_exists($logPath)) { $thumbAsset->incLogFileVersion(); $thumbAsset->save(); // creats the file sync $logSyncKey = $thumbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG); kFileSyncUtils::moveFromFile($logPath, $logSyncKey); KalturaLog::debug("Log archived file to: " . kFileSyncUtils::getLocalFilePathForKey($logSyncKey)); } else { $thumbAsset->save(); } $syncKey = $thumbAsset->getSyncKey(thumbAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::moveFromFile($capturedPath, $syncKey); KalturaLog::debug("Thumbnail archived file to: " . kFileSyncUtils::getLocalFilePathForKey($syncKey)); if ($thumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { // increment thumbnail version $entry->setThumbnail(".jpg"); $entry->save(); $entrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $syncFile = kFileSyncUtils::createSyncFileLinkForKey($entrySyncKey, $syncKey, false); if ($syncFile) { // removes the DEFAULT_THUMB tag from all other thumb assets $entryThumbAssets = thumbAssetPeer::retrieveByEntryId($thumbAsset->getEntryId()); foreach ($entryThumbAssets as $entryThumbAsset) { if ($entryThumbAsset->getId() == $thumbAsset->getId()) { continue; } if (!$entryThumbAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { continue; } $entryThumbAsset->removeTags(array(thumbParams::TAG_DEFAULT_THUMB)); $entryThumbAsset->save(); } } } if (!is_null($thumbAsset->getFlavorParamsId())) { kFlowHelper::generateThumbnailsFromFlavor($thumbAsset->getEntryId(), null, $thumbAsset->getFlavorParamsId()); } return $thumbAsset; }
/** * @return string path value * @param entry $entry * @param string $xslStr */ protected function getPathValue(entry $entry, $xslStr) { // set the default criteria to use the current entry distribution partner id (it is restored later) // this is needed for related entries under kMetadataMrssManager which is using retrieveByPK without the correct partner id filter $oldEntryCriteria = entryPeer::getCriteriaFilter()->getFilter(); myPartnerUtils::resetPartnerFilter('entry'); myPartnerUtils::addPartnerToCriteria('entry', $entry->getPartnerId(), true); $mrss = null; $mrssParams = new kMrssParameters(); $mrssParams->setStatuses(array(flavorAsset::ASSET_STATUS_READY, flavorAsset::ASSET_STATUS_EXPORTING)); $mrss = kMrssManager::getEntryMrssXml($entry, $mrss, $mrssParams); $mrssStr = $mrss->asXML(); // restore the original criteria entryPeer::getCriteriaFilter()->setFilter($oldEntryCriteria); if (!$mrssStr) { KalturaLog::err('No MRSS returned for entry [' . $entry->getId() . ']'); return null; } $mrssObj = new DOMDocument(); if (!$mrssObj->loadXML($mrssStr)) { KalturaLog::err('Error loading MRSS XML object for entry [' . $entry->getId() . ']'); return null; } $xslObj = new DOMDocument(); $xslStr = trim($xslStr); if (!$xslObj->loadXML($xslStr)) { KalturaLog::err('Error loading XSL'); return null; } $proc = new XSLTProcessor(); $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions()); $proc->importStyleSheet($xslObj); $resultXmlObj = $proc->transformToDoc($mrssObj); if (!$resultXmlObj) { KalturaLog::err('Error transforming XML for entry id [' . $entry->getId() . ']'); return null; } /* DEBUG logs KalturaLog::log('entry mrss = '.$mrssStr); KalturaLog::log('profile xslt = '.$xslStr); */ KalturaLog::debug('Result XML: ' . $resultXmlObj->saveXML()); $xpath = new DOMXPath($resultXmlObj); $fieldElement = $xpath->query("//path_value")->item(0); if (!$fieldElement) { KalturaLog::err('Cannot find element <path_value> in XML'); return null; } $fieldValue = $fieldElement->nodeValue; return $fieldValue; }
/** * Convert all drop folder files' status from PROCESSING to HANDLED/DELETED in case of DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY * * Note that if the entry reached entryStatus::ERROR_CONVERTING, then the drop folder files' * conversions already failed, so there's no need to change their status (thus they won't be handled here). * * @param entry $entry */ private function onEntryStatusChanged($entry) { // Handle only files that are still in the PROCESSING state, which were left // in this state due to AUTO_DELETE_WHEN_ENTRY_IS_READY delete policy. $dropFolderFiles = DropFolderFilePeer::retrieveByEntryIdPartnerIdAndStatuses($entry->getId(), $entry->getPartnerId(), array(DropFolderFileStatus::PROCESSING)); $dropFolderIdToDropFolderCache = array(); $entryStatus = $entry->getStatus(); foreach ($dropFolderFiles as $dropFolderFile) { $newDropFolderFileStatus = null; if ($entryStatus == entryStatus::ERROR_CONVERTING) { $newDropFolderFileStatus = DropFolderFileStatus::ERROR_HANDLING; } elseif ($entryStatus == entryStatus::READY) { // Get the associated drop folder $dropFolderId = $dropFolderFile->getDropFolderId(); if (key_exists($dropFolderId, $dropFolderIdToDropFolderCache)) { $dropFolder = $dropFolderIdToDropFolderCache[$dropFolderId]; } else { $dropFolder = DropFolderPeer::retrieveByPK($dropFolderId); $dropFolderIdToDropFolderCache[$dropFolderId] = $dropFolder; } if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE_WHEN_ENTRY_IS_READY) { if ($dropFolder->getAutoFileDeleteDays() == 0) { $newDropFolderFileStatus = DropFolderFileStatus::DELETED; // Mark for immediate deletion } else { $newDropFolderFileStatus = DropFolderFileStatus::HANDLED; } } } KalturaLog::info("Entry id [{$entry->getId()}] status [{$entryStatus}], drop folder file id [{$dropFolderFile->getId()}] status [{$dropFolderFile->getStatus()}] => [" . ($newDropFolderFileStatus ? $newDropFolderFileStatus : "{$dropFolderFile->getStatus()} (unchanged)") . "]"); if ($newDropFolderFileStatus) { $dropFolderFile->setStatus($newDropFolderFileStatus); $dropFolderFile->save(); } } }
public function execute() { KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND); $this->deliveryAttributes = new DeliveryProfileDynamicAttributes(); // Parse input parameters $this->deliveryAttributes->setSeekFromTime($this->getRequestParameter("seekFrom", -1)); if ($this->deliveryAttributes->getSeekFromTime() <= 0) { $this->deliveryAttributes->setSeekFromTime(-1); } $this->deliveryAttributes->setClipTo($this->getRequestParameter("clipTo", 0)); $this->deliveryAttributes->setPlaybackRate($this->getRequestParameter("playbackRate", 0)); $deliveryCode = $this->getRequestParameter("deliveryCode", null); $playbackContext = $this->getRequestParameter("playbackContext", null); $this->deliveryAttributes->setMediaProtocol($this->getRequestParameter("protocol", null)); if (!$this->deliveryAttributes->getMediaProtocol() || $this->deliveryAttributes->getMediaProtocol() === "null") { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } $this->deliveryAttributes->setFormat($this->getRequestParameter("format")); if (!$this->deliveryAttributes->getFormat()) { $this->deliveryAttributes->setFormat(PlaybackProtocol::HTTP); } if ($this->deliveryAttributes->getFormat() == self::HDNETWORKSMIL) { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } // Akamai HD doesn't support any other protocol if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::AKAMAI_HDS) { if (strpos($this->deliveryAttributes->getMediaProtocol(), "http") !== 0) { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } } $tags = $this->getRequestParameter("tags", null); if (!$tags) { $this->deliveryAttributes->setTags(self::getDefaultTagsByFormat($this->deliveryAttributes->getFormat())); } else { $tagsArray = explode(',', $tags); $tags = array(); foreach ($tagsArray as $tag) { $tags[] = array(trim($tag)); } $this->deliveryAttributes->setTags($tags); } $this->deliveryAttributes->setpreferredBitrate($this->getRequestParameter("preferredBitrate", null)); $this->maxBitrate = $this->getRequestParameter("maxBitrate", null); if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) { KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE); } $this->deliveryAttributes->setStorageId($this->getRequestParameter("storageId", null)); $this->cdnHost = $this->getRequestParameter("cdnHost", null); $this->deliveryAttributes->setResponseFormat($this->getRequestParameter("responseFormat", null)); // Initialize $this->initEntry(); $this->deliveryAttributes->setEntryId($this->entryId); $this->deliveryAttributes->setUsePlayServer((bool) $this->getRequestParameter("usePlayServer") && PermissionPeer::isValidForPartner(PermissionName::FEATURE_PLAY_SERVER, $this->entry->getPartnerId())); if ($this->deliveryAttributes->getUsePlayServer()) { $this->deliveryAttributes->setPlayerConfig($this->getRequestParameter("playerConfig")); //In case request needs to be redirected to play-server we need to add the ui conf id to the manifest url as well $this->deliveryAttributes->setUiConfId($this->getRequestParameter("uiConfId")); } $this->secureEntryHelper->updateDeliveryAttributes($this->deliveryAttributes); $this->enforceEncryption(); $renderer = null; switch ($this->entry->getType()) { case entryType::MEDIA_CLIP: // VOD $renderer = $this->serveVodEntry(); break; case entryType::LIVE_STREAM: case entryType::LIVE_CHANNEL: // Live stream $renderer = $this->serveLiveEntry(); break; default: KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE); } if (!$renderer) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'This format is unsupported'); } $renderer->contributors = array(); $config = new kManifestContributorConfig(); $config->format = $this->deliveryAttributes->getFormat(); $config->deliveryCode = $deliveryCode; $config->storageId = $this->deliveryAttributes->getStorageId(); $config->entryId = $this->entryId; $contributors = KalturaPluginManager::getPluginInstances('IKalturaPlayManifestContributor'); foreach ($contributors as $contributor) { /* @var $contributor IKalturaPlayManifestContributor */ $renderer->contributors = array_merge($renderer->contributors, $contributor->getManifestEditors($config)); } $renderer->entryId = $this->entryId; $renderer->duration = $this->duration; if ($this->deliveryProfile) { $renderer->tokenizer = $this->deliveryProfile->getTokenizer(); } $renderer->defaultDeliveryCode = $this->entry->getPartner()->getDefaultDeliveryCode(); $renderer->lastModified = time(); // Handle caching $canCacheAccessControl = false; if (kConf::hasParam("force_caching_headers") && in_array($this->entry->getPartnerId(), kConf::get("force_caching_headers"))) { $renderer->cachingHeadersAge = 60; $renderer->forceCachingHeaders = true; } if (!$this->secureEntryHelper) { $canCacheAccessControl = true; // TODO: reconsider this if/when expired ktokens will be used } else { if (!$this->secureEntryHelper->shouldDisableCache() && !$this->secureEntryHelper->isKsAdmin() && ($this->secureEntryHelper->isKsWidget() || !$this->secureEntryHelper->hasRules())) { $canCacheAccessControl = true; } } if (!$renderer->tokenizer && $canCacheAccessControl) { // Note: kApiCache::hasExtraFields is checked in kManifestRenderers $renderer->cachingHeadersAge = 60; } if (!$this->secureEntryHelper || !$this->secureEntryHelper->shouldDisableCache()) { $cache = kPlayManifestCacher::getInstance(); $cache->storeRendererToCache($renderer); } // Output the response KExternalErrors::terminateDispatch(); $renderer->output($deliveryCode, $playbackContext); }