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)
21 str = URI.escape(rawstr) << ";site=aka"
28 resp = @bot.httputil.get_response("http://us.imdb.com/find?q=#{str}",
32 warning e.backtrace.join("\n")
37 m = /<a href="(\/(?:title|name)\/(?:tt|nm)[0-9]+\/?)[^"]*"(?:[^>]*)>(?:[^<]*)<\/a>/.match(resp.body)
42 elsif resp.code == "302"
43 new_loc = resp['location'].gsub(/http:\/\/us.imdb.com/, "")
44 if new_loc.match(/\/find\?q=(.*)/)
47 return new_loc.gsub(/\?.*/, "")
56 debug "IMDB: search returned NIL"
59 type = sr.match(/^\/([^\/]+)\//)[1].downcase.intern rescue nil
70 def grab_info(info, body)
71 /<div class="info">\s+<h5>#{info}:<\/h5>\s+(.*?)<\/div>/mi.match(body)[1] rescue nil
77 resp = @bot.httputil.get_response('http://us.imdb.com' + sr,
81 warning e.backtrace.join("\n")
86 m = /<title>([^<]*)<\/title>/.match(resp.body)
88 title = Utils.decode_html_entities(m[1])
90 m = /<b>([0-9.]+)\/10<\/b>\n?\r?\s+<small>\(<a href="ratings">([0-9,]+) votes?<\/a>\)<\/small>/.match(resp.body)
96 data = grab_info(/Plot (?:Outline|Summary)/, resp.body)
98 plot = "Plot: #{data.ircify_html.gsub(/\s+more$/,'')}"
102 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
105 info = "#{title} : http://us.imdb.com#{sr}\n"
106 info << "Ratings: #{score}/10 (#{votes} voters). Genre: #{genre.join('/')}\n"
116 resp = @bot.httputil.get_response('http://us.imdb.com' + sr,
118 rescue Exception => e
120 warning e.backtrace.join("\n")
124 if resp.code == "200"
125 m = /<title>([^<]*)<\/title>/.match(resp.body)
127 name = Utils.decode_html_entities(m[1])
130 data = grab_info("Date of Birth", resp.body)
132 birth = "Birth: #{data.ircify_html.gsub(/\s+more$/,'')}"
136 data = grab_info("Date of Death", resp.body)
138 death = "Death: #{data.ircify_html.gsub(/\s+more$/,'')}"
145 filmorate = @bot.httputil.get("http://us.imdb.com" + sr + "filmorate")
150 filmorate.scan(/<div class="filmo">.*?<a href="\/title.*?<\/div>/m) { |str|
151 what = str.match(/<a name="[^"]+">([^<]+)<\/a>/)[1] rescue nil
153 next unless ['Actor', 'Director'].include?(what)
154 movies[what] = str.scan(/<a href="\/title\/[^"]+">([^<]+)<\/a>/)[0..2].map { |tit|
155 Utils.decode_html_entities(tit)
161 info = "#{name} : http://us.imdb.com#{sr}\n"
162 info << [birth, death].compact.join('. ') << "\n"
164 info << "Top Movies:: "
166 movies.keys.sort.each { |key|
168 ar.last << ": " + movies[key].join(', ')
170 info << ar.join('. ')
179 class ImdbPlugin < Plugin
180 def help(plugin, topic="")
181 "imdb <string> => search http://www.imdb.org for <string>"
185 what = params[:what].to_s
189 m.reply "Nothing found for #{what}"
196 plugin = ImdbPlugin.new
197 plugin.map "imdb *what"