diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/imdb.rb | 77 |
1 files changed, 71 insertions, 6 deletions
diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb index cfadd3c8..2388ed61 100644 --- a/data/rbot/plugins/imdb.rb +++ b/data/rbot/plugins/imdb.rb @@ -32,10 +32,9 @@ class Imdb end if resp.code == "200" - m = /<a href="(\/title\/tt[0-9]+\/?)[^"]*"(?:[^>]*)>([^<]*)<\/a>/.match(resp.body) + m = /<a href="(\/(?:title|name)\/(?:tt|nm)[0-9]+\/?)[^"]*"(?:[^>]*)>(?:[^<]*)<\/a>/.match(resp.body) if m url = m[1] - title = m[2] return url end elsif resp.code == "302" @@ -50,6 +49,22 @@ class Imdb debug "IMDB: search returned NIL" return nil end + type = sr.match(/^\/([^\/]+)\//)[1].downcase.intern rescue nil + case type + when :title + return info_title(sr) + when :name + return info_name(sr) + else + return "#{sr}" + end + end + + def grab_info(info, body) + /<div class="info">\s+<h5>#{info}:<\/h5>\s+(.*?)<\/div>/mi.match(body)[1] rescue nil + end + + def info_title(sr) resp = nil begin resp = @bot.httputil.get_response('http://us.imdb.com' + sr, @@ -70,12 +85,63 @@ class Imdb score = m[1] votes = m[2] + plot = nil + data = grab_info(/Plot (?:Outline|Summary)/, resp.body) + if data + plot = "Plot: #{data.ircify_html.gsub(/\s+more$/,'')}" + end + genre = Array.new resp.body.scan(/<a href="\/Sections\/Genres\/[^\/]+\/">([^<]+)<\/a>/) do |gnr| genre << gnr end - return ["http://us.imdb.com" + sr, title, score, votes, - genre] + info = "#{title} : http://us.imdb.com#{sr}\n" + info << "Ratings: #{score}/10 (#{votes} voters). Genre: #{genre.join('/')}\n" + info << plot if plot + return info + end + return nil + end + + def info_name(sr) + resp = nil + begin + resp = @bot.httputil.get_response('http://us.imdb.com' + sr, + :max_redir => -1) + rescue Exception => e + error e.message + warning e.backtrace.join("\n") + return nil + end + + if resp.code == "200" + m = /<title>([^<]*)<\/title>/.match(resp.body) + return nil if !m + name = CGI.unescapeHTML(m[1]) + + birth = nil + data = grab_info("Date of Birth", resp.body) + if data + birth = "Birth: #{data.ircify_html.gsub(/\s+more$/,'')}" + end + + death = nil + data = grab_info("Date of Death", resp.body) + if data + death = "Death: #{data.ircify_html.gsub(/\s+more$/,'')}" + end + + awards = nil + data = grab_info("Awards", resp.body) + if data + awards = "Awards: #{data.ircify_html.gsub(/\s+more$/,'')}" + end + + info = "#{name} : http://us.imdb.com#{sr}\n" + info << [birth, death].compact.join('. ') << "\n" + info << awards if awards + return info + end return nil end @@ -94,8 +160,7 @@ class ImdbPlugin < Plugin m.reply "Nothing found for #{what}" return nil end - m.reply "#{info[1]} : #{info[0]}" - m.reply "Ratings: #{info[2]}/10 (#{info[3]} voters). Genre: #{info[4].join('/')}" + m.reply info end end |