Class: Popcorn::MovieManager
- Inherits:
-
Object
- Object
- Popcorn::MovieManager
- Defined in:
- lib/popcorn/movies.rb
Instance Attribute Summary collapse
-
#movie ⇒ Object
Returns the value of attribute movie.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize ⇒ MovieManager
constructor
A new instance of MovieManager.
- #lookup(movie, movie_filename) ⇒ Object
- #save_poster(directory) ⇒ Object
- #save_to_library ⇒ Object
Constructor Details
#initialize ⇒ MovieManager
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
#movie ⇒ Object
Returns the value of attribute movie.
12 13 14 |
# File 'lib/popcorn/movies.rb', line 12 def movie @movie end |
#path ⇒ Object
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_library ⇒ Object
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 |