From 52ecf61db173556aa45d8a6848a6c06989cc3a45 Mon Sep 17 00:00:00 2001 From: pks Date: Sat, 11 Jun 2022 16:33:16 +0200 Subject: rename-pix-by-time-and-cam: update --- rename-pix-by-time-and-cam | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'rename-pix-by-time-and-cam') diff --git a/rename-pix-by-time-and-cam b/rename-pix-by-time-and-cam index c8fd579..16f0808 100755 --- a/rename-pix-by-time-and-cam +++ b/rename-pix-by-time-and-cam @@ -2,7 +2,7 @@ require 'date' -$possible_devices = { "SIGMA DP2 Merrill" => "dp2m", "FP2" => "fp2", "Canon EOS 1000D" => "1000d", "iPad Air" => "ipadair", "iPhone 5" => "iphone5", "iPhone SE" => "iphonese", "IQ180" => "iq180", "iPhone XR" => "iphonexr" } +$possible_devices = { "SIGMA DP2 Merrill" => "dp2m", "FP2" => "fp2", "Canon EOS 1000D" => "1000d", "iPad Air" => "ipadair", "iPhone 5s" => "iphone5s", "iPhone SE" => "iphonese", "IQ180" => "iq180", "iPhone XR" => "iphonexr", "NIKON D70" => "d70" } $possible_devices.default = "unknown-device" file_ext = ARGV[0] @@ -49,10 +49,20 @@ def format_datetime dt end end +def get_possible_device s + s.strip! + s.downcase! + $possible_devices.each { |k,v| + if s.downcase.start_with? k.downcase + return v + end + } + return $possible_devices.default +end + def parse_device s d = s.split(':', 2)[1] - d.strip! - return $possible_devices[d] + return get_possible_device d end def determine_device a @@ -72,7 +82,8 @@ ids.each do |i| devices = [] a.each { |j| if j.start_with? "Camera Model Name" \ - or j.start_with? "Model" + or j.start_with? "Model" \ + or j.start_with? "Lens Model" devices << parse_device(j) elsif j.start_with? "Date/Time Original" \ or j.start_with? "Creation Date" \ @@ -80,11 +91,18 @@ ids.each do |i| or j.start_with? "Media Create Date" \ or j.start_with? "Track Create Date" \ or j.start_with? "File Modification Date/Time" - timestamps << parse_timestamp(j) + begin + timestamps << parse_timestamp(j) + rescue + end elsif j.start_with? "Sub Sec Time Original" subsec_time = j.split(':', 2)[1].strip end } + if timestamps.size == 0 + puts "No timestamp found" + exit + end skip = false new_prefix = "" add = 0 -- cgit v1.2.3