Class: UnifiedDB::Backend::IMDB

Inherits:
Base
  • Object
show all
Defined in:
lib/unified_db/backend/imdb.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #title

Instance Method Summary collapse

Methods inherited from Base

find, #find, #initialize, #result

Constructor Details

This class inherits a constructor from UnifiedDB::Backend::Base

Instance Method Details

#find_by_id(id) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/unified_db/backend/imdb.rb', line 8

def find_by_id(id)
  movie = handler.find_movie_by_id(id)
  @result = Result::ID.new(
    :id => movie.imdb_id,
    :title => movie.title.to_s,
    :overview => movie.plot.to_s,
    :release_date => movie.release_date.to_s,
    :genres => movie.genres,
    :rating => movie.rating.to_s,
    :runtime => movie.runtime.to_i.to_s,
    :actors => format_actors(movie.actors),
    :directors => format_directors(movie.directors),
    :writers => format_writers(movie.writers),
    :posters => Array(movie.poster_url)
  )
rescue
  raise ApiError, 'not found'
end

#find_by_title(title) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/unified_db/backend/imdb.rb', line 27

def find_by_title(title)
  # movies = handler.find_by_title(title)
  movies = Imdb::Search.new(title).movies
  movies.each do |movie|
    id = "tt#{movie.id}"
    title = movie.title
    title = title.encode('iso-8859-1').force_encoding('utf-8') if title.respond_to? :force_encoding
    title1, year, tmp, title2 = title.match(/(.*) \(([0-9]{4})(\/[a-zA-Z]*)?\)(.*)/)[1..4] rescue next
    @result << Result::Title.new(
      :id => id,
      :title => [title1.to_s.strip, title2.to_s.strip].join(" ").strip,
      :year => year)
  end
  result
end