/** * Fetch the manifest and build all flavors array * @param string $url */ private function buildF4mFlavors($url, array &$flavors, array &$bootstrapInfos) { $manifest = KCurlWrapper::getContent($url); if (!$manifest) { return; } $manifest = preg_replace('/xmlns="[^"]+"/', '', $manifest); $xml = new SimpleXMLElement($manifest); $mediaElements = $xml->xpath('/manifest/media'); foreach ($mediaElements as $mediaElement) { /* @var $mediaElement SimpleXMLElement */ $flavor = array('urlPrefix' => ''); $playlistUrl = null; foreach ($mediaElement->attributes() as $attr => $attrValue) { $attrValue = "{$attrValue}"; if ($attr === 'url') { $attrValue = requestUtils::resolve($attrValue, $url); } if ($attr === 'bootstrapInfoId') { $bootstrapInfoElements = $xml->xpath("/manifest/bootstrapInfo[@id='{$attrValue}']"); if (count($bootstrapInfoElements)) { $bootstrapInfoElement = reset($bootstrapInfoElements); /* @var $bootstrapInfoElement SimpleXMLElement */ $playlistUrl = requestUtils::resolve(strval($bootstrapInfoElement['url']), $url); } } $flavor["{$attr}"] = $attrValue; } if ($playlistUrl) { $playlistId = md5($playlistUrl); $bootstrapInfo = array('id' => $playlistId, 'url' => $playlistUrl); $bootstrapInfos[$playlistId] = $bootstrapInfo; $flavor['bootstrapInfoId'] = $playlistId; } $flavors[] = $flavor; } }
/** * Validates that the xml is valid using the XSD *@return bool - if the validation is ok */ protected function validate() { if (!file_exists($this->data->filePath)) { throw new KalturaBatchException("File doesn't exist [{$this->data->filePath}]", KalturaBatchJobAppErrors::BULK_FILE_NOT_FOUND); } libxml_use_internal_errors(true); $this->loadXslt(); $xdoc = new KDOMDocument(); $this->xslTransformedContent = $this->xslTransform($this->data->filePath); KalturaLog::info("Tranformed content: " . $this->xslTransformedContent); libxml_clear_errors(); if (!$xdoc->loadXML($this->xslTransformedContent)) { $errorMessage = kXml::getLibXmlErrorDescription($this->xslTransformedContent); KalturaLog::debug("Could not load xml"); throw new KalturaBatchException("Could not load xml [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED); } //Validate the XML file against the schema libxml_clear_errors(); $xsdURL = KBatchBase::$kClient->schema->serve($this->getSchemaType()); if (KBatchBase::$taskConfig->params->xmlSchemaVersion) { $xsdURL .= "&version=" . KBatchBase::$taskConfig->params->xmlSchemaVersion; } $xsd = KCurlWrapper::getContent($xsdURL); if (!$xdoc->schemaValidateSource($xsd)) { $errorMessage = kXml::getLibXmlErrorDescription($this->xslTransformedContent); KalturaLog::debug("XML is invalid:\n{$errorMessage}"); throw new KalturaBatchException("Validate files failed on job [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED); } return true; }
/** * Fetch the manifest and build all flavors array * @param string $url */ private function buildM3u8Flavors($url, array &$flavors) { $this->finalizeUrls($url, $flavors); $manifest = KCurlWrapper::getContent($url); if (!$manifest) { return; } $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); } }