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; }
public function toObject($dbObject = null, $props_to_skip = array()) { parent::toObject($dbObject, $props_to_skip); if ($this->bitrates) { $dbObject->setStreamBitrates($this->bitrates->toArray()); } return $dbObject; }
function update($entryId, KalturaMediaEntry $mediaEntry) { $kparams = array(); $this->client->addParam($kparams, "entryId", $entryId); $this->client->addParam($kparams, "mediaEntry", $mediaEntry->toParams()); $this->client->queueServiceActionCall("media", "update", $kparams); if ($this->client->isMultiRequest()) { return null; } $resultObject = $this->client->doQueue(); $this->client->throwExceptionIfError($resultObject); $this->client->validateObjectType($resultObject, "KalturaMediaEntry"); return $resultObject; }
/** * 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; }
/** * add KalturaMediaEntry from email ingestion * * @action addMediaEntry * @param KalturaMediaEntry $mediaEntry Media entry metadata * @param string $uploadTokenId Upload token id * @param int $emailProfId * @param string $fromAddress * @param string $emailMsgId * * @return KalturaMediaEntry * * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN * @throws KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND * */ function addMediaEntryAction(KalturaMediaEntry $mediaEntry, $uploadTokenId, $emailProfId, $fromAddress, $emailMsgId) { try { // check that the uploaded file exists $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId); if (!file_exists($entryFullPath)) { throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN); } // get the email profile by the given id $existingEIP = EmailIngestionProfilePeer::retrieveByPK($emailProfId); if (!$existingEIP) { throw new KalturaAPIException(KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND, $emailProfId); } $emailIP = new KalturaEmailIngestionProfile(); $emailIP->fromObject($existingEIP, $this->getResponseProfile()); // handle defaults for media entry metadata $this->changeIfNull($mediaEntry->tags, $emailIP->defaultTags); $this->changeIfNull($mediaEntry->adminTags, $emailIP->defaultAdminTags); $this->changeIfNull($mediaEntry->conversionProfileId, $emailIP->conversionProfile2Id); $this->changeIfNull($mediaEntry->userId, $emailIP->defaultUserId); if (is_null($mediaEntry->categories) || is_null(categoryPeer::getByFullNameExactMatch($mediaEntry->categories))) { $mediaEntry->categories = $emailIP->defaultCategory; } // validate the input object //$entry->validatePropertyMinLength("name", 1); if (!$mediaEntry->name) { $mediaEntry->name = $this->getPartnerId() . '_' . time(); } // first copy all the properties to the db entry, then we'll check for security stuff $dbEntry = $mediaEntry->toObject(new entry()); if ($emailIP->moderationStatus == KalturaEntryModerationStatus::PENDING_MODERATION) { $dbEntry->setModerate(true); } $dbEntry->setType(KalturaEntryType::MEDIA_CLIP); $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC); $this->checkAndSetValidUserInsert($mediaEntry, $dbEntry); $this->checkAdminOnlyInsertProperties($mediaEntry); $this->validateAccessControlId($mediaEntry); $this->validateEntryScheduleDates($mediaEntry, $dbEntry); $dbEntry->setPartnerId($this->getPartnerId()); $dbEntry->setSubpId($this->getPartnerId() * 100); $dbEntry->setSourceId($uploadTokenId); $dbEntry->setSourceLink($entryFullPath); $dbEntry->setDefaultModerationStatus(); $dbEntry->save(); $te = new TrackEntry(); $te->setEntryId($dbEntry->getId()); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY); $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_EMAIL_INGESTION"); $te->setParam1Str($fromAddress); $te->setParam2Str($emailMsgId); $te->setParam3Str($emailProfId . '::' . $emailIP->emailAddress . '::' . $emailIP->mailboxId); TrackEntry::addTrackEntry($te); $kshow = $this->createDummyKShow(); $kshowId = $kshow->getId(); myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath); // 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); myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry); $mediaEntry->fromObject($dbEntry, $this->getResponseProfile()); return $mediaEntry; } catch (kCoreException $ex) { if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) { } throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY); throw $ex; } }
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)); }
public function doFromObject($dbObject, KalturaDetachedResponseProfile $responseProfile = null) { if (!$dbObject instanceof LiveEntry) { return; } parent::doFromObject($dbObject, $responseProfile); if ($this->shouldGet('recordingOptions', $responseProfile) && !is_null($dbObject->getRecordingOptions())) { $this->recordingOptions = new KalturaLiveEntryRecordingOptions(); $this->recordingOptions->fromObject($dbObject->getRecordingOptions()); } }
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'); }
function update($entryId, KalturaMediaEntry $mediaEntry) { $kparams = array(); $this->client->addParam($kparams, "entryId", $entryId); $this->client->addParam($kparams, "mediaEntry", $mediaEntry->toParams()); $resultObject = $this->client->callService("media", "update", $kparams); $this->client->throwExceptionIfError($resultObject); $this->client->validateObjectType($resultObject, "KalturaMediaEntry"); return $resultObject; }
public function validateForInsert($propertiesToSkip = array()) { $this->validatePropertyNotNull('mediaType'); $this->validatePropertyNotNull('externalSourceType'); parent::validateForInsert($propertiesToSkip); }