diff options
author | Patrick Simianer <p@simianer.de> | 2016-12-04 14:31:37 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2016-12-04 14:31:37 +0100 |
commit | f7c8277fd3de5e3aa300f9d20953d77a2b920ea9 (patch) | |
tree | 7b02d5ef7a1a214b6bd637ea0c49873d46d7f5c4 | |
parent | a37671558e5f3a4578d783f4dad1c8116183ac38 (diff) |
rename-pix-by-time-and-cam: use exiftool insteal of exiv2
-rwxr-xr-x | rename-pix-by-time-and-cam | 51 |
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 |