Created
April 22, 2015 21:09
-
-
Save matschaffer/3396c9a7f4119ff76121 to your computer and use it in GitHub Desktop.
a recovery script for grabbing remaining previews for lost iPhoto/Photos Masters
This file contains 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
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