Class: Kithe::ExiftoolCharacterization::Result

Inherits:
Object
  • Object
show all
Defined in:
app/characterization/kithe/exiftool_characterization/result.rb

Overview

Retrieve known info out of exiftool results.

It can be really tricky to get this reliably from arbitrary files/cameras, there’s a lot of variety in EXIF/XMP/etc use.

We also normalize exiftool validation warnings in #exiftool_validation_warnings, they’re kind of a pain to extract

We do this right now for our use cases, in terms of what data we want, and what is actually found in ours. PR’s welcome to generalize!

In the future, we might have different result classes for different versions of exiftool or ways of calling it, it’s best to instantiate this with:

result = Kithe::ExiftoolChacterization.presenter(some_result_hash)
result.camera_model
result.exiftool_validation_warnings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Result

Returns a new instance of Result.



23
24
25
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 23

def initialize(hash)
  @result = hash || {}
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



21
22
23
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 21

def result
  @result
end

Instance Method Details

#bits_per_sampleObject



35
36
37
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 35

def bits_per_sample
  result["EXIF:BitsPerSample"]
end

#camera_isoObject



79
80
81
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 79

def camera_iso
  result["EXIF:ISO"]
end

#camera_lensObject



71
72
73
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 71

def camera_lens
  result["XMP:Lens"]
end

#camera_makeObject



47
48
49
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 47

def camera_make
  result["EXIF:Make"]
end

#camera_modelObject



51
52
53
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 51

def camera_model
  result["EXIF:Model"]
end

#compressionObject



43
44
45
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 43

def compression
  result["EXIF:Compression"]
end

#creation_dateObject

We look in a few places, and we only return date not time because getting timezone info is unusual, and it’s all we need right now.

Returns:

  • Date



99
100
101
102
103
104
105
106
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 99

def creation_date
  str_date = result["EXIF:DateTimeOriginal"] || result["EXIF:DateTimeOriginal"] || result["XMP:DateCreated"]
  return nil unless str_date

  Date.strptime(str_date, '%Y:%m:%d')
rescue Date::Error
  return nil
end

#dpiObject



55
56
57
58
59
60
61
62
63
64
65
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 55

def dpi
  # only "dpi" if unit is inches
  return nil unless result["EXIF:ResolutionUnit"] == "inches"

  if result["EXIF:XResolution"] == result["EXIF:YResolution"]
    result["EXIF:XResolution"]
  else
    # for now, we bail on complicated case
    nil
  end
end

#exif_tool_argsObject



31
32
33
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 31

def exif_tool_args
  result["Kithe:CliArgs"]
end

#exiftool_validation_warningsObject

Multiple exiftool validation warnings are annoyingly in keys ‘ExifTool:Warning`, `ExifTool:Copy1:Warning`, `ExifTool:Copy2:Warning`, etc. We provide a convenience method to fetch em all and return them as an array.



113
114
115
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 113

def exiftool_validation_warnings
  @exiftool_validation_warnings ||= result.slice( *result.keys.grep(/ExifTool(:Copy\d+):Warning/) ).values
end

#exiftool_versionObject



27
28
29
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 27

def exiftool_version
  result["ExifTool:ExifToolVersion"]
end

#icc_profile_nameObject



83
84
85
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 83

def icc_profile_name
  result["ICC_Profile:ProfileDescription"]
end

#page_countObject



91
92
93
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 91

def page_count
  result["PDF:PageCount"]
end

#pdf_versionObject



87
88
89
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 87

def pdf_version
  result["PDF:PDFVersion"]
end

#photometric_interpretationObject



39
40
41
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 39

def photometric_interpretation
  result["EXIF:PhotometricInterpretation"]
end

#shutter_speedObject



75
76
77
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 75

def shutter_speed
  result["Composite:ShutterSpeed"]
end

#softwareObject



67
68
69
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 67

def software
  result["XMP:CreatorTool"]
end