File: shift_time.rb

package info (click to toggle)
ruby-mini-exiftool 2.9.0-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 688 kB
  • sloc: ruby: 2,616; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 724 bytes parent folder | download | duplicates (3)
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