Problem with media namespace on youtube atom feeds

136 views
Skip to first unread message

mixtli

unread,
Sep 24, 2009, 4:42:40 AM9/24/09
to feedzirra
I'm trying to grab the media tags from youtube playlists. I tried
feedtools as well and had a similar problem. It seems I just can't
pull out those tags no matter what I do.

Here is the relevant code:
Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail", :as
=> :thumbnail)
feed = Feedzirra::Feed.fetch_and_parse("http://gdata.youtube.com/feeds/
api/playlists/189C0DCE90CB6D81?v=2")

puts feed.title
entry = feed.entries.first

puts "TITLE #{entry.title}"
puts "THUMBNAIL: #{entry.thumbnail.inspect}"


entry.thumbnail always comes up nil.

I tried all sorts of things for the xpath. "media:thumbnail", "//
media:thumbnail[1]", and so on. It's enclosed in a <media:group> tag
and I can't get that one either.

Any help would be appreciated. I spent about 3 hours with feedtools
trying to work this out and another couple hours with feedzirra. It
seems like no matter what I do, the parsers seem to completely ignore
everything under media:group, even though I can get other namespaced
tags that come both before and after that one like "yt:location".

Thanks!

Paul Dix

unread,
Sep 24, 2009, 9:02:01 AM9/24/09
to feed...@googlegroups.com
You were on the right track. Here are the commands you'll want to do
to get the properties on the thumbnail element:

Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
:value => :url, :as => :thumbnail)
Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
:value => :height, :as => :thumbnail_height)
Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
:value => :width, :as => :thumbnail_width)

The regular element option says that you want what's inside the angle
brackets. The value option lets you pull out a property on that
element.

Best,
Paul

mixtli

unread,
Sep 24, 2009, 1:37:13 PM9/24/09
to feedzirra
Thank you!

On Sep 24, 9:02 am, Paul Dix <paulc...@gmail.com> wrote:
> You were on the right track. Here are the commands you'll want to do
> to get the properties on the thumbnail element:
>
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :url, :as => :thumbnail)
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :height, :as => :thumbnail_height)
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :width, :as => :thumbnail_width)
>
> The regular element option says that you want what's inside the angle
> brackets. The value option lets you pull out a property on that
> element.
>
> Best,
> Paul
>

Al-Faisal El-Dajani

unread,
Oct 26, 2009, 6:41:36 AM10/26/09
to feedzirra
Thanx for the tip, however, how should I go about this if I have
multiple subentries?

Sample:
<item>
<media:group>
<media:content type="video/mp4" url="http://blip.tv/file/get/
Ajarabic-NewsBulletin25102009192.mp4"></media:content>
<media:content type="audio/mpeg" url="http://blip.tv/file/get/
Ajarabic-NewsBulletin25102009138.mp3"></media:content>
<media:content type="video/x-flv" url="http://blip.tv/file/get/
Ajarabic-NewsBulletin25102009485.flv" width="640"></media:content>
</media:group>
</item>

How can I get all media:content objects in this feed?

On Sep 24, 4:02 pm, Paul Dix <paulc...@gmail.com> wrote:
> You were on the right track. Here are the commands you'll want to do
> to get the properties on the thumbnail element:
>
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :url, :as => :thumbnail)
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :height, :as => :thumbnail_height)
> Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",
> :value => :width, :as => :thumbnail_width)
>
> The regular element option says that you want what's inside the angle
> brackets. The value option lets you pull out a property on that
> element.
>
> Best,
> Paul
>

Al-Faisal El-Dajani

unread,
Oct 26, 2009, 8:37:32 AM10/26/09
to feedzirra
I fixed my problem using the following code snippet:

Feedzirra::Feed.feed_classes.map{|k| eval("#{k}Entry") }.each do |
klass|
klass.send(:elements, 'media:content', :value => :url, :as
=> :media_url)
klass.send(:elements, 'media:content', :value => :type, :as
=> :media_type)
end

This way, the feed object now contains two extra elements, media_url
and media_type. Each is an array that contains the media urls and
media content types respectively.
I think it is safe to assume that elements in respective positions in
this array belong to the same feed object. i.e: media_url[1] and
media_type[1] belong to the same media:content element.

If you have any idea of a better solution, I am open to suggestions.

On Oct 26, 1:41 pm, Al-Faisal El-Dajani <faisal.daj...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages