Ejemplo n.º 1
0
 private function parseMediaContent(&$item)
 {
     switch ($this->reader->getAttribute('medium')) {
         // <media:content bitrate="1800.0" duration="3475" expression="full" height="144" lang="sv" type="video/3gpp" width="176" medium="video" url="rtsp://www...3gp">
         case 'video':
             $mime = $this->reader->getAttribute('type');
             if ($mime == 'application/vnd.apple.mpegurl') {
                 // http url with a m3u playlist, possibly containing more m3u playlists
                 $m3u = new M3uReader($this->reader->getAttribute('url'));
                 //throw new \Exception ('xxxxxxx apple stuff');
                 foreach ($m3u->getItems() as $m) {
                     if (file_suffix($m->getUrl()) == '.m3u8') {
                         // pl points to another playlist
                         $m3u2 = new M3uReader($m->getUrl());
                         //                        d ( $m3u2->getItems() );
                         $item->addMediaItems($m3u2->getItems());
                     }
                 }
                 return;
             }
             $media = new VideoResource();
             $media->setUrl($this->reader->getAttribute('url'));
             $media->setDuration($this->reader->getAttribute('duration'));
             $media->video_height = $this->reader->getAttribute('height');
             $media->video_width = $this->reader->getAttribute('width');
             $media->mimetype = $mime;
             $media->bitrate = $this->reader->getAttribute('bitrate');
             break;
             // <media:content height="576" type="image/jpeg" width="720" medium="image" url="http://www....jpg" />
         // <media:content height="576" type="image/jpeg" width="720" medium="image" url="http://www....jpg" />
         case 'image':
             $media = new ImageResource();
             $media->setUrl($this->reader->getAttribute('url'));
             $media->width = $this->reader->getAttribute('width');
             $media->height = $this->reader->getAttribute('height');
             break;
         default:
             throw new \Exception('unhandled medium type ' . $this->reader->getAttribute('medium'));
     }
     while ($this->reader->read()) {
         if ($this->reader->nodeType == XMLReader::END_ELEMENT && $this->reader->name == 'media:content') {
             //                d($media);
             $item->addMedia($media);
             return;
         }
         if ($this->reader->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         $key = strtolower($this->reader->name);
         switch ($key) {
             // <media:player url="http://svtplay.se/v/2191821/uppdrag_granskning/del_7_av_16_kapade_natverk" />
             case 'media:player':
                 break;
                 // <media:title>Uppdrag granskning - Del 7 av 16: Kapade nätverk</media:title>
             // <media:title>Uppdrag granskning - Del 7 av 16: Kapade nätverk</media:title>
             case 'media:title':
                 $title = $this->reader->readValue();
                 //XXXX never used!
                 break;
             default:
                 //echo 'unknown item entry ' .$this->reader->name.ln();
                 break;
         }
     }
     $item->addMedia($media);
 }
Ejemplo n.º 2
0
 function parse($data)
 {
     if (is_url($data)) {
         $u = new HttpClient($data);
         $u->setCacheTime(60 * 60);
         //1h
         $data = $u->getBody();
         //FIXME check http client return code for 404
         if (substr($data, 0, 5) != '<asx ') {
             dp('input_asx->parse FAIL: cant parse playlist from ' . $u->getUrl());
             return false;
         }
     }
     $reader = new XMLReader();
     if ($this->getDebug()) {
         echo 'Parsing ASX: ' . $data . ln();
     }
     $reader->xml($data);
     $item = new VideoResource();
     while ($reader->read()) {
         if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'asx') {
             $this->items[] = $item;
             $item = new VideoResource();
         }
         if ($reader->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         switch ($reader->name) {
             case 'asx':
                 if ($reader->getAttribute('version') != '3.0') {
                     die('XXX FIXME unsupported ASX version ' . $reader->getAttribute('version'));
                 }
                 break;
             case 'entry':
                 while ($reader->read()) {
                     if ($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'entry') {
                         break;
                     }
                     if ($reader->nodeType != XMLReader::ELEMENT) {
                         continue;
                     }
                     switch ($reader->name) {
                         case 'author':
                             break;
                             //<author>svt.se</author>
                         //<author>svt.se</author>
                         case 'copyright':
                             break;
                             //<copyright>Sveriges Television AB 2009</copyright>
                         //<copyright>Sveriges Television AB 2009</copyright>
                         case 'starttime':
                             break;
                             //<starttime value="00:00:00.00"/>
                         //<starttime value="00:00:00.00"/>
                         case 'ref':
                             //<ref href="mms://wm0.c90901.cdn.qbrick.com/90901/kluster/20091026/aekonomi920.wmv"/>
                             $item->setUrl($reader->getAttribute('href'));
                             break;
                         case 'duration':
                             //<duration value="00:03:39.00"/>
                             $item->setDuration($reader->getAttribute('value'));
                             break;
                         default:
                             echo "bad entry " . $reader->name . ln();
                     }
                 }
                 break;
             default:
                 echo "unknown " . $reader->name . ln();
                 break;
         }
     }
     $reader->close();
     return true;
 }
Ejemplo n.º 3
0
 function parse($data)
 {
     $base_url = '';
     if (is_url($data)) {
         //d($data);
         $http = new HttpClient($data);
         $http->setCacheTime(60 * 60);
         //1h
         $data = $http->getBody();
         if (strpos($data, '#EXTM3U') === false) {
             throw new \Exception('M3uReader->parse FAIL: cant parse feed from ' . $http->getUrl());
             return false;
         }
         $base_url = dirname($http->getUrl());
     }
     $this->items = array();
     $rows = explode("\n", $data);
     $ent = new VideoResource();
     //echo '<pre>';
     foreach ($rows as $row) {
         $row = trim($row);
         $p = explode(':', $row, 2);
         switch ($p[0]) {
             case '#EXTM3U':
             case '':
                 break;
                 /*
                 #EXT-X-VERSION:2
                 #EXT-X-ALLOW-CACHE:YES
                 #EXT-X-TARGETDURATION:10
                 #EXT-X-MEDIA-SEQUENCE:0
                 */
             /*
             #EXT-X-VERSION:2
             #EXT-X-ALLOW-CACHE:YES
             #EXT-X-TARGETDURATION:10
             #EXT-X-MEDIA-SEQUENCE:0
             */
             case '#EXTINF':
                 $x = explode(',', $p[1], 2);
                 $ent->setDuration($x[0] != '-1' ? $x[0] : '');
                 $ent->setTitle($x[1]);
                 break;
                 // multiple quality streams for same media can exist
             // multiple quality streams for same media can exist
             case '#EXT-X-STREAM-INF':
                 // #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=294332
                 $x = explode(',', $p[1]);
                 foreach ($x as $kv) {
                     $x2 = explode('=', trim($kv), 2);
                     if ($x2[0] == 'PROGRAM-ID') {
                         $ent->track_id = $x2[1];
                     }
                     if ($x2[0] == 'BANDWIDTH') {
                         // XXX BITRATE???
                         $ent->bitrate = $x2[1];
                     }
                 }
                 break;
             default:
                 if (substr($row, 0, 1) == '#') {
                     break;
                 }
                 if ($base_url && strpos($row, '://') === false) {
                     $row = $base_url . '/' . $row;
                 }
                 $ent->setUrl($row);
                 $this->items[] = $ent;
                 $ent = new VideoResource();
                 break;
         }
     }
 }