Skip to content

Instantly share code, notes, and snippets.

@wilik16
Created June 19, 2023 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilik16/15335711be8e2b528f24d0b347be92e7 to your computer and use it in GitHub Desktop.
Save wilik16/15335711be8e2b528f24d0b347be92e7 to your computer and use it in GitHub Desktop.
Almost similar with https://gist.github.com/wilik16/ce6f3e96b90fd459da661c4e22be3c91, but this one is based on the photo's exif instead of the csv file from icloud. Unfortunately this script is still incomplete but almost complete.
# frozen_string_literal: true
require 'exif'
require 'time'
folders = Dir.foreach('.').select do |e|
/^iCloud Photos/.match(e)
end
photos_paths = []
folders.each do |folder|
photo_names = Dir.new("#{folder}/Photos").entries.reject do |e|
/(^.*\.csv$)|(^\.)|(^\.\.)/.match(e)
end
unless photo_names.empty?
photos_paths << "#{folder}/#{photo_names}"
end
end
return
file_path = 'iCloud Photos Part 48 of 50/Photos/IMG_5768-1.JPG'
# file_path = 'Photos/IMG_97721.JPG'
data = Exif::Data.new(File.open(file_path))
puts data.date_time_original
puts data.date_time_digitized
puts data.offset_time
puts data.time_zone_offset
new_date = Time.strptime("#{data.date_time} #{data.offset_time}", '%Y:%m:%d %H:%M:%S %z')
puts new_date
puts File.mtime(file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment