Feed thumbnails with Feedzirra

559 Views Asked by At

I'm using Feedzirra to update RSS feeds. I am currently getting thumbnails for individual entries like this.

Feedzirra::Feed.add_common_feed_entry_element("media:thumbnail",:value => :url, :as => :thumbnail)
feed = Feedzirra::Feed.fetch_and_parse("http://somefeed")
entry = feed.entries.first.thumbnail

That works great, but I also want to get the thumbnail of the website each entry is coming from (the icon displayed in the browser next to the URL, usually the company logo). What is the best way to do this?

1

There are 1 best solutions below

0
On

I usually use the favicon.ico (16x16) for the host name of the feed URL. You can stretch it to 24x24 without it looking too awful.

def get_fav_icon_url
    "http://" + get_host + "/favicon.ico"
end

def get_host
    url = self.url
    url = "http://#{url}" unless url.start_with?('http')
    uri = URI.parse(url)
    uri.host.downcase
end