lib/feedbag.rb in feedbagtoo-0.7.3 vs lib/feedbag.rb in feedbagtoo-0.7.4
- old
+ new
@@ -91,11 +91,11 @@
rescue => ex
$stderr.puts "#{ex.class} error ocurred with: `#{url}': #{ex.message}"
end
begin
- Timeout::timeout(15) do
+ Timeout::timeout(20) do
html = open(url) do |f|
content_type = f.content_type.downcase
if content_type == "application/octet-stream" # open failed
content_type = f.meta["content-type"].gsub(/;.*$/, '')
end
@@ -138,20 +138,20 @@
end
(doc/"a").each do |a|
next unless a["href"]
if self.looks_like_feed?(a["href"]) and (a["href"] =~ /\// or a["href"] =~ /#{url_uri.host}/)
- title = a["title"] || a.innerText || a['alt'] || title
- self.add_feed(a["href"], url, $base_uri, title, description || title)
+ calculated_title = self.title_for_anchor(a, title)
+ self.add_feed(a["href"], url, $base_uri, calculated_title, description || calculated_title)
end
end
(doc/"a").each do |a|
next unless a["href"]
if self.looks_like_feed?(a["href"])
- title = a["title"] || a.innerText || a['alt'] || title
- self.add_feed(a["href"], url, $base_uri, title, description || title)
+ calculated_title = self.title_for_anchor(a, title)
+ self.add_feed(a["href"], url, $base_uri, calculated_title, description || calculated_title)
end
end
# Added support for feeds like http://tabtimes.com/tbfeed/mashable/full.xml
if url.match(/.xml$/) and doc.root and doc.root["xml:base"] and doc.root["xml:base"].strip == url.strip
@@ -171,13 +171,23 @@
return $feeds
end
end
def self.looks_like_feed?(url)
+ return false unless url[0...4] == 'http'
if url =~ /((\.|\/)(rdf|xml|rdf|rss)$|feed=(rss|atom)|(atom|feed)\/?$)/i
true
else
false
+ end
+ end
+
+ def self.title_for_anchor(a, title)
+ t = a["title"] || a.innerText || a['alt']
+ if(t && t.length > 0)
+ t
+ else
+ title
end
end
def self.add_feed(feed_url, orig_url, base_uri = nil, title = "", description = "")
# puts "#{feed_url} - #{orig_url}"