summaryrefslogtreecommitdiff
path: root/rename-pix-by-time-and-cam
diff options
context:
space:
mode:
Diffstat (limited to 'rename-pix-by-time-and-cam')
-rwxr-xr-xrename-pix-by-time-and-cam51
1 files changed, 31 insertions, 20 deletions
diff --git a/rename-pix-by-time-and-cam b/rename-pix-by-time-and-cam
index dc4041f..9595d86 100755
--- a/rename-pix-by-time-and-cam
+++ b/rename-pix-by-time-and-cam
@@ -7,48 +7,59 @@ ids = []
while line = STDIN.gets # list of files
a = line.split('.')
a.pop
- ids << a.join '.'
+ ids << a.join('.')
end
-ids.uniq!
used_prefixes = {} # prefix -> 0..N
ids.each do |i|
- exif = `exiv2 #{i}.jpg 2>/dev/null`
+ exif = `exiftool #{i}.jpg 2>/dev/null`
a = exif.split "\n"
timestamp = nil
cam = nil
a.each { |j|
- if j.start_with? "Camera model"
+ if j.start_with? "Camera Model Name"
cam = j
- elsif j.start_with? "Image timestamp"
+ elsif j.start_with? "Date/Time Original"
timestamp = j
next
else
next
end
}
+ skip = false
+ t = ""
+ c = ""
+ new_prefix = ""
+ add = 0
begin
t = timestamp.split(':',2)[1].strip.gsub(/(:|\ )/, '-')
c = cams[cam.split(':',2)[1].strip]
new_prefix = "#{t}-#{c}"
add = 1
- while used_prefixes.has_key? new_prefix
- new_prefix = "#{t}-#{add}-#{c}"
- add += 1
- end
- used_prefixes[new_prefix] = true
-
- Dir.glob("#{i}*").each { |f|
- ext = f.gsub(/^#{i}/,"")
- if File.exists? "#{new_prefix}#{ext}"
- puts "File exists: #{new_prefix}#{ext}, exiting!"
- exit
- end
- `mv #{i}#{ext} #{new_prefix}#{ext}`
- }
rescue
- puts "Error @#{i}"
+ puts "Can't find metadata for #{i}, skipping!"
+ skip = true
+ end
+ if t.split('-').first.to_i < 2000
+ puts "metadata unreasonable for #{i}, skipping!"
+ skip = true
+ end
+ next if skip
+ while used_prefixes.has_key? new_prefix
+ new_prefix = "#{t}-#{add}-#{c}"
+ add += 1
end
+ used_prefixes[new_prefix] = true
+
+ Dir.glob("#{i}*").each { |f|
+ ext = f.gsub(/^#{i}/,"")
+ if File.exists? "#{new_prefix}#{ext}"
+ puts "File exists: #{new_prefix}#{ext} (#{i})!"
+ exit
+ else
+ `mv #{i}#{ext} #{new_prefix}#{ext}`
+ end
+ }
end