Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created April 22, 2015 21:09
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 matschaffer/3396c9a7f4119ff76121 to your computer and use it in GitHub Desktop.
Save matschaffer/3396c9a7f4119ff76121 to your computer and use it in GitHub Desktop.
a recovery script for grabbing remaining previews for lost iPhoto/Photos Masters
require 'pathname'
require 'uri'
require 'fileutils'
# Expects a dir arg of exported photos and a .log which contains /var/log/system.log Photo messages generated during the export
dir = Pathname.new(ARGV[0])
log = Pathname.new(dir.basename.to_s + '.log')
recovered_dir = dir + 'recovered'
recovered_dir.mkpath
File.new(log).each_line do |line|
if match = line.match(/file:\/\/([^',]+)/)
missing_file = match[1]
missing_file = URI.unescape(missing_file)
preview_prefix = File.dirname(missing_file.sub('Masters', 'Previews'))
preview_file = Dir[preview_prefix + '/*/' + File.basename(missing_file)].first
if preview_file
FileUtils.cp preview_file, recovered_dir
else
puts "No preview file found for #{missing_file}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment