summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2017-07-05 07:54:49 +0200
committerPatrick Simianer <p@simianer.de>2017-07-05 07:54:49 +0200
commit6502b84244f232cbe97056da6585b16ed9c1f475 (patch)
tree697f63bbfc6d0a1b7b0e1e823f19422ddc6a3231
parentca87cdfa1dc9a4dd9838ad61c4456a6fefb91b98 (diff)
rename-pix-by-time-and-cam: fixes and additions
-rwxr-xr-xrename-pix-by-time-and-cam28
1 files changed, 24 insertions, 4 deletions
diff --git a/rename-pix-by-time-and-cam b/rename-pix-by-time-and-cam
index 5681bc9..b419236 100755
--- a/rename-pix-by-time-and-cam
+++ b/rename-pix-by-time-and-cam
@@ -3,6 +3,11 @@
cams = { "SIGMA DP2 Merrill" => "dp2m", "FP2" => "fp2", "Canon EOS 1000D" => "1000d", "iPad Air" => "ipadair", "iPhone 5" => "iphone5" }
cams.default = "default"
+file_ext = ARGV[0]
+if !file_ext
+ file_ext = "jpg"
+end
+
ids = []
while line = STDIN.gets # list of files
a = line.split('.')
@@ -13,16 +18,21 @@ end
used_prefixes = {} # prefix -> 0..N
ids.each do |i|
- exif = `exiftool #{i}.jpg 2>/dev/null`
+ exif = `exiftool #{i}.#{file_ext} 2>/dev/null`
a = exif.split "\n"
timestamp = nil
+ timestamp_bak = nil
cam = nil
+ cam_bak = nil
a.each { |j|
if j.start_with? "Camera Model Name"
cam = j
+ elsif j.start_with? "Model"
+ cam_bak = j
elsif j.start_with? "Date/Time Original"
timestamp = j
- next
+ elsif j.start_with? "File Modification Date/Time"
+ timestamp_bak = j
else
next
end
@@ -33,8 +43,18 @@ ids.each do |i|
new_prefix = ""
add = 0
begin
- t = timestamp.split(':',2)[1].strip.gsub(/(:|\ )/, '-')
- c = cams[cam.split(':',2)[1].strip]
+ if timestamp
+ t = timestamp.split(':',2)[1].strip.gsub(/(:|\ )/, '-')
+ elsif timestamp_bak
+ t = timestamp_bak.split(':',2)[1].strip.gsub(/(:|\ )/, '-')
+ end
+ if cam
+ c = cams[cam.split(':',2)[1].strip]
+ elsif cam_bak
+ c = cams[cam_bak.split(':',2)[1].strip]
+ else
+ c = "unknown-device"
+ end
new_prefix = "#{t}-#{c}"
add = 1
rescue