lib/imdb.rb in pirate-autonzb-0.4 vs lib/imdb.rb in pirate-autonzb-0.4.1
- old
+ new
@@ -10,10 +10,11 @@
def initialize(name, year = nil, link = nil)
@name, @year, @link = name, year, link
@coder = HTMLEntities.new
set_doc
set_id
+ p @id
end
def score
if @doc && score_text = @doc.search("div.meta b").first
score_text.inner_html.match(/(.*)\/10/)[1].to_f
@@ -34,10 +35,11 @@
private
def set_doc
if @link
@doc = Hpricot(open(@link.gsub(/\/\s*$/,'')))
+ @id = @link.match(/tt[0-9]+/)[0]
else
query = "#{@name} (#{@year})"
search_url = "http://www.imdb.com/find?q=#{CGI::escape(query)}"
doc = Hpricot(open(search_url))
case doc.search("title").inner_html
@@ -49,17 +51,20 @@
imdb_id = doc.search("td[@valign='top'] a[@href^='/title/tt']").first[:href]
movie_url = "http://www.imdb.com#{imdb_id}"
else
movie_url = nil
end
- @doc = Hpricot(open(movie_url)) if movie_url
+ if movie_url
+ @doc = Hpricot(open(movie_url))
+ @id = movie_url.match(/tt[0-9]+/)[0]
+ end
else # direct in movie page
@doc = doc
end
end
end
def set_id
- @id = doc.search("a[@href*='/title/tt']").first[:href].match(/tt[0-9]+/)[0] if doc
+ @id ||= doc.search("a[@href*='/title/tt']").first[:href].match(/tt[0-9]+/)[0] if doc
end
end
\ No newline at end of file