Created
July 6, 2014 17:35
-
-
Save dannguyen/bc8918067685c06e5472 to your computer and use it in GitHub Desktop.
For Adobe Lightroom XMP files, a quickie Ruby script to timeshift the capture time by an arbitrary number of seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A quickie script to timeshift all XMP files of a certain camera model | |
# by an arbitrary number of seconds | |
require 'nokogiri' | |
require 'chronic' | |
require 'fileutils' | |
files = Dir.glob('./xmps/*.xmp') | |
orgdir = "./new-xmps" | |
seconds_to_shift = 98 | |
model_name_to_change = 'NEX-7' | |
files.each do |file| | |
xstr = open(file){|f| f.read } | |
# we'll just overwrite the time values in xstr rather than rebuild a XML file | |
# via Nokogiri | |
xmp = Nokogiri::XML(xstr) | |
attrs = xmp.children[0].children[1].children[1].attributes | |
model = attrs['Model'] | |
if model.value == model_name_to_change | |
datetime = attrs['DateTimeOriginal'] | |
prevtime = datetime.value | |
t = Chronic.parse(prevtime) | |
newtime = (t - seconds_to_shift).strftime("%Y-%m-%dT%H:%M:%S") | |
open(File.join(orgdir, File.basename(file) ), 'wb'){|o| o.write xstr.gsub(prevtime, newtime) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment