Exemplo n.º 1
0
 private function parseEntry()
 {
     $item = new NewsItem();
     while ($this->reader->read()) {
         if ($this->reader->nodeType == \XMLReader::END_ELEMENT && $this->reader->name == 'entry') {
             if ($item->title == $item->desc) {
                 $item->desc = '';
             }
             $this->items[] = $item;
             return;
         }
         if ($this->reader->nodeType != \XMLReader::ELEMENT) {
             continue;
         }
         switch (strtolower($this->reader->name)) {
             case 'title':
                 $this->reader->read();
                 $item->title = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'summary':
                 $this->reader->read();
                 $item->desc = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'content':
                 $this->reader->read();
                 $item->body = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'updated':
                 $this->reader->read();
                 $item->setTimestamp($this->reader->value);
                 break;
             case 'name':
                 ///XXX :hack to avoid 2-level parsing of <author><name>Sveriges Radio</name></author>
                 $this->reader->read();
                 $item->author = html_entity_decode($this->reader->value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'id':
                 $this->reader->read();
                 $item->guid = $this->reader->value;
                 break;
             case 'link':
                 switch ($this->reader->getAttribute('rel')) {
                     case 'alternate':
                         $item->setUrl($this->reader->getAttribute('href'));
                         break;
                     case 'enclosure':
                         switch ($this->reader->getAttribute('type')) {
                             case 'video/x-flv':
                             case 'video/quicktime':
                                 $item->video_url = $this->reader->getAttribute('href');
                                 $item->video_mime = $this->reader->getAttribute('type');
                                 if ($this->reader->getAttribute('length')) {
                                     $this->duration = $this->reader->getAttribute('length');
                                 }
                                 break;
                             case 'image/jpeg':
                                 $item->image_url = $this->reader->getAttribute('href');
                                 $item->image_mime = $this->reader->getAttribute('type');
                                 break;
                             default:
                                 throw new \Exception('unknown enclosure mime: ' . $this->reader->getAttribute('type'));
                         }
                         break;
                     case 'image':
                         switch ($this->reader->getAttribute('type')) {
                             case 'image/png':
                                 $img = new ImageResource();
                                 $img->setUrl($this->reader->getAttribute('href'));
                                 $img->setMimetype($this->reader->getAttribute('type'));
                                 $item->addMedia($img);
                                 break;
                             default:
                                 throw new \Exception('unknown image mime: ' . $this->reader->getAttribute('type'));
                         }
                         break;
                     case 'replies':
                         //FIXME: handle
                         break;
                     case 'edit':
                         //XXX ???
                     //XXX ???
                     case 'self':
                         //XXX ???
                     //XXX ???
                     case '':
                         // no "rel" attribute exists
                         break;
                     default:
                         d($item);
                         throw new \Exception('unknown link type: ' . $this->reader->getAttribute('rel'));
                 }
                 break;
             default:
                 // echo 'unknown entry entry: '.$this->reader->name.ln();
                 break;
         }
     }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  */
 function getAlbumCovers($artist, $album)
 {
     $temp = TempStore::getInstance();
     $key = 'LastFmClient/covers//' . $artist . '/' . $album;
     $data = $temp->get($key);
     if ($data) {
         return unserialize($data);
     }
     $xml = $this->query('album.getInfo', array('artist' => $artist, 'album' => $album, 'lang' => $this->language));
     if (isset($xml->error)) {
         // eg: "Album not found"
         return false;
     }
     $images = array();
     foreach ($xml->album->image as $i) {
         $attrs = $i->attributes();
         $image = new ImageResource();
         $image->type = strval($attrs['size']);
         $image->setUrl(strval($i));
         $images[] = $image;
     }
     $temp->set($key, serialize($images));
     return $images;
 }