4 # :title: IMDB plugin for rbot
6 # Author:: Arnaud Cornet <arnaud.cornet@gmail.com>
7 # Copyright:: (C) 2005 Arnaud Cornet
8 # License:: MIT license
20 str = URI.escape(rawstr)
21 @http = @bot.httputil.get_proxy(URI.parse("http://us.imdb.com/find?q=#{str}"))
24 resp, data = @http.get("/find?q=#{str}", "User-Agent" => "Mozilla/5.0")
25 rescue Net::ProtoRetriableError => detail
27 if head.code == "301" or head.code == "302"
28 return head['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
32 m = /<a href="(\/title\/tt[0-9]+\/?)[^"]*"(:?[^>]*)>([^<]*)<\/a>/.match(resp.body)
38 elsif resp.code == "302"
39 return resp['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
47 debug "IMDB: search returned NIL"
50 resp, data = @http.get(sr, "User-Agent" =>
51 "Mozilla/5.0 (compatible; Konqueror/3.1; Linux)")
53 m = /<title>([^<]*)<\/title>/.match(resp.body)
55 title = CGI.unescapeHTML(m[1])
57 m = /<b>([0-9.]+)\/10<\/b> \(([0-9,]+) votes?\)/.match(resp.body)
63 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
66 return ["http://us.imdb.com" + sr, title, score, votes,
73 class ImdbPlugin < Plugin
74 def help(plugin, topic="")
75 "imdb <string> => search http://www.imdb.org for <string>"
79 what = params[:what].to_s
83 m.reply "Nothing found for #{what}"
86 m.reply "#{info[1]} : #{info[0]}"
87 m.reply "Ratings: #{info[2]}/10 (#{info[3]} voters). Genre: #{info[4].join('/')}"
91 plugin = ImdbPlugin.new
92 plugin.map "imdb *what"