Last active
December 15, 2015 07:19
-
-
Save lodestone/5222776 to your computer and use it in GitHub Desktop.
photo_stream_sync.rb
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 'logger' | |
logfile = Time.now.strftime('%Y%m%d') | |
logfile = "/tmp/photo_sync_#{logfile}.log" | |
`touch #{logfile}` | |
$logger = Logger.new(logfile) | |
USER = 'matt' | |
class PhotoStream | |
ORIGINAL_FOLDER = "/Users/#{USER}/Library/Application Support/iLifeAssetManagement/assets/sub/" | |
RAW_DESTINATION_FOLDER = "/Users/#{USER}/Pictures/DCIM/Photo Stream/raw" | |
FINAL_DESTINATION_FOLDER = "/Users/#{USER}/Pictures/DCIM/Photo Stream/" | |
`mkdir -p "#{RAW_DESTINATION_FOLDER}"` | |
`mkdir -p "#{FINAL_DESTINATION_FOLDER}"` | |
def logger; $logger; end | |
def original_folders | |
Dir["#{ORIGINAL_FOLDER}/*"] | |
end | |
def sync | |
rsync_from_icloud_to_picture_folder | |
move_into_single_folder | |
remove_raw_folder | |
end | |
def rsync_from_icloud_to_picture_folder | |
logger.debug(`rsync -av "#{ORIGINAL_FOLDER}" "#{RAW_DESTINATION_FOLDER}"`) | |
end | |
def move_into_single_folder | |
Dir["#{RAW_DESTINATION_FOLDER}/**/*.*"].each do |file| | |
file_name = file.split('sub-').last.split(/raw/).last.split("/")[1] | |
file_name = file.split("sub-").last.split("/").first if file_name.length == 12 | |
file_name = "#{file_name}.jpg" | |
command = "mv \"#{file}\" \"#{FINAL_DESTINATION_FOLDER}/#{file_name}\"" | |
logger.debug command | |
puts command | |
`#{command}` | |
end | |
end | |
def remove_raw_folder | |
`rm -rf "#{RAW_DESTINATION_FOLDER}"` | |
end | |
def self.sync | |
PhotoStream.new.sync | |
end | |
end | |
PhotoStream.sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment