Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Created July 6, 2014 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannguyen/bc8918067685c06e5472 to your computer and use it in GitHub Desktop.
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
# 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