]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
imdb plugin: imdb_filter for titles
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 19 Mar 2008 00:37:27 +0000 (01:37 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 19 Mar 2008 13:49:49 +0000 (14:49 +0100)
data/rbot/plugins/imdb.rb

index 82afd94a0de4a89a16e62af0998d5f0ad74c4f91..94e4e57101290438c5c4c329bf741f650d62bd7e 100644 (file)
@@ -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