Class: Popcorn::MovieManager

Inherits:
Object
  • Object
show all
Defined in:
lib/popcorn/movies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMovieManager

Returns a new instance of MovieManager.



14
15
16
# File 'lib/popcorn/movies.rb', line 14

def initialize
  @imdb = ImdbParty::Imdb.new
end

Instance Attribute Details

#movieObject

Returns the value of attribute movie.



12
13
14
# File 'lib/popcorn/movies.rb', line 12

def movie
  @movie
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/popcorn/movies.rb', line 12

def path
  @path
end

Instance Method Details

#lookup(movie, movie_filename) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/popcorn/movies.rb', line 18

def lookup(movie, movie_filename)
  if @path.nil?
    @path = Pathname.new(movie_filename)
  end
  #movie = File.basename(movie, '.*')
  @movie = @imdb.find_by_title(movie)[0]
end

#save_poster(directory) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/popcorn/movies.rb', line 39

def save_poster(directory)
  unless movie[:poster_url].nil?
    splituri = URI.split(movie[:poster_url])
    Net::HTTP.start(splituri[2]) do |http|
      resp = http.get(splituri[5])
      open("#{directory}/#{@movie[:title]}.tbn", "wb") do |file|
        file.write(resp.body)
      end
    end
  end
end

#save_to_libraryObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/popcorn/movies.rb', line 26

def save_to_library
  unless @path.exist?
    raise "Error: File does not exist #{@path}"
  end
  to_dir = "#{Settings.library}/#{@movie[:title]} (#{@movie[:year]})/"
  filename = "#{@movie[:title]} (#{@movie[:year]})#{@path.extname}"
  to_path = "#{to_dir}#{filename}"
  FileUtils.mkdir(to_dir)
  puts "Moving #{@path} to #{to_path}"
  FileUtils.mv(@path, to_path)
  self.save_poster(to_dir)
end