Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 31 lines (27 sloc) 0.724 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# -- encoding: utf-8 --
require 'rubygems'
require 'mini_exiftool'

if ARGV.size < 2
  puts "usage: ruby #{__FILE__} [+|-]SECONDS FILES"
  puts " i.e.: ruby #{__FILE__} 3600 *.jpg"
  exit -1
end

delta = ARGV.shift.to_i

ARGV.each do |filename|
  begin
    photo = MiniExiftool.new filename
  rescue MiniExiftool::Error => e
    $stderr.puts e.message
    exit -1
  end
  time = photo.date_time_original
  # time is a Time object, so we can use the methods of it :)
  photo.date_time_original = time + delta
  save_ok = photo.save
  if save_ok
    fmt = '%Y-%m-%d %H:%M:%S'
    puts "#{filename} changed: #{time.strftime(fmt)} -> #{(time + delta).strftime(fmt)}"
  else
    puts "#{filename} could not be changed"
  end
end
Something went wrong with that request. Please try again.