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)
26 resp = @bot.httputil.get_response("http://us.imdb.com/find?q=#{str}",
30 warning e.backtrace.join("\n")
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"
55 resp = @bot.httputil.get_response('http://us.imdb.com' + sr,
59 warning e.backtrace.join("\n")
64 m = /<title>([^<]*)<\/title>/.match(resp.body)
66 title = CGI.unescapeHTML(m[1])
68 m = /<b>([0-9.]+)\/10<\/b>\n?\r?\s+<small>\(<a href="ratings">([0-9,]+) votes?<\/a>\)<\/small>/.match(resp.body)
74 resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr|
77 return ["http://us.imdb.com" + sr, title, score, votes,
84 class ImdbPlugin < Plugin
85 def help(plugin, topic="")
86 "imdb <string> => search http://www.imdb.org for <string>"
90 what = params[:what].to_s
94 m.reply "Nothing found for #{what}"
97 m.reply "#{info[1]} : #{info[0]}"
98 m.reply "Ratings: #{info[2]}/10 (#{info[3]} voters). Genre: #{info[4].join('/')}"
102 plugin = ImdbPlugin.new
103 plugin.map "imdb *what"