public function fromObject($source_object) { if (!$source_object instanceof entry) { return; } parent::fromObject($source_object); $bitrates = $source_object->getStreamBitrates(); if (is_array($bitrates)) { $this->bitrates = KalturaLiveStreamBitrateArray::fromLiveStreamBitrateArray($bitrates); } }
public static function fromEntryArray($arr) { $newArr = new KalturaMediaEntryArray(); if ($arr == null) { return $newArr; } foreach ($arr as $obj) { $nObj = new KalturaMediaEntry(); $nObj->fromObject($obj); $newArr[] = $nObj; } return $newArr; }
/** * Add new entry after the specific media file was uploaded and the upload token id exists * * @action addFromUploadedFile * @param KalturaMediaEntry $mediaEntry Media entry metadata * @param string $uploadTokenId Upload token id * @return KalturaMediaEntry The new media entry * * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN */ function addFromUploadedFileAction(KalturaMediaEntry $mediaEntry, $uploadTokenId) { try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId()); if ($remoteDCHost) { kFile::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } } $dbEntry = $this->prepareEntryForInsert($mediaEntry); $kshowId = $dbEntry->getKshowId(); // setup the needed params for my insert entry helper $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags()); $token = $this->getKsUniqueString(); $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray); $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100); $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry); $dbEntry = $insert_entry_helper->getEntry(); kUploadTokenMgr::closeUploadTokenById($uploadTokenId); $ret = new KalturaMediaEntry(); if ($dbEntry) { myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry, $dbEntry->getPartnerId(), null, null, null, $dbEntry->getId()); $ret->fromObject($dbEntry); } return $ret; }
/** * Add new entry after the specific media file was uploaded and the upload token id exists * * @action addFromUploadedFile * @param KalturaMediaEntry $mediaEntry Media entry metadata * @param string $uploadTokenId Upload token id * @return KalturaMediaEntry The new media entry * * @throws KalturaErrors::PROPERTY_VALIDATION_MIN_LENGTH * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN * * @deprecated use media.add instead */ function addFromUploadedFileAction(KalturaMediaEntry $mediaEntry, $uploadTokenId) { if ($mediaEntry->conversionQuality && !$mediaEntry->conversionProfileId) { $mediaEntry->conversionProfileId = $mediaEntry->conversionQuality; } try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); // Make sure that the uploads path is not modified by $uploadTokenId (with the value of "../" for example ) $entryRootDir = realpath(dirname($entryFullPath)); $uploadPathBase = realpath(myContentStorage::getFSUploadsPath()); if (strpos($entryRootDir, $uploadPathBase) !== 0) { KalturaLog::err("uploadTokenId [{$uploadTokenId}] points outside of uploads directory"); throw new KalturaAPIException(KalturaErrors::INVALID_UPLOAD_TOKEN_ID); } } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } if (!file_exists($entryFullPath)) { // Backward compatability - support case in which the required file exist in the other DC kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrlByDcId(1 - kDataCenterMgr::getCurrentDcId())); /* $remoteDCHost = kUploadTokenMgr::getRemoteHostForUploadToken($uploadTokenId, kDataCenterMgr::getCurrentDcId()); if($remoteDCHost) { kFileUtils::dumpApiRequest($remoteDCHost); } else { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } */ } $dbEntry = parent::add($mediaEntry, $mediaEntry->conversionProfileId); $kshowId = $dbEntry->getKshowId(); // setup the needed params for my insert entry helper $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags()); $token = $this->getKsUniqueString(); $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray); $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100); $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry); $dbEntry = $insert_entry_helper->getEntry(); kUploadTokenMgr::closeUploadTokenById($uploadTokenId); $ret = new KalturaMediaEntry(); if ($dbEntry) { myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry, $dbEntry->getPartnerId(), null, null, null, $dbEntry->getId()); $ret->fromObject($dbEntry, $this->getResponseProfile()); } return $ret; }
public function execute($limit = 0) { if ($this->executed) { return; } if ($limit) { $this->limit = $limit; } $microTimeStart = microtime(true); $renderer = KalturaSyndicationFeedFactory::getRendererByType($this->syndicationFeed->type); $renderer->init($this->syndicationFeed, $this->syndicationFeedDb, $this->mimeType); header($renderer->handleHttpHeader()); echo $renderer->handleHeader(); $cacheStore = null; if ($renderer->shouldEnableCache()) { $cacheStore = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_FEED_ENTRY); } $protocol = infraRequestUtils::getProtocol(); $cachePrefix = "feed_{$this->syndicationFeed->id}/{$protocol}/entry_"; $feedUpdatedAt = $this->syndicationFeedDb->getUpdatedAt(null); $e = null; $kalturaFeed = $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA || $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA_XSLT; $nextEntry = $this->getNextEntry(); while ($nextEntry) { $this->enableApcProcessingFlag(); $entry = $nextEntry; $nextEntry = $this->getNextEntry(); // in case no video player is requested by user and the entry is mix, skip it if ($entry->getType() === entryType::MIX && !$this->syndicationFeed->allowEmbed) { continue; } $xml = false; // check cache $updatedAt = max($feedUpdatedAt, $entry->getUpdatedAt(null)); if ($cacheStore) { $cacheKey = $cachePrefix . str_replace("_", "-", $entry->getId()) . self::CACHE_VERSION; // replace _ with - so cache folders will be created with random entry id and not 0_/1_ $cacheTime = $cacheStore->get($cacheKey . self::CACHE_CREATION_TIME_SUFFIX); if ($cacheTime !== false && $cacheTime > $updatedAt + self::CACHE_CREATION_MARGIN) { $xml = $cacheStore->get($cacheKey); } } if ($xml === false) { $e = null; if (!$kalturaFeed) { $e = new KalturaMediaEntry(); $e->fromObject($entry); } $flavorAssetUrl = is_null($e) ? null : $this->getFlavorAssetUrl($e); if (!$kalturaFeed && $entry->getType() !== entryType::MIX && is_null($flavorAssetUrl)) { $xml = ""; // cache empty result to avoid checking getFlavorAssetUrl next time } else { $xml = $renderer->handleBody($entry, $e, $flavorAssetUrl); } } if ($cacheStore) { $cacheStore->set($cacheKey . self::CACHE_CREATION_TIME_SUFFIX, time(), self::CACHE_EXPIRY); $cacheStore->set($cacheKey, $xml, self::CACHE_EXPIRY); } echo $renderer->finalize($xml, $nextEntry !== false); } echo $renderer->handleFooter(); if ($this->feedProcessingKey && function_exists('apc_delete')) { apc_delete($this->feedProcessingKey); } $microTimeEnd = microtime(true); KalturaLog::info("syndicationFeedRenderer- render time for ({$this->syndicationFeed->type}) is " . ($microTimeEnd - $microTimeStart)); }
public function execute($limit = 0) { if ($this->executed) { return; } if ($limit) { $this->limit = $limit; } $microTimeStart = microtime(true); $renderers = array(KalturaSyndicationFeedType::GOOGLE_VIDEO => "renderGoogleVideoFeed", KalturaSyndicationFeedType::ITUNES => "renderITunesFeed", KalturaSyndicationFeedType::TUBE_MOGUL => "renderTubeMogulFeed", KalturaSyndicationFeedType::YAHOO => "renderYahooFeed", KalturaSyndicationFeedType::KALTURA => "renderKalturaFeed", KalturaSyndicationFeedType::KALTURA_XSLT => "renderKalturaFeed"); $renderer = array($this, $renderers[$this->syndicationFeed->type]); call_user_func($renderer, self::STATE_HEADER); $cacheStore = null; // kCacheManager::getCache(kCacheManager::FS_ENTRY); $cachePrefix = "feed_{$this->syndicationFeed->id}/entry-"; $feedUpdatedAt = $this->syndicationFeedDB->getUpdatedAt(null); $e = null; $kalturaFeed = $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA || $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA_XSLT; $nextEntry = $this->getNextEntry(); while ($nextEntry) { $entry = $nextEntry; $nextEntry = $this->getNextEntry(); // in case no video player is requested by user and the entry is mix, skip it if ($entry->getType() === entryType::MIX && !$this->syndicationFeed->allowEmbed) { continue; } $xml = false; // check cache $updatedAt = max($feedUpdatedAt, $entry->getUpdatedAt(null)); if ($cacheStore) { $cacheKey = $cachePrefix . str_replace("_", "-", $entry->getId()); // replace _ with - so cache folders will be created with random entry id and not 0_/1_ $cacheTime = $cacheStore->get($cacheKey . self::CACHE_CREATION_TIME_SUFFIX); if ($cacheTime !== false && $cacheTime > $updatedAt + self::CACHE_CREATION_MARGIN) { $xml = $cacheStore->get($cacheKey); if ($xml !== false) { echo $xml; continue; } } } $e = null; if (!$kalturaFeed) { $e = new KalturaMediaEntry(); $e->fromObject($entry); // non kaltura feeds require a flavor asset url if (!$kalturaFeed && $entry->getType() !== entryType::MIX && $this->getFlavorAssetUrl($e) == null) { $xml = ""; } // cache empty result to avoid checking getFlavorAssetUrl next time } if ($xml === false) { ob_start(); call_user_func($renderer, self::STATE_BODY, $entry, $e, $nextEntry !== false); $xml = ob_get_flush(); } if ($cacheStore) { $cacheStore->set($cacheKey . self::CACHE_CREATION_TIME_SUFFIX, time()); $cacheStore->set($cacheKey, $xml); } } call_user_func($renderer, self::STATE_FOOTER); $microTimeEnd = microtime(true); KalturaLog::info("syndicationFeedRenderer- render time for ({$this->syndicationFeed->type}) is " . ($microTimeEnd - $microTimeStart)); }
private function renderGoogleVideoFeed() { header("content-type: text/xml; charset=utf-8"); $uiconfId = $this->syndicationFeed->playerUiconfId ? '/ui_conf_id/' . $this->syndicationFeed->playerUiconfId : ''; $this->writeOpenXmlNode('urlset', 0, array('xmlns' => "http://www.sitemaps.org/schemas/sitemap/0.9", 'xmlns:video' => "http://www.google.com/schemas/sitemap-video/1.1")); while ($entry = $this->getNextEntry()) { $e = new KalturaMediaEntry(); $e->fromObject($entry); // in case no video player is requested by user and the entry is mix, skip it if ($entry->getType() === entryType::MIX && !$this->syndicationFeed->allowEmbed || $entry->getType() !== entryType::MIX && $this->getFlavorAssetUrl($e) == null) { continue; } $this->writeOpenXmlNode('url', 1); $this->writeFullXmlNode('loc', $this->syndicationFeed->landingPage . $e->id, 2); $this->writeOpenXmlNode('video:video', 2); $this->writeFullXmlNode('video:content_loc', $this->getFlavorAssetUrl($e), 3); if ($this->syndicationFeed->allowEmbed) { $this->writeFullXmlNode('video:player_loc', $this->getPlayerUrl($e->id), 3, array('allow_embed' => 'yes')); } $this->writeFullXmlNode('video:thumbnail_loc', $e->thumbnailUrl . '/width/480', 3); $this->writeFullXmlNode('video:title', $this->stringToSafeXml($e->name), 3); $this->writeFullXmlNode('video:description', $this->stringToSafeXml($e->description), 3); $this->writeFullXmlNode('video:view_count', $e->views, 3); $this->writeFullXmlNode('video:publication_date', date('Y-m-d', $e->createdAt) . 'T' . date('H:i:sP', $e->createdAt), 3); $tags = explode(',', $e->tags); foreach ($tags as $tag) { if (!$tag) { continue; } $this->writeFullXmlNode('video:tag', rtrim(ltrim($this->stringToSafeXml($tag))), 3); } $this->writeFullXmlNode('video:category', $this->stringToSafeXml($e->categories), 3); if ($this->syndicationFeed->adultContent == KalturaGoogleSyndicationFeedAdultValues::NO) { $familyFriendly = KalturaGoogleSyndicationFeedAdultValues::YES; } else { $familyFriendly = KalturaGoogleSyndicationFeedAdultValues::NO; } $this->writeFullXmlNode('video:family_friendly', $familyFriendly, 3); $this->writeFullXmlNode('video:duration', $e->duration, 3); $this->writeClosingXmlNode('video:video', 2); $this->writeClosingXmlNode('url', 1); } $this->writeClosingXmlNode('urlset'); }