Module: MultiExiftool

Defined in:
lib/multi_exiftool.rb,
lib/multi_exiftool/batch.rb,
lib/multi_exiftool/reader.rb,
lib/multi_exiftool/values.rb,
lib/multi_exiftool/writer.rb,
lib/multi_exiftool/executable.rb

Defined Under Namespace

Modules: Executable Classes: Batch, Error, Reader, Values, Writer

Constant Summary collapse

VERSION =
'0.19.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exiftool_commandObject

Returns the value of attribute exiftool_command.



92
93
94
# File 'lib/multi_exiftool.rb', line 92

def exiftool_command
  @exiftool_command
end

.exiftool_versionObject (readonly)

ExifTool version as float (since exiftool versions are numbered “float friendly”)



102
103
104
# File 'lib/multi_exiftool.rb', line 102

def exiftool_version
  @exiftool_version
end

Class Method Details

.batch(&block) ⇒ Object

Execute a batch of write commands Returns an array of the error messages

Example:

errors = MultiExiftool.batch do
  Dir['*.jpg'].each_with_index do |filename, i|
    write filename, {author: 'Jan Friedrich', comment: "This is file number #{i+1}."}
  end
unless errors.empty?
  # do error handling
end


81
82
83
84
85
86
87
88
89
90
# File 'lib/multi_exiftool.rb', line 81

def batch &block
  batch = Batch.new
  if block.arity == 0
    batch.instance_exec &block
  else
    yield batch
  end
  batch.execute
  batch.errors
end

.delete_values(filenames, opts = {}) ⇒ Object

Deleting metadata Returns an array of the error messages

Examples:

# delete values for all tags
errors = MultiExiftool.delete_values(Dir['*.jpg'])
unless errors.empty?
  # do error handling
end

# delete values for tags Author and Title
errors = MultiExiftool.delete_values(Dir['*.jpg'], %w[author title])
unless errors.empty?
  # do error handling
end


63
64
65
66
67
# File 'lib/multi_exiftool.rb', line 63

def delete_values filenames, opts={}
  tags = opts.fetch(:tags, :all)
  values = Array(tags).inject(Hash.new) {|h,tag| h[tag] = nil; h}
  write(filenames, values)
end

.read(filenames, opts = {}) ⇒ Object

Reading metadata Be aware: it returns an array of two elements: values, errors

Example:

values, errors = MultiExiftool.read(Dir['*.jpg'])
if errors.empty?
  values.each {|val| do_something_with(val) }
else
  # error handling
end


28
29
30
31
32
# File 'lib/multi_exiftool.rb', line 28

def read filenames, opts={}
  reader = Reader.new(filenames, opts)
  values = reader.read
  [values, reader.errors]
end

.write(filenames, values, opts = {}) ⇒ Object

Writing metadata Returns an array of the error messages

Example:

errors = MultiExiftool.write(Dir['*.jpg'], {author: 'Jan Friedrich'})
unless errors.empty?
  # do error handling
end


42
43
44
45
46
# File 'lib/multi_exiftool.rb', line 42

def write filenames, values, opts={}
  writer = Writer.new(filenames, values, opts)
  writer.write
  writer.errors
end