/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $url = parent::doGetFileSyncUrl($fileSync); if (in_array($fileSync->getPartnerId(), array(666132, 628012, 357521, 560751)) && kString::beginsWith($url, "mp4:")) { $url .= ".mp4"; } return $url; }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $fileSync = kFileSyncUtils::resolve($fileSync); $url = parent::doGetFileSyncUrl($fileSync); $url = ltrim($url, '/'); if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { return "/hls-vod/{$url}.m3u8"; } return "/hds-vod/{$url}.f4m"; }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $url = parent::doGetFileSyncUrl($fileSync); $url = preg_replace('/^mp4:(\\/)*/', 'mp4:', $url); if ($this->protocol == StorageProfile::PLAY_FORMAT_HTTP) { $syncKey = kFileSyncUtils::getKeyForFileSync($fileSync); $url = $this->addEcSeek($url, $syncKey); } return $url; }
protected static function getAssetUrl(asset $asset) { $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId()); $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId()); $urlManager->setDomain($cdnHost); $url = $urlManager->getAssetUrl($asset); $url = $cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt(); return $url; }
public function getExternalUrl($format = StorageProfile::PLAY_FORMAT_HTTP) { $storage = StorageProfilePeer::retrieveByPK($this->getDc()); if (!$storage || $storage->getProtocol() == StorageProfile::STORAGE_KALTURA_DC) { return kDataCenterMgr::getInternalRemoteUrl($this); } $urlManager = kUrlManager::getUrlManagerByStorageProfile($this->getDc()); $url = $urlManager->getFileSyncUrl($this); if ($format == StorageProfile::PLAY_FORMAT_RTMP) { return $storage->getDeliveryRmpBaseUrl() . '/' . $url; } return $storage->getDeliveryHttpBaseUrl() . '/' . $url; }
/** * Returns the url for the given flavor. in case of rtmp, return the file path in order ot use a local streaming server * * @param flavorAsset $flavorAsset * @return string */ protected function doGetFlavorAssetUrl(flavorAsset $flavorAsset) { if ($this->protocol != StorageProfile::PLAY_FORMAT_RTMP) { return parent::doGetFlavorAssetUrl($flavorAsset); } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); $url = $this->doGetFileSyncUrl($fileSync); if ($this->extention && strtolower($this->extention) != 'flv' || $this->containerFormat && strtolower($this->containerFormat) != 'flash video') { $url = "mp4:{$url}"; } $url = str_replace('\\', '/', $url); return $url; }
/** * @param FileSync $fileSync * @return string */ protected function doGetFileSyncUrl(FileSync $fileSync) { $fileSync = kFileSyncUtils::resolve($fileSync); $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return parent::doGetFileSyncUrl($fileSync); } $serverUrl = $storage->getDeliveryIisBaseUrl(); $partnerPath = myPartnerUtils::getUrlForPartner($fileSync->getPartnerId(), $fileSync->getPartnerId() * 100); if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP && isset($this->params["hd_ios"])) { $path = $fileSync->getFilePath(); $urlSuffix = str_replace('\\', '/', $path) . "/index_0_av.m3u8"; $urlPrefix = "http://" . $this->params["hd_ios"] . '/i/'; return $urlPrefix . ltrim($urlSuffix, '/'); } if ($this->protocol == "hdnetworksmil" && isset($this->params["hd_flash"])) { $path = $fileSync->getFilePath(); $urlSuffix = str_replace('\\', '/', $path); $urlPrefix = "http://" . $this->params["hd_flash"]; return $urlPrefix . '/' . ltrim($urlSuffix, '/'); } if ($fileSync->getObjectSubType() != entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) { return parent::doGetFileSyncUrl($fileSync); } $serverUrl = myPartnerUtils::getIisHost($fileSync->getPartnerId(), "http"); $path = $partnerPath . '/serveIsm/objectId/' . $fileSync->getObjectId() . '_' . $fileSync->getObjectSubType() . '_' . $fileSync->getVersion() . '.' . pathinfo(kFileSyncUtils::resolve($fileSync)->getFilePath(), PATHINFO_EXTENSION) . '/manifest'; $matches = null; if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $serverUrl, $matches)) { $path = $matches[2] . $path; } $path = str_replace('//', '/', $path); return $path; }
private function serveRtmp() { switch ($this->entry->getType()) { case entryType::MEDIA_CLIP: $duration = $this->entry->getDurationInt(); $flavorAssets = array(); if ($this->flavorId) { $flavorAsset = flavorAssetPeer::retrieveById($this->flavorId); if (!$flavorAsset->hasTag(flavorParams::TAG_WEB)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if (!$flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } $flavorAssets[] = $flavorAsset; } else { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_MBR); if (!count($flavorAssets)) { $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB); } } $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets); if (!$this->storageId) { $partner = $this->entry->getPartner(); $finalFlavors = array(); if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) { foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key); if ($fileSync) { $finalFlavors[] = $flavorAsset; } } } if (!count($finalFlavors) && $partner->getStorageServePriority() && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { $storages = StorageProfilePeer::retrieveExternalByPartnerId($partner->getId()); if (count($storages) == 1) { $this->storageId = $storages[0]->getId(); } elseif (count($storages)) { $storagesFlavors = array(); foreach ($storages as $storage) { $storagesFlavors[$storage->getId()] = array(); foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storage->getId()); if ($fileSync) { $storagesFlavors[$storage->getId()][] = $flavorAsset; } } } $maxCount = 0; foreach ($storagesFlavors as $storageId => $storageFlavors) { $count = count($storageFlavors); if ($count > $maxCount) { $maxCount = $count; $this->storageId = $storageId; $finalFlavors = $storageFlavors; } } $flavorAssets = $finalFlavors; } else { foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key); if ($fileSync) { $finalFlavors[] = $flavorAsset; } } } } } foreach ($flavorAssets as $flavorAsset) { $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId()); if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) { $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration()); $duration /= 1000; break; } } $baseUrl = null; $flavors = array(); if ($this->storageId) { $storage = StorageProfilePeer::retrieveByPK($this->storageId); if (!$storage) { die; } $baseUrl = $storage->getDeliveryRmpBaseUrl(); // get all flavors with external urls foreach ($flavorAssets as $flavorAsset) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId); if (!$fileSync) { continue; } $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc()); $urlManager->setClipTo($this->clipTo); $urlManager->setFileExtension($flavorAsset->getFileExt()); $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP); $url = $urlManager->getFileSyncUrl($fileSync); $url = preg_replace('/^\\//', '', $url); $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight()); } } else { $partnerId = $this->entry->getPartnerId(); $subpId = $this->entry->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId); $baseUrl = myPartnerUtils::getRtmpUrl($partnerId); $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost); // get all flavors with kaltura urls foreach ($flavorAssets as $flavorAsset) { $urlManager->setClipTo($this->clipTo); $urlManager->setFileExtension($flavorAsset->getFileExt()); $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP); $url = $urlManager->getFlavorAssetUrl($flavorAsset); $url = preg_replace('/^\\//', '', $url); $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight()); } } if (!count($flavors)) { KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND); } if (strpos($this->protocol, "rtmp") === 0) { $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl); } return $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, $flavors, 'video/x-flv', $duration, $baseUrl); case entryType::LIVE_STREAM: $streamId = $this->entry->getStreamRemoteId(); $streamUsername = $this->entry->getStreamUsername(); $baseUrl = $this->entry->getStreamUrl(); $baseUrl = rtrim($baseUrl, '/'); $flavors = $this->entry->getStreamBitrates(); if (count($flavors)) { foreach ($flavors as $index => $flavor) { $brIndex = $index + 1; $flavors[$index]['url'] = str_replace('%i', $brIndex, $this->entry->getStreamName()); } } else { $flavors[0]['url'] = str_replace('%i', '1', $this->entry->getStreamName()); } if (strpos($this->protocol, "rtmp") === 0) { $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl); } return $this->buildXml(self::PLAY_STREAM_TYPE_LIVE, $flavors, 'video/x-flv', null, $baseUrl); } KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE); }
public static function enforceDelivery($partnerId) { $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner || !$partner->getDeliveryRestrictions()) { return; } $deliveryRestrictions = $partner->getDeliveryRestrictions(); $deliveryRestrictionsArr = explode(",", $deliveryRestrictions); $delivery = kUrlManager::getUrlManagerIdentifyRequest(); $restricted = true; foreach ($deliveryRestrictionsArr as $deliveryRestriction) { if ($deliveryRestriction === $delivery) { $restricted = false; break; } } if ($restricted) { KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]"); KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED); } }
public function getAssetUrl(asset $asset) { $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId()); $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId()); $urlManager->setDomain($cdnHost); $url = $urlManager->getAssetUrl($asset); $url = $cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); return 'http://' . $url; }
private function getFlavorAssetUrl($kalturaEntry) { $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId); if (!$partner) { return null; } $flavorAsset = assetPeer::retrieveByEntryIdAndParams($kalturaEntry->id, $this->syndicationFeed->flavorParamId); if (!$flavorAsset) { return null; } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = $this->getExternalStorageUrl($partner, $flavorAsset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $this->protocol = StorageProfile::PLAY_FORMAT_HTTP; $this->cdnHost = myPartnerUtils::getCdnHost($this->syndicationFeed->partnerId, $this->protocol); $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost, $flavorAsset->getEntryId()); $urlManager->setDomain($this->cdnHost); $url = $urlManager->getAssetUrl($flavorAsset); $url = $this->cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); return $this->protocol . '://' . $url; }
private static function addIsmLink(entry $entry, SimpleXMLElement $mrss) { if (self::$addedIsmUrl) { return; } self::$addedIsmUrl = true; $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); $kalturaFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey); $urlPrefix = myPartnerUtils::getIisHost($entry->getPartnerId(), StorageProfile::PLAY_FORMAT_HTTP); $iisHost = parse_url($urlPrefix, PHP_URL_HOST); $matches = null; if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $urlPrefix, $matches)) { $urlPrefix = $matches[1]; } $urlPrefix = rtrim($urlPrefix, '/') . '/'; $urlManager = kUrlManager::getUrlManagerByCdn($iisHost, $entry->getId()); if ($kalturaFileSync) { $urlManager->setFileExtension(pathinfo($kalturaFileSync->getFilePath(), PATHINFO_EXTENSION)); } $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_SILVER_LIGHT); $partner = $entry->getPartner(); if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) { if ($kalturaFileSync) { $url = $urlManager->getFileSyncUrl($kalturaFileSync, false); $mrss->addChild('ismUrl', $urlPrefix . $url); return; } } if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { return null; } $externalFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey); if ($externalFileSync) { $urlManager = kUrlManager::getUrlManagerByStorageProfile($externalFileSync->getDc(), $entry->getId()); $urlManager->setFileExtension(pathinfo($externalFileSync->getFilePath(), PATHINFO_EXTENSION)); $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_SILVER_LIGHT); $url = $urlManager->getFileSyncUrl($externalFileSync, false); $url = ltrim($url, '/'); if (strpos($url, "://") !== false) { $urlPrefix = ''; } $mrss->addChild('ismUrl', $urlPrefix . $url); return; } if ($partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { if ($kalturaFileSync) { $url = $urlManager->getFileSyncUrl($kalturaFileSync, false); $mrss->addChild('ismUrl', $urlPrefix . $url); return; } } }
public function getExternalUrl($storageId) { $key = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId); if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) { return null; } $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return null; } $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc(), $this->getEntryId()); $urlManager->setFileExtension($this->getFileExt()); $url = rtrim($storage->getDeliveryHttpBaseUrl(), "/") . "/" . ltrim($urlManager->getFileSyncUrl($fileSync), "/"); return $url; }
/** * @param asset $asset * @return string */ protected static function getAssetUrl(asset $asset) { $partner = PartnerPeer::retrieveByPK($asset->getPartnerId()); if (!$partner) { return null; } $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $externalStorageUrl = self::getExternalStorageUrl($partner, $asset, $syncKey); if ($externalStorageUrl) { return $externalStorageUrl; } if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) { return null; } $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId()); $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost); $urlManager->setDomain($cdnHost); $url = $urlManager->getAssetUrl($asset); $url = $cdnHost . $url; $url = preg_replace('/^https?:\\/\\//', '', $url); return 'http://' . $url; }
/** * @param string $cdnHost * @param FileSync $fileSync * @param flavorAsset $flavorAsset * @param string $format * @return kUrlManager */ private function getUrlManagerByCdn($cdnHost, FileSync $fileSync = null, flavorAsset $flavorAsset = null, $format = null) { $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $this->entryId); $this->setupUrlManager($urlManager, $fileSync, $flavorAsset, $format); return $urlManager; }
/** * @param FileSync $fileSync * @return string */ public function getFileSyncUrl(FileSync $fileSync) { $fileSync = kFileSyncUtils::resolve($fileSync); $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return parent::getFileSyncUrl($fileSync); } $serverUrl = $storage->getDeliveryIisBaseUrl(); $partnerPath = myPartnerUtils::getUrlForPartner($fileSync->getPartnerId(), $fileSync->getPartnerId() * 100); if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP) { return $partnerPath . $fileSync->getFilePath() . "/playlist.m3u8"; } if ($fileSync->getObjectSubType() != entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM) { return parent::getFileSyncUrl($fileSync); } $path = $partnerPath . '/serveIsm/objectId/' . $fileSync->getObjectId() . '_' . $fileSync->getObjectSubType() . '_' . $fileSync->getVersion() . '.' . pathinfo(kFileSyncUtils::resolve($fileSync)->getFilePath(), PATHINFO_EXTENSION) . '/manifest'; // $path = $partnerPath.'/serveIsm/objectId/'.pathinfo(kFileSyncUtils::resolve($fileSync)->getFilePath(), PATHINFO_BASENAME).'/manifest'; $matches = null; if (preg_match('/(https?:\\/\\/[^\\/]+)(.*)/', $serverUrl, $matches)) { $serverUrl = $matches[1]; $path = $matches[2] . $path; } $path = str_replace('//', '/', $path); $window = $this->params['smooth_auth_seconds']; $param = $this->params['smooth_auth_param']; $salt = $this->params['smooth_auth_salt']; $authPath = $this->urlauth_gen_url($path, $param, $window, $salt, null, null); return $serverUrl . '/' . $authPath; }