lib/movier/lmdb.rb in movier-0.0.9 vs lib/movier/lmdb.rb in movier-0.1.0
- old
+ new
@@ -55,10 +55,11 @@
end
false
end
def find(params)
+ # TODO: add support for "find in a box" and "exclude boxes"
read_data; @params = params; @params[:verbose] = true if @params[:shuffle]
raise "Please, add some movie boxes, before searching in the local movie database" unless @movies.any?
@movies.select!{|movie| movie[:title].downcase.include? @params[:keywords].downcase} if @params[:keywords]
[:directors, :writers, :actors, :genre, :tags].each { |kind| find_persons(kind) }
@@ -152,19 +153,13 @@
#
def update_itself
message = "Found no movie box in the local database.\n"
message += "Please, run `movier add` to add some movie boxes, before updating me!"
raise message if @boxes.empty?
- @boxes.each { |box| delete(box); add(box) }
- end
-
- def delete(dir = nil)
- dir = File.expand_path dir
- @movies.reject!{ |movie| movie[:box] == dir }
- @boxes.reject!{ |box| box == dir }
+ @movies = []
write_data
- current_state
+ @boxes.each { |box| add(box) }
end
# Add a given directory to the local movie database.
# The directory should be pre-organized using the Organize command.
#
@@ -179,26 +174,23 @@
raise 'You should first run `movier organize` on this directory!' unless imdb.count > 0
count = 0
imdb.each do |file|
movie = Movier.read_yaml file
- if in_database?(movie) && !@boxes.include?(dir)
- Movier.warn_with "#{movie[:imdb]["Title"]} already exists in database!"
+ if in_database?(movie)
+ # TODO: add the path with a "dup" key
+ Movier.warn_with "#{movie[:imdb]["Title"]} - # #{movie[:imdb]["imdbRating"]} - already exists in database!"
elsif !in_database?(movie)
@movies.push sanitize(movie, dir, file)
count += 1
end
end
@boxes.push dir unless @boxes.include? dir
write_data
- Movier.passed_with "Added #{count} new movies in LMDB."
- current_state
- end
-
- def current_state
- Movier.tip_now "LMDB now contains #{@movies.count} movies, and #{@boxes.count} boxes."
+ Movier.passed_with "Added #{"%4d" % count} new movies in LMDB from: #{dir}"
+ Movier.tip_now "LMDB now contains #{"%4d" % @movies.count} movies."
end
def sanitize(movie, dir, imdb_file)
imdb = movie[:imdb]
nice_name = "#{imdb["Title"]} [#{imdb["Year"]}]"