lib/filentory/exifextractor.rb in filentory-cli-0.3.1 vs lib/filentory/exifextractor.rb in filentory-cli-0.4.0

- old
+ new

@@ -1,7 +1,8 @@ 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) @@ -13,10 +14,11 @@ extract_exif_main_meta_data(img, xmpValues) extract_gps_infos(img, xmpValues) xmpValues.delete_if { |k, v| v.nil? || v.to_s.empty?} rescue => error + puts "metadata_for_file #{file_path} failed: #{error}" Hash.new end # Check if ExifExtractor handles the file extension. # Example: ExifExtractor.handles? ".jpg" => returns true @@ -29,24 +31,32 @@ xmp = XMP.parse(img) xmp.namespaces.each do |namespace_name| namespace = xmp.send(namespace_name) namespace.attributes.each do |attr| begin - xmpValues["#{namespace_name}.#{attr}"] = namespace.send(attr)#.inspect - rescue + 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 + end + rescue => error + #puts error end def extract_exif_main_meta_data(img, xmpValues) - xmpValues["exif.model"] = img.model - xmpValues["exif.artist"] = img.artist + 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.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 + xmpValues["exif.height"] = img.height + rescue => error + #puts error end def extract_gps_infos(img, xmpValues) if img.gps @@ -56,7 +66,9 @@ end end def format_date(date) date.strftime("%FT%T+00:00") unless date.nil? + rescue + nil end end \ No newline at end of file