X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fimdb.rb;h=0a878c7516f8e112506bdc817ffd3958b1097cac;hb=1e841175468b3e0357ab278a226a237fe4d7687e;hp=3f750793cc1969a86e38a34ce0ebdb679e5b4163;hpb=23b75487b51e7bb0850c66e320eda586658aed80;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git
diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb
index 3f750793..0a878c75 100644
--- a/data/rbot/plugins/imdb.rb
+++ b/data/rbot/plugins/imdb.rb
@@ -11,24 +11,33 @@
#
# License:: MIT license
-require 'uri/common'
-
class Imdb
IMDB = "http://us.imdb.com"
TITLE_OR_NAME_MATCH = /]*)>([^<]*)<\/a>/
TITLE_MATCH = /]*)>([^<]*)<\/a>/
NAME_MATCH = /]*)>([^<]*)<\/a>/
+ CREDIT_NAME_MATCH = /#{NAME_MATCH}<\/td>
]+> \.\.\. <\/td> | ]+>(.+?)<\/td>/
+ FINAL_ARTICLE_MATCH = /, ([A-Z]\S{0,2})$/
+
+ MATCHER = {
+ :title => TITLE_MATCH,
+ :name => NAME_MATCH,
+ :both => TITLE_OR_NAME_MATCH
+ }
def initialize(bot)
@bot = bot
end
- def search(rawstr)
- str = URI.escape(rawstr) << ";site=aka"
- return do_search(str)
+ def search(rawstr, rawopts={})
+ str = CGI.escape(rawstr)
+ str << ";site=aka" if @bot.config['imdb.aka']
+ opts = rawopts.dup
+ opts[:type] = :both unless opts[:type]
+ return do_search(str, opts)
end
- def do_search(str)
+ def do_search(str, opts={})
resp = nil
begin
resp = @bot.httputil.get_response(IMDB + "/find?q=#{str}",
@@ -39,11 +48,14 @@ class Imdb
return nil
end
+
+ matcher = MATCHER[opts[:type]]
+
if resp.code == "200"
m = []
- m << TITLE_OR_NAME_MATCH.match(resp.body) if @bot.config['imdb.popular']
+ m << matcher.match(resp.body) if @bot.config['imdb.popular']
if resp.body.match(/\(Exact Matches\)<\/b>/) and @bot.config['imdb.exact']
- m << TITLE_OR_NAME_MATCH.match($')
+ m << matcher.match($')
end
m.compact!
unless m.empty?
@@ -55,7 +67,7 @@ class Imdb
debug "automatic redirection"
new_loc = resp['location'].gsub(IMDB, "")
if new_loc.match(/\/find\?q=(.*)/)
- return do_search($1)
+ return do_search($1, opts)
else
return [new_loc.gsub(/\?.*/, "")]
end
@@ -63,8 +75,9 @@ class Imdb
return nil
end
- def info(rawstr)
- urls = search(rawstr)
+ def info(rawstr, opts={})
+ debug opts.inspect
+ urls = search(rawstr, opts)
debug urls
if urls.nil_or_empty?
debug "IMDB: search returned NIL"
@@ -75,9 +88,9 @@ class Imdb
type = sr.match(/^\/([^\/]+)\//)[1].downcase.intern rescue nil
case type
when :title
- results << info_title(sr)
+ results << info_title(sr, opts)
when :name
- results << info_name(sr)
+ results << info_name(sr, opts)
else
results << "#{sr}"
end
@@ -89,7 +102,24 @@ class Imdb
/ |