4 # :title: IMDB plugin for rbot
6 # Author:: Arnaud Cornet <arnaud.cornet@gmail.com>
7 # Copyright:: (C) 2005 Arnaud Cornet
8 # License:: MIT license
10 # Notes by Giuseppe Bilotta:
11 # TODO return more than one match (configurable)
12 # TODO why do we use CGI.unescapeHTML? shall we rely on the rbot methods?
23 str = URI.escape(rawstr) << ";site=aka"
26 resp = @bot.httputil.get_response("http://us.imdb.com/find?q=#{str}",
30 warning e.backtrace.join("\n")
35 m = /<a href="(\/(?:title|name)\/(?:tt|nm)[0-9]+\/?)[^"]*"(?:[^>]*)>(?:[^<]*)<\/a>/.match(resp.body)
40 elsif resp.code == "302"
41 return resp['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
49 debug "IMDB: search returned NIL"
52 type = sr.match(/^\/([^\/]+)\//)[1].downcase.intern rescue nil
63 def grab_info(info, body)
64 /<div class="info">\s+<h5>#{info}:<\/h5>\s+(.*?)<\/div>/mi.match(body)[1] rescue nil
70 resp = @bot.httputil.get_response('http://us.imdb.com' + sr,
74 warning e.backtrace.join("\n")
79 m = /<title>([^<]*)<\/title>/.match(resp.body)
81 title = CGI.unescapeHTML(m[1])
83 m = /<b>([0-9.]+)\/10<\/b>\n?\r?\s+<small>\(<a href="ratings">([0-9,]+) votes?<\/a>\)<\/small>/.match(resp.body)
89 data = grab_info(/Plot (?:Outline|Summary)/, resp.body)
91 plot = "Plot: #{data.ircify_html.gsub(/\s+more$/,'')}"
95 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
98 info = "#{title} : http://us.imdb.com#{sr}\n"
99 info << "Ratings: #{score}/10 (#{votes} voters). Genre: #{genre.join('/')}\n"
109 resp = @bot.httputil.get_response('http://us.imdb.com' + sr,
111 rescue Exception => e
113 warning e.backtrace.join("\n")
117 if resp.code == "200"
118 m = /<title>([^<]*)<\/title>/.match(resp.body)
120 name = CGI.unescapeHTML(m[1])
123 data = grab_info("Date of Birth", resp.body)
125 birth = "Birth: #{data.ircify_html.gsub(/\s+more$/,'')}"
129 data = grab_info("Date of Death", resp.body)
131 death = "Death: #{data.ircify_html.gsub(/\s+more$/,'')}"
135 data = grab_info("Awards", resp.body)
137 awards = "Awards: #{data.ircify_html.gsub(/\s+more$/,'')}"
140 info = "#{name} : http://us.imdb.com#{sr}\n"
141 info << [birth, death].compact.join('. ') << "\n"
142 info << awards if awards
150 class ImdbPlugin < Plugin
151 def help(plugin, topic="")
152 "imdb <string> => search http://www.imdb.org for <string>"
156 what = params[:what].to_s
160 m.reply "Nothing found for #{what}"
167 plugin = ImdbPlugin.new
168 plugin.map "imdb *what"