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)
24 @http = @bot.httputil.get_proxy(URI.parse("http://us.imdb.com/find?q=#{str}"))
27 resp, data = @http.get("/find?q=#{str}", @bot.httputil.headers)
28 rescue Net::ProtoRetriableError => detail
30 if head.code == "301" or head.code == "302"
31 return head['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
35 m = /<a href="(\/title\/tt[0-9]+\/?)[^"]*"(?:[^>]*)>([^<]*)<\/a>/.match(resp.body)
41 elsif resp.code == "302"
42 return resp['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "")
50 debug "IMDB: search returned NIL"
53 resp, data = @http.get(sr, @bot.httputil.headers)
55 m = /<title>([^<]*)<\/title>/.match(resp.body)
57 title = CGI.unescapeHTML(m[1])
59 m = /<b>([0-9.]+)\/10<\/b>\n?\r?\s+<small>\(<a href="ratings">([0-9,]+) votes?<\/a>\)<\/small>/.match(resp.body)
65 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
68 return ["http://us.imdb.com" + sr, title, score, votes,
75 class ImdbPlugin < Plugin
76 def help(plugin, topic="")
77 "imdb <string> => search http://www.imdb.org for <string>"
81 what = params[:what].to_s
85 m.reply "Nothing found for #{what}"
88 m.reply "#{info[1]} : #{info[0]}"
89 m.reply "Ratings: #{info[2]}/10 (#{info[3]} voters). Genre: #{info[4].join('/')}"
93 plugin = ImdbPlugin.new
94 plugin.map "imdb *what"