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,
    :overview => movie.plot,
    :release_date => movie.release_date,
    :genres => movie.genres,
    :rating => movie.rating,
    :runtime => movie.runtime.to_i,
    :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.encode('iso-8859-1')
    title.force_encoding('utf-8')
    title1, year, title2 = title.match(/(.*) \(([0-9]{4})\)(.*)/)[1..3] rescue next
    @result << Result::Title.new(
      :id => id,
      :title => [title1.to_s.strip, title2.to_s.strip].join(" ").strip,
      :year => year)
  end
  result
end