]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rss.rb
url plugin: customizable max amount of data to retrieve to look for a title. return...
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rss.rb
index 3dc343955bb3152902ce90dd075cd15b7d4de0ef..f85ccc13327672aab429e325792c7fd8a414ddb7 100644 (file)
@@ -1,23 +1,32 @@
 #-- vim:sw=2:et\r
 #++\r
 #\r
-# RSS feed plugin for RubyBot\r
-# (c) 2004 Stanislav Karchebny <berkus@madfire.net>\r
-# (c) 2005 Ian Monroe <ian@monroe.nu>\r
-# (c) 2005 Mark Kretschmann <markey@web.de>\r
-# (c) 2006 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\r
+# :title: RSS feed plugin for rbot\r
 #\r
-# Licensed under MIT License.\r
-\r
-require 'rss/parser'\r
-require 'rss/1.0'\r
-require 'rss/2.0'\r
-require 'rss/dublincore'\r
-# begin\r
-#   require 'rss/dublincore/2.0'\r
-# rescue\r
-#   warning "Unable to load RSS libraries, RSS plugin functionality crippled"\r
-# end\r
+# Author:: Stanislav Karchebny <berkus@madfire.net>\r
+# Author:: Ian Monroe <ian@monroe.nu>\r
+# Author:: Mark Kretschmann <markey@web.de>\r
+# Author:: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\r
+#\r
+# Copyright:: (C) 2004 Stanislav Karchebny\r
+# Copyright:: (C) 2005 Ian Monroe, Mark Kretschmann\r
+# Copyright:: (C) 2006-2007 Giuseppe Bilotta\r
+#\r
+# License:: MIT license\r
+\r
+# require 'rss/parser'\r
+# require 'rss/1.0'\r
+# require 'rss/2.0'\r
+# require 'rss/dublincore'\r
+# # begin\r
+# #   require 'rss/dublincore/2.0'\r
+# # rescue\r
+# #   warning "Unable to load RSS libraries, RSS plugin functionality crippled"\r
+# # end\r
+#\r
+# GB: Let's just go for the simple stuff:\r
+#\r
+require 'rss'\r
 \r
 class ::RssBlob\r
   attr_accessor :url\r
@@ -48,11 +57,13 @@ class ::RssBlob
   end\r
 \r
   def dup\r
-    self.class.new(@url,\r
-                   @handle,\r
-                   @type ? @type.dup : nil,\r
-                   @watchers.dup,\r
-                   @xml ? @xml.dup : nil)\r
+    @mutex.synchronize do\r
+      self.class.new(@url,\r
+                     @handle,\r
+                     @type ? @type.dup : nil,\r
+                     @watchers.dup,\r
+                     @xml ? @xml.dup : nil)\r
+    end\r
   end\r
 \r
   # Downcase all watchers, possibly turning them into Strings if they weren't\r
@@ -76,12 +87,16 @@ class ::RssBlob
     if watched_by?(who)\r
       return nil\r
     end\r
-    @watchers << who.downcase\r
+    @mutex.synchronize do\r
+      @watchers << who.downcase\r
+    end\r
     return who\r
   end\r
 \r
   def rm_watch(who)\r
-    @watchers.delete(who.downcase)\r
+    @mutex.synchronize do\r
+      @watchers.delete(who.downcase)\r
+    end\r
   end\r
 \r
   def to_a\r
@@ -146,12 +161,7 @@ class RSSFeedsPlugin < Plugin
   def save\r
     unparsed = Hash.new()\r
     @feeds.each { |k, f|\r
-      f.mutex.synchronize do\r
-        unparsed[k] = f.dup\r
-      end\r
-    }\r
-    unparsed.each { |k, f|\r
-      debug f.inspect\r
+      unparsed[k] = f.dup\r
     }\r
     @registry[:feeds] = unparsed\r
   end\r
@@ -614,6 +624,11 @@ class RSSFeedsPlugin < Plugin
       report_problem("reading feed #{feed} failed", nil, m)\r
       return nil\r
     end\r
+    # Ok, 0.9 feeds are not supported, maybe because\r
+    # Netscape happily removed the DTD. So what we do is just to\r
+    # reassign the 0.9 RDFs to 1.0, and hope it goes right.\r
+    xml.gsub!("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\"",\r
+              "xmlns=\"http://purl.org/rss/1.0/\"")\r
     feed.mutex.synchronize do\r
       feed.xml = xml\r
     end\r
@@ -627,11 +642,12 @@ class RSSFeedsPlugin < Plugin
       begin\r
         ## do validate parse\r
         rss = RSS::Parser.parse(xml)\r
-        debug "parsed #{feed}"\r
+        debug "parsed and validated #{feed}"\r
       rescue RSS::InvalidRSSError\r
         ## do non validate parse for invalid RSS 1.0\r
         begin\r
           rss = RSS::Parser.parse(xml, false)\r
+          debug "parsed but not validated #{feed}"\r
         rescue RSS::Error => e\r
           report_problem("parsing rss stream failed, whoops =(", e, m)\r
           return nil\r