Created
March 19, 2023 09:05
-
-
Save fredplante/53ec071e7115672d79fe9ef77850e5af to your computer and use it in GitHub Desktop.
Put all google photo takout export files in a same directory (and remove jpeg from heic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "fileutils" | |
INPUT_DIR = "/Users/user/Takeout" | |
OUTPUT_DIR = "/Users/user/Takeout Output" | |
item_count = 0 | |
debug = true | |
Dir.glob("#{INPUT_DIR}/**/*") do |file| | |
next if File.directory? file | |
next if file.start_with?(".") | |
file_extension = File.extname file | |
next if file_extension.downcase == ".json" | |
puts "\nProcessing '#{file}'" | |
file_basename = File.basename(file, file_extension) | |
file_path = File.dirname(file) | |
heic_version_exists = false | |
heic_version = nil | |
if file_extension.downcase != ".heic" | |
puts "=> DEBUG: checking if heic version exists" if debug | |
heic_candidates = Dir["#{file_path}/#{file_basename}.*"] | |
heic_candidates.each do |heic_candidate| | |
puts "=> DEBUG: checking #{heic_candidate}" if debug | |
is_same_file = heic_candidate == file | |
puts "=> DEBUG: skipping as candidate is the current file" if is_same_file && debug | |
next if heic_candidate == is_same_file | |
is_json_file = File.extname(heic_candidate).downcase == ".json" | |
puts "=> DEBUG: skipping as candidate is a json file" if is_json_file && debug | |
next if is_json_file | |
is_heic_file = File.extname(heic_candidate).downcase == ".heic" | |
heic_version_exists = true if is_heic_file | |
heic_version = heic_candidate | |
puts "=> DEBUG: found the heic file!" if is_heic_file && debug | |
break if heic_version_exists | |
end | |
puts "=> skipping because a heic version exists (#{heic_version})" if heic_version_exists | |
next if heic_version_exists | |
end | |
item_count += 1 | |
new_filename = "google-photos-item-#{item_count}#{file_extension.downcase}" | |
puts "=> new filename: #{new_filename}" | |
destination = "#{OUTPUT_DIR}/#{new_filename}" | |
puts "=> copy #{file} to #{destination}" | |
FileUtils.cp(file, destination) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment