-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini_exiftool_renamer.rb
45 lines (35 loc) · 1013 Bytes
/
mini_exiftool_renamer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# encoding: utf-8
require 'mini_exiftool'
require './location'
require './name_formatter'
class MiniExiftoolRenamer
attr_reader :source_dir
def initialize(source_dir)
@source_dir = source_dir
end
def process
Location.new(source_dir).subfolders.each do |subfolder|
process_subfolder subfolder
end
end
private
def process_subfolder(subfolder)
photo_files = Location.new("#{source_dir}#{subfolder}").list
photo_files.each do |file|
update_photo file, subfolder
end
end
def update_photo(file_name, subfolder)
return unless file_name
path = "#{source_dir}#{subfolder}/#{file_name}"
photo = MiniExiftool.new path
created_date = NameFormatter.new(file_name).to_s
puts "[Updating Timestamp] #{photo.filename}: #{created_date} "
photo.modifydate = created_date
photo.datetimeoriginal = created_date
photo.createdate = created_date
photo.save
end
end
renamer = MiniExiftoolRenamer.new '/Volumes/PICTURE/'
renamer.process