From: Giuseppe Bilotta Date: Wed, 4 Apr 2007 14:16:24 +0000 (+0000) Subject: imdb plugin: handle double-redirection and other charset-related issues X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=1919256548369eed007f7a4b9ea5358b31f05da6;hp=f955b7187f452323ded7ccd41cf898117e48e391;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git imdb plugin: handle double-redirection and other charset-related issues --- diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb index fc4dc1e6..d8d4dad8 100644 --- a/data/rbot/plugins/imdb.rb +++ b/data/rbot/plugins/imdb.rb @@ -9,9 +9,7 @@ # # Notes by Giuseppe Bilotta: # TODO return more than one match (configurable) -# TODO why do we use CGI.unescapeHTML? shall we rely on the rbot methods? -require 'cgi' require 'uri/common' class Imdb @@ -21,6 +19,10 @@ class Imdb def search(rawstr) str = URI.escape(rawstr) << ";site=aka" + return do_search(str) + end + + def do_search(str) resp = nil begin resp = @bot.httputil.get_response("http://us.imdb.com/find?q=#{str}", @@ -38,7 +40,12 @@ class Imdb return url end elsif resp.code == "302" - return resp['location'].gsub(/http:\/\/us.imdb.com/, "").gsub(/\?.*/, "") + new_loc = resp['location'].gsub(/http:\/\/us.imdb.com/, "") + if new_loc.match(/\/find\?q=(.*)/) + return do_search($1) + else + return new_loc.gsub(/\?.*/, "") + end end return nil end @@ -78,7 +85,7 @@ class Imdb if resp.code == "200" m = /([^<]*)<\/title>/.match(resp.body) return nil if !m - title = CGI.unescapeHTML(m[1]) + title = Utils.decode_html_entities(m[1]) m = /<b>([0-9.]+)\/10<\/b>\n?\r?\s+<small>\(<a href="ratings">([0-9,]+) votes?<\/a>\)<\/small>/.match(resp.body) return nil if !m @@ -117,7 +124,7 @@ class Imdb if resp.code == "200" m = /<title>([^<]*)<\/title>/.match(resp.body) return nil if !m - name = CGI.unescapeHTML(m[1]) + name = Utils.decode_html_entities(m[1]) birth = nil data = grab_info("Date of Birth", resp.body)