class Popcorn::MovieManager

Attributes

movie[RW]
path[RW]

Public Class Methods

new() click to toggle source
# File lib/popcorn/movies.rb, line 14
def initialize
  @imdb = ImdbParty::Imdb.new
end

Public Instance Methods

lookup(movie, movie_filename) click to toggle source
# 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) click to toggle source
# 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_library() click to toggle source
# 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