|
|
@@ -0,0 +1,43 @@
|
|
|
+require 'exifr/jpeg'
|
|
|
+require 'fileutils'
|
|
|
+
|
|
|
+module Fotos
|
|
|
+ class Organizer
|
|
|
+ def initialize(options)
|
|
|
+ @source_path = options[:source]
|
|
|
+ @destination_path = options[:destination]
|
|
|
+ end
|
|
|
+
|
|
|
+ def call
|
|
|
+ date_format = '%d-%m-%Y'
|
|
|
+ source_path_pattern = File.join(@source_path, "**/*")
|
|
|
+ paths = Dir.glob(source_path_pattern)
|
|
|
+ paths.each do |fp|
|
|
|
+ asset = Asset.new(fp)
|
|
|
+ puts "looking at #{asset.file_name}"
|
|
|
+ next unless asset.supported?
|
|
|
+
|
|
|
+ exif = EXIFR::JPEG.new(fp)
|
|
|
+
|
|
|
+ # get date from file's exif data
|
|
|
+ exif_date_str = exif.date_time.strftime(Fotos::DATE_FORMAT)
|
|
|
+
|
|
|
+ dest_dir = File.join(@destination_path, exif_date_str)
|
|
|
+ dest_path = File.join(dest_dir, asset.file_name)
|
|
|
+
|
|
|
+ # create destination dir if not already there
|
|
|
+ FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
|
|
|
+ puts "#{asset.file_name} --> #{dest_path}"
|
|
|
+ FileUtils.cp(fp, dest_path)
|
|
|
+ dest_path
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ private
|
|
|
+ def generate_thumbnails
|
|
|
+ @copied_paths.map do |fp|
|
|
|
+ Thumbnail.new(fp).create
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|