/** * @return array */ protected function getSecureHdUrl() { $params = array(); if ($this->getSupportClipping()) { $seekStart = $this->params->getSeekFromTime(); $seekEnd = $this->params->getClipTo(); if ($seekStart != -1) { $params['start'] = floor($this->params->getSeekFromTime() / 1000); $this->params->setSeekFromTime(-1); } else { if ($seekEnd) { $params['start'] = 0; } } if ($seekEnd) { $params['end'] = ceil($this->params->getClipTo() / 1000); $this->params->setClipTo(null); } } $flavors = $this->buildHttpFlavorsArray(); $flavor = AkamaiDeliveryUtils::getHDN2ManifestUrl($flavors, $this->params->getMediaProtocol(), $this->getUrl(), '/manifest.f4m', '/z', $params); if (!$flavor) { KalturaLog::info(get_class() . ' failed to find flavor'); return null; } if ($this->getExtraParams()) { $flavor['url'] = kDeliveryUtils::addQueryParameter($flavor['url'], $this->getExtraParams()); } return $flavor; }
protected function doGetFileSyncUrl(FileSync $fileSync) { $url = parent::doGetFileSyncUrl($fileSync); $pattern = $this->getPattern(); if (is_null($pattern)) { $pattern = '{url}'; } return kDeliveryUtils::formatGenericUrl($url, $pattern, $this->params); }
/** * @return kManifestRenderer */ public function serve() { if ($this->params->getManifestFileSync()) { /** @var FileSync $manifestFileSync */ $manifestFileSync = $this->params->getManifestFileSync(); $this->initDeliveryDynamicAttributes($this->params->getManifestFileSync()); if ($manifestFileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_FILE) { // return kaltura urls with serveSmil / serveManifest $partnerPath = myPartnerUtils::getUrlForPartner($manifestFileSync->getPartnerId(), $manifestFileSync->getPartnerId() * 100); $manifestObjectId = $manifestFileSync->getObjectId() . '_' . $manifestFileSync->getObjectSubType() . '_' . $manifestFileSync->getVersion(); $extension = pathinfo($manifestFileSync->getFilePath(), PATHINFO_EXTENSION); $url = $partnerPath . '/serveManifest/objectId/' . $manifestObjectId . '.' . $extension; $url = kDeliveryUtils::formatGenericUrl($url, $this->getPattern(), $this->params); } else { $url = $this->getFileSyncUrl($manifestFileSync, false); } $manifestInfo = $this->getFlavorAssetInfo($url); return $this->getRenderer(array($manifestInfo)); } else { KalturaLog::debug("No manifest file was found"); return null; } }
/** * @param string $url * @param string $baseUrl * @param string $fileExtension * @return string */ public function tokenizeUrl($url, $baseUrl = null, $fileExtension = null) { $url = preg_replace('/([^:])\\/\\//', '$1/', $url); $fullUrl = trim(str_replace('mp4:', '', $url), '/'); if (!is_null($baseUrl)) { $fullUrl = rtrim($baseUrl, '/') . '/' . $fullUrl; } if ($this->includeExtension && $fileExtension == 'flv') { $fullUrl .= ".{$fileExtension}"; } if ($this->window) { $expiry = "{$this->expiryName}=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + $this->window); $url = kDeliveryUtils::addQueryParameter($url, $expiry); $fullUrl = kDeliveryUtils::addQueryParameter($fullUrl, $expiry); } $parsedUrl = parse_url($fullUrl); $pathString = '/' . ltrim($parsedUrl['path'], '/'); if (isset($parsedUrl['query']) && strlen($parsedUrl['query']) > 0) { $pathString .= '?' . $parsedUrl['query']; } $token = substr(self::hmac('sha1', $this->key, $pathString), 0, 20); $url = $url = kDeliveryUtils::addQueryParameter($url, "{$this->name}={$this->gen}" . $token); return $url; }
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); } }
public function finalizeUrls(&$baseUrl, &$flavorsUrls) { if ($this->getDisableExtraAttributes()) { $baseUrl = kDeliveryUtils::addQueryParameter($baseUrl, "attributes=off"); } }
public function checkIsLive($url) { $url = kDeliveryUtils::addQueryParameter($url, "hdcore=" . kConf::get('hd_core_version')); return parent::checkIsLive($url); }
/** * Fetch the manifest and build all flavors array * @param string $url */ private function buildM3u8Flavors($url, array &$flavors) { if ($this->getDisableExtraAttributes()) { $url = kDeliveryUtils::addQueryParameter($url, "attributes=off"); } $manifest = KCurlWrapper::getContent($url); if (!$manifest) { return; } $this->finalizeUrls($url, $flavors); $manifestLines = explode("\n", $manifest); $manifestLine = reset($manifestLines); while ($manifestLine) { $lineParts = explode(':', $manifestLine, 2); if ($lineParts[0] === '#EXT-X-STREAM-INF') { // passing the url as urlPrefix so that only the path will be tokenized $flavor = array('url' => '', 'urlPrefix' => requestUtils::resolve(next($manifestLines), $url), 'ext' => 'm3u8'); $attributes = explode(',', $lineParts[1]); foreach ($attributes as $attribute) { $attributeParts = explode('=', $attribute, 2); switch ($attributeParts[0]) { case 'BANDWIDTH': $flavor['bitrate'] = $attributeParts[1] / 1024; break; case 'RESOLUTION': list($flavor['width'], $flavor['height']) = explode('x', $attributeParts[1], 2); break; } } $flavors[] = $flavor; } $manifestLine = next($manifestLines); } }