Exemplo n.º 1
0
 public function checkIsLive($url)
 {
     $content = $this->urlExists($url, array('application/dash+xml'));
     if (!$content) {
         return false;
     }
     $mediaUrls = $this->getDashUrls($content);
     foreach ($mediaUrls as $mediaUrl) {
         $mediaUrl = requestUtils::resolve($mediaUrl, $url);
         if ($this->urlExists($mediaUrl, array('audio/mp4', 'video/mp4'), '0-1') !== false) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
 /**
  * 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);
     }
 }