From 36f1f28e668919dfab75c8fc4d1020abad351bd1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 30 Jan 2009 18:24:34 +0100 Subject: rss plugin: try all RSS parsers Some feeds fail when parsed by some parsers, but work correctly with others (e.g. http://www.blueman.com/community/rss fails with xmlparser but not with REXML). So try all of them and only abort if none works rather than failing because the default parser fails. --- data/rbot/plugins/rss.rb | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb index 87f79ec5..981eb4f8 100644 --- a/data/rbot/plugins/rss.rb +++ b/data/rbot/plugins/rss.rb @@ -1134,25 +1134,32 @@ class RSSFeedsPlugin < Plugin return nil unless feed.xml feed.mutex.synchronize do xml = feed.xml - begin - ## do validate parse - rss = RSS::Parser.parse(xml) - debug "parsed and validated #{feed}" - rescue RSS::InvalidRSSError - ## do non validate parse for invalid RSS 1.0 + rss = nil + errors = [] + RSS::AVAILABLE_PARSERS.each do |parser| begin - rss = RSS::Parser.parse(xml, false) - debug "parsed but not validated #{feed}" + ## do validate parse + rss = RSS::Parser.parse(xml, true, true, parser) + debug "parsed and validated #{feed} with #{parser}" + break + rescue RSS::InvalidRSSError + begin + ## do non validate parse for invalid RSS 1.0 + rss = RSS::Parser.parse(xml, false, true, parser) + debug "parsed but not validated #{feed} with #{parser}" + break + rescue RSS::Error => e + errors << [parser, e, "parsing rss stream failed, whoops =("] + end rescue RSS::Error => e - report_problem("parsing rss stream failed, whoops =(", e, m) - return nil + errors << [parser, e, "parsing rss stream failed, oioi"] + rescue => e + errors << [parser, e, "processing error occured, sorry =("] end - rescue RSS::Error => e - report_problem("parsing rss stream failed, oioi", e, m) - return nil - rescue => e - report_problem("processing error occured, sorry =(", e, m) - return nil + end + debug errors unless errors.empty? + if !rss + self.send(:report_problem, errors.last[2], errors.last[1], m) end items = [] if rss.nil? -- cgit v1.2.3