#PHP

Media RSS 대충(?) 파싱

프로필

2010. 12. 27. 18:22

이웃추가

위키피디아에 정의된 Media RSS 란?

 

Media RSS (MRSS) is an RSS extension used for syndicating multimedia files (audio, video, image) in RSS feeds. It was designed in 2004 by Yahoo! and the Media RSS community, and adds several enhancements to RSS enclosures. One example of enhancements is specification of thumbnails for each media enclosure.

Media RSS is used by content publishers to feed media files into Yahoo! Video Search, which is a feature of Yahoo! Search that allows to search for video files. The format can be used for podcasting, which uses the RSS format as a means of delivering content to media-playing devices. Media RSS allows for a much more detailed description of the content to be delivered to the subscriber than is covered by the RSS standard.

 

플리커에서 제공해주는 RSS를 통해서, 업데이트 된 이미지를 가져 오고자 함.

 

 

 

대충.... 아래 박스와 같은 xml 포맷임.

<item></item> 안에, 하나의 이미지나 동영상 정보가 들어 있음.

 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
      xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
          <title>Feed title</title>
          <description>Feed Description</description>
          <link>http://www.example_url.com</link>
          <item>
               <title>Picture A</title>
               <media:description> This one's my favorite.</media:description>
               <link>pl_images/A.jpg</link>
               <media:thumbnail url="http://example.com/pl_thumbs/A.jpg"/>
               <media:content url="http://example.com/pl_images/A.jpg"/>
          </item>
          <item>
              <title>Video B</title>
              <link>http://example.com/pl_images/B.jpg</link>
              <media:thumbnail url="http://example.com/pl_thumbs/B.jpg"/>
              <media:content type="video/x-flv"
              url="http://example.com/pl_images/B.flv"/>
          </item>
      </channel>
      </rss>

 

아래 빨간 색인 부분에 가져 오고 싶은 element 명을 써 주면 됨....

내가 원하는 element는 "pubDate", "media:description", "media:title", 이고

media:thumbnail등과 같은 element는 attribute의 정보까지 읽어 오고자 했음~~

 

어쩌거 저쩌고 잘 쓰면 될것 같아요......ㅎㅎㅎ

 

<?php
include 'dbinfo.inc';


$items = array();
$i = 0;
$xmlReader = new XMLReader();

$xmlReader->open("rss주소", null, LIBXML_NOBLANKS);

$isParserActive = false;

$simpleNodeTypes = array("pubDate", "media:description", "media:title");

while ($xmlReader->read()) {
 
    $nodeType = $xmlReader->nodeType;
 
 if ($nodeType != XMLReader::ELEMENT && $nodeType != XMLReader::END_ELEMENT) {       
  continue;    
 }    
 else if ($xmlReader->name == "item")    
 {        
  if (($nodeType == XMLReader::END_ELEMENT) && $isParserActive){
    $i++;        
  }
          
  $isParserActive = ($nodeType != XMLReader::END_ELEMENT);   
  
 }     
 if (!$isParserActive || $nodeType == XMLReader::END_ELEMENT){        
   continue;    
 }     
  
 $name = $xmlReader->name;     
 if (in_array ($name, $simpleNodeTypes))    
 {         // Skip to the text node        
  $xmlReader->read ();
  $value = $xmlReader->value;
  $items[$i][$name] = $value;
      
 }  else if ($name == "media:thumbnail")     {
  $items[$i]['thumbnail_url'] = $xmlReader->getAttribute("url");
                  
 } else if ($name == "media:content")     {
          
  $items[$i]['content_url']  =    $xmlReader->getAttribute("url");        
  $items[$i]['type'] = $xmlReader->getAttribute("type");
         
 } else if ($name == "media:category")     {        
  $xmlReader->read (); 
  $items[$i]['tag'] = $xmlReader->value;  
 }

    
?>

 

GamZehYaavor
GamZehYaavor

이것또한지나가리라.