-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimfindr.rb
executable file
·59 lines (51 loc) · 1.22 KB
/
simfindr.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
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rubygems'
require 'fileutils'
require 'ftools'
require 'exifr'
require 'digest/sha1'
digests = Hash.new
if ARGV.size != 2
puts "You should set two parameters: cmd image_path_src image_dest"
exit 1
end
to_sort_dir = ARGV[0]
work_dir = ARGV[1]
Dir.glob("#{to_sort_dir}/**/*") do |file|
if file.match(/(JPEG|jpg|JPG|jpeg)/) then
puts file
time = EXIFR::JPEG.new(file).date_time_original
puts time.strftime("%Y-%m-%d_%H:%M:%S") unless time.nil?
digest = Digest::SHA1.file(file).hexdigest if File.file?(file)
digests[digest] ||= Array.new
digests[digest] << file
end
end
digests.each_pair do |key,v|
v.each_with_index do |old_name, index|
time = nil
puts
puts old_name
begin
time = EXIFR::JPEG.new(old_name).date_time_original
rescue Exception => e
p e
p key
p v
end
if time.nil? then
time_str = '0000'
else
time_str = time.strftime("%Y-%m-%d_%H:%M:%S")
end
p time_str
p key
p index
new_name = work_dir + '/' + time_str + '_' + key + '_' + index.to_s + '.jpg'
p new_name
p old_name
if File.exists?(new_name)
puts "BLAD"
end
FileUtils.cp(old_name, new_name)
end
end