How to get videos from rss feed entries

454 Views Asked by At

I am trying to get videos(urls) from feed entry url.

I am using Feedjira and MetaInspector in my application to fetch and store articles along with images. Now I want to store videos of articles if any. Can anyone please tell me what could be the best possible ways to store videos from articles

Thank you.

1

There are 1 best solutions below

9
On

I do this in my project to save all the url found from rss feeds

Source.all.each do |source|
  feed = Feedjira::Feed.fetch_and_parse(source.url)
  feed.entries.each do |entry|
    unless Link.exists? url: entry.url
      Link.create!(title: entry.title,
        url: entry.url)
    end
  end
end

in my snippet, I only save the url and title, for videos you just need to add entry.video,

you can see all the entry tag from feed.entries object or from the rss given.

and If you want to add another attributes, ex: media:thumbnail you could add this code before calling fetch_and_parse but you need to call it once not everytime you call fetch_and_parse to avoid memory leak

Feedjira::Feed.add_common_feed_entry_element("media:thumbnail", :value => :url, :as => :pic)

then you could do entry.pic to get the thumbnail url