Class: Kithe::ExiftoolCharacterization::Result
- Inherits:
-
Object
- Object
- Kithe::ExiftoolCharacterization::Result
- 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
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #bits_per_sample ⇒ Object
- #camera_iso ⇒ Object
- #camera_lens ⇒ Object
- #camera_make ⇒ Object
- #camera_model ⇒ Object
- #compression ⇒ Object
-
#creation_date ⇒ Object
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.
- #dpi ⇒ Object
- #exif_tool_args ⇒ Object
-
#exiftool_validation_warnings ⇒ Object
Multiple exiftool validation warnings are annoyingly in keys ‘ExifTool:Warning`, `ExifTool:Copy1:Warning`, `ExifTool:Copy2:Warning`, etc.
- #exiftool_version ⇒ Object
- #icc_profile_name ⇒ Object
-
#initialize(hash) ⇒ Result
constructor
A new instance of Result.
- #page_count ⇒ Object
- #pdf_version ⇒ Object
- #photometric_interpretation ⇒ Object
- #shutter_speed ⇒ Object
- #software ⇒ Object
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
#result ⇒ Object (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_sample ⇒ Object
35 36 37 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 35 def bits_per_sample result["EXIF:BitsPerSample"] end |
#camera_iso ⇒ Object
79 80 81 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 79 def camera_iso result["EXIF:ISO"] end |
#camera_lens ⇒ Object
71 72 73 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 71 def camera_lens result["XMP:Lens"] end |
#camera_make ⇒ Object
47 48 49 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 47 def camera_make result["EXIF:Make"] end |
#camera_model ⇒ Object
51 52 53 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 51 def camera_model result["EXIF:Model"] end |
#compression ⇒ Object
43 44 45 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 43 def compression result["EXIF:Compression"] end |
#creation_date ⇒ Object
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.
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 |
#dpi ⇒ Object
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_args ⇒ Object
31 32 33 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 31 def exif_tool_args result["Kithe:CliArgs"] end |
#exiftool_validation_warnings ⇒ Object
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_version ⇒ Object
27 28 29 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 27 def exiftool_version result["ExifTool:ExifToolVersion"] end |
#icc_profile_name ⇒ Object
83 84 85 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 83 def icc_profile_name result["ICC_Profile:ProfileDescription"] end |
#page_count ⇒ Object
91 92 93 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 91 def page_count result["PDF:PageCount"] end |
#pdf_version ⇒ Object
87 88 89 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 87 def pdf_version result["PDF:PDFVersion"] end |
#photometric_interpretation ⇒ Object
39 40 41 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 39 def photometric_interpretation result["EXIF:PhotometricInterpretation"] end |
#shutter_speed ⇒ Object
75 76 77 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 75 def shutter_speed result["Composite:ShutterSpeed"] end |
#software ⇒ Object
67 68 69 |
# File 'app/characterization/kithe/exiftool_characterization/result.rb', line 67 def software result["XMP:CreatorTool"] end |