lib/filentory/exifextractor.rb in filentory-cli-0.6.0 vs lib/filentory/exifextractor.rb in filentory-cli-0.6.1
- old
+ new
@@ -1,9 +1,10 @@
-require 'exifr'
+require 'exifr/jpeg'
require 'xmp'
+require 'methadone'
-class ExifExtractor
+class ExifExtractor include Methadone::CLILogging
# Extracts the metadata of a file at a given path in the file system.
def metadata_for_file(file_path)
img = EXIFR::JPEG.new(file_path)
@@ -30,23 +31,23 @@
xmp = XMP.parse(img)
xmp.namespaces.each do |namespace_name|
namespace = xmp.send(namespace_name)
extract_namespace_attributes(namespace_name, namespace, xmpValues)
end
- rescue => error
- #puts error
+ rescue => error_message
+ error ("#{error_message}")
end
def extract_namespace_attributes(namespace_name, namespace, xmpValues)
namespace.attributes.each do |attr|
begin
returnval = namespace.send(attr)#.inspect
#puts "returnval: #{returnval}"
answer = returnval.scrub("*")
xmpValues["#{namespace_name}.#{attr}"] = answer.strip.to_s[0...250]
- rescue => error
- #puts error
+ rescue => error_message
+ error ("#{error_message}")
end
end
end
def extract_exif_main_meta_data(img, xmpValues)
@@ -55,12 +56,12 @@
xmpValues["exif.artist"] = cleanup_description(img.artist)
xmpValues["exif.date_time"] = format_date(img.date_time)
xmpValues["exif.date_time_original"] = format_date(img.date_time_original)
xmpValues["exif.width"] = img.width
xmpValues["exif.height"] = img.height
- rescue => error
- #puts error
+ rescue => error_message
+ error ("#{error_message}")
end
def cleanup_metadata(value)
value.scrub("*").strip unless value.nil?
end
@@ -88,6 +89,6 @@
def format_date(date)
date.strftime("%FT%T+00:00") unless date.nil?
rescue
nil
end
-end
\ No newline at end of file
+end