lib/filentory/exifextractor.rb in filentory-cli-0.4.0 vs lib/filentory/exifextractor.rb in filentory-cli-0.5.0
- old
+ new
@@ -34,36 +34,53 @@
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]
+ xmpValues["#{namespace_name}.#{attr}"] = answer.strip.to_s[0...250]
rescue => error
#puts error
end
end
end
rescue => error
#puts error
end
def extract_exif_main_meta_data(img, xmpValues)
- xmpValues["exif.model"] = img.model.scrub("*").strip unless img.model.nil?
- xmpValues["exif.artist"] = img.artist.force_encoding('UTF-8').scrub("*").strip.to_s[0..250] unless img.artist.nil?
+ 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)
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
end
+ def cleanup_metadata(value)
+ value.scrub("*").strip unless value.nil?
+ end
+ def cleanup_description(value)
+ cleanup_metadata(value.force_encoding('UTF-8')).to_s[0...250] unless value.nil?
+ end
+
def extract_gps_infos(img, xmpValues)
if img.gps
- xmpValues["exif.gps.latitude"] = img.gps.latitude
- xmpValues["exif.gps.longitude"] = img.gps.longitude
- xmpValues["exif.gps.altitude"] = img.gps.altitude
+
+ 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
+
+ if !img.gps.altitude.nil? && !img.gps.altitude.nan? then
+ xmpValues["exif.gps.altitude"] = img.gps.altitude
+ end
end
end
def format_date(date)
date.strftime("%FT%T+00:00") unless date.nil?
\ No newline at end of file