1 # IMDB plugin for RubyBot
2 # (c) 2005 Arnaud Cornet <arnaud.cornet@gmail.com>
3 # Licensed under MIT License.
15 str = URI.escape(rawstr)
16 @http = @bot.httputil.get_proxy(URI.parse("http://us.imdb.com/find?q=#{str}"))
19 resp, data = @http.get("/find?q=#{str}", "User-Agent" => "Mozilla/5.0")
20 rescue Net::ProtoRetriableError => detail
22 if head.code == "301" or head.code == "302"
23 return head['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
27 m = /<a href="(\/title\/tt[0-9]+\/?)[^"]*"(:?[^>]*)>([^<]*)<\/a>/.match(resp.body)
33 elsif resp.code == "302"
34 return resp['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
42 debug "IMDB: search returned NIL"
45 resp, data = @http.get(sr, "User-Agent" =>
46 "Mozilla/5.0 (compatible; Konqueror/3.1; Linux)")
48 m = /<title>([^<]*)<\/title>/.match(resp.body)
50 title = CGI.unescapeHTML(m[1])
52 m = /<b>([0-9.]+)\/10<\/b> \(([0-9,]+) votes?\)/.match(resp.body)
58 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
61 return ["http://us.imdb.com" + sr, title, score, votes,
68 class ImdbPlugin < Plugin
69 def help(plugin, topic="")
70 "imdb <string> => search http://www.imdb.org for <string>"
74 unless(m.params && m.params.length > 0)
75 m.reply "incorrect usage: " + help(m.plugin)
80 info = i.info(m.params)
82 m.reply "Nothing found for #{m.params}"
85 m.reply "#{info[1]} : #{info[0]}"
86 m.reply "Ratings: #{info[2]}/10 (#{info[3]} voters). Genre: #{info[4].join('/')}"
90 plugin = ImdbPlugin.new
91 plugin.register("imdb")