I've created a function that consumes an RSS feed from Flickr using Zend_Feed. Unfortunately I am struggling to extract some keys!
I can get the < title > and such by echoing
$entry->title();
But how can I echo out something like < media:thumbnail >?
I'm sure there's a completely simple way of doing this but I can't for the life of me figure it out!
Here is an example entry
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/T-Pq6QSeH7A</id>
<published>2009-09-16T11:51:20.000Z</published>
<updated>2009-09-18T02:37:35.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Games' label='Gaming'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='torchlight'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='vanquisher'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mmo'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mmorpg'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='massively'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='multiplayer'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='online'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='game'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mmohub'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='hub'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='forums'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='reviews'/>
<title type='text'>Torchlight - Vanquisher Gameplay</title>
<content type='text'>I'm so excited to reveal the latest trailer for Torchlight, featuring the third class, the Vanquisher!</content>
<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=T-Pq6QSeH7A&feature=youtube_gdata'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/T-Pq6QSeH7A/responses'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/T-Pq6QSeH7A/related'/>
<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=T-Pq6QSeH7A'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/mmolifetv/uploads/T-Pq6QSeH7A'/>
<author>
<name>mmolifetv</name>
<uri>http://gdata.youtube.com/feeds/api/users/mmolifetv</uri>
</author>
<gd:comments>
<gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/T-Pq6QSeH7A/comments' countHint='0'/>
</gd:comments>
<media:group>
<media:category label='Gaming' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Games</media:category>
<media:content url='http://www.youtube.com/v/T-Pq6QSeH7A?f=user_uploads&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefaul开发者_C百科t='true' expression='full' duration='97' yt:format='5'/>
<media:content url='rtsp://rtsp2.youtube.com/CigLENy73wIaHwmwH54E6erjTxMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='97' yt:format='1'/>
<media:content url='rtsp://rtsp2.youtube.com/CigLENy73wIaHwmwH54E6erjTxMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='97' yt:format='6'/>
<media:description type='plain'>I'm so excited to reveal the latest trailer for Torchlight, featuring the third class, the Vanquisher!</media:description>
<media:keywords>torchlight, vanquisher, mmo, mmorpg, massively, multiplayer, online, game, mmohub, hub, forums, reviews</media:keywords>
<media:player url='http://www.youtube.com/watch?v=T-Pq6QSeH7A&feature=youtube_gdata'/>
<media:thumbnail url='http://i.ytimg.com/vi/T-Pq6QSeH7A/2.jpg' height='90' width='120' time='00:00:48.500'/>
<media:thumbnail url='http://i.ytimg.com/vi/T-Pq6QSeH7A/1.jpg' height='90' width='120' time='00:00:24.250'/>
<media:thumbnail url='http://i.ytimg.com/vi/T-Pq6QSeH7A/3.jpg' height='90' width='120' time='00:01:12.750'/>
<media:thumbnail url='http://i.ytimg.com/vi/T-Pq6QSeH7A/0.jpg' height='240' width='320' time='00:00:48.500'/>
<media:title type='plain'>Torchlight - Vanquisher Gameplay</media:title>
<yt:duration seconds='97'/>
</media:group>
<gd:rating average='5.0' max='5' min='1' numRaters='1' rel='http://schemas.google.com/g/2005#overall'/>
<yt:statistics favoriteCount='0' viewCount='24'/>
I would like to extract the first thumbnail url from the entry.
a colon in the key means a namespace is being used. The media one, which will be defined somewhere else in the XML as pointing at a yahoo domain, is a pretty common one to find in RSS. Zend_Feed sometimes takes away the namespace, so did you try $entry->thumbnail()?
Alternatively, I recall that there's a getDom
method that will return you a DOMDocument on which you can use all the built-in NS-matching methods (getElementsByTagNameNS
for example).
Or, take a look at the new Zend_Feed_Reader stuff - it might have support for the media namespace already or writing your own adapter is pretty simple - there's an example in the docs for amazon's inclusion of ISBN in some of their feeds that you'd be able to copy.
$entry->media()->thumbnail()
could work or
$entry->{'media:thumbnail'}
But iam not 100% sure.
I have resolved this by using Zend Gdata YouTube instead, I am still interested how It could be done this way though as I may use Zend_Feed in the future for similar things!
精彩评论