lib/filentory/exifextractor.rb in filentory-cli-0.5.0 vs lib/filentory/exifextractor.rb in filentory-cli-0.6.0
- old
+ new
@@ -1,8 +1,7 @@
require 'exifr'
require 'xmp'
-require 'string-scrub'
class ExifExtractor
# Extracts the metadata of a file at a given path in the file system.
def metadata_for_file(file_path)
@@ -28,26 +27,30 @@
private
def extract_xmp_meta_data(img, xmpValues)
xmp = XMP.parse(img)
xmp.namespaces.each do |namespace_name|
- namespace = xmp.send(namespace_name)
- 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
- end
- end
- end
+ namespace = xmp.send(namespace_name)
+ extract_namespace_attributes(namespace_name, namespace, xmpValues)
+ end
rescue => error
#puts error
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
+ end
+ end
+ end
+
def extract_exif_main_meta_data(img, xmpValues)
xmpValues["exif.model"] = cleanup_description(img.model)
xmpValues["exif.make"] = cleanup_description(img.make)
xmpValues["exif.artist"] = cleanup_description(img.artist)
xmpValues["exif.date_time"] = format_date(img.date_time)
@@ -66,21 +69,20 @@
cleanup_metadata(value.force_encoding('UTF-8')).to_s[0...250] unless value.nil?
end
def extract_gps_infos(img, xmpValues)
if img.gps
+ assing_value_when_field_is_set(img.gps, :latitude, "exif.gps.latitude", xmpValues)
- if !img.gps.latitude.nil? && !img.gps.latitude.nan? then
- xmpValues["exif.gps.latitude"] = img.gps.latitude
- end
-
- if !img.gps.longitude.nil? && !img.gps.longitude.nan? then
- xmpValues["exif.gps.longitude"] = img.gps.longitude
- end
+ assing_value_when_field_is_set(img.gps, :longitude, "exif.gps.longitude", xmpValues)
- if !img.gps.altitude.nil? && !img.gps.altitude.nan? then
- xmpValues["exif.gps.altitude"] = img.gps.altitude
- end
+ assing_value_when_field_is_set(img.gps, :altitude, "exif.gps.altitude", xmpValues)
+ end
+ end
+
+ def assing_value_when_field_is_set(img, method, key_in_array, xmpValues)
+ if !img.send(method).nil? && !img.send(method).nan?
+ xmpValues[key_in_array] = img.send(method)
end
end
def format_date(date)
date.strftime("%FT%T+00:00") unless date.nil?
\ No newline at end of file