From 7875312e3b5d7042efba931e8aa237be9c5b9313 Mon Sep 17 00:00:00 2001
From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date: Wed, 19 Mar 2008 01:37:27 +0100
Subject: imdb plugin: imdb_filter for titles

---
 data/rbot/plugins/imdb.rb | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

(limited to 'data/rbot/plugins')

diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb
index 82afd94a..94e4e571 100644
--- a/data/rbot/plugins/imdb.rb
+++ b/data/rbot/plugins/imdb.rb
@@ -153,7 +153,7 @@ class Imdb
         country = data.ircify_html.gsub(' / ','/')
       end
 
-      info << [title, "(#{country}, #{date})", extra, dir ? "[#{dir}]" : nil, ": http://us.imdb.com#{sr}"].compact.join(" ")
+      info << [title, "(#{country}, #{date})", extra, dir ? "[#{dir}]" : nil, opts[:nourl] ? nil : ": http://us.imdb.com#{sr}"].compact.join(" ")
 
       return info if opts[:title_only]
 
@@ -405,9 +405,27 @@ class ImdbPlugin < Plugin
 
   attr_reader :i
 
+  TITLE_URL = %r{^http://(?:[^.]+\.)?imdb.com(/title/tt\d+/)}
+  def imdb_filter(s)
+    loc = Utils.check_location(s, TITLE_URL)
+    if loc
+      sr = loc.first.match(TITLE_URL)[1]
+      extra = $2
+      res = i.info_title(sr, :nourl => true, :characters => (extra == 'fullcredits'))
+      debug res
+      if res
+        return {:title => res.first, :content => res.last}
+      else
+        return nil
+      end
+    end
+    return nil
+  end
+
   def initialize
     super
     @i = Imdb.new(@bot)
+    @bot.register_filter(:imdb, :htmlinfo) { |s| imdb_filter(s) }
   end
 
   # Find a person or movie on IMDB. A :type (name/title, default both) can be
-- 
cgit v1.2.3