lib/iphoto_backup/cli.rb in iphoto_backup-1.0.0 vs lib/iphoto_backup/cli.rb in iphoto_backup-1.0.1
- old
+ new
@@ -6,15 +6,15 @@
class CLI < Thor
IPHOTO_ALBUM_PATH = "~/Pictures/iPhoto Library.photolibrary/AlbumData.xml"
DEFAULT_OUTPUT_DIRECTORY = "~/Google Drive/Dropbox"
IPHOTO_EPOCH = Time.new(2001, 1, 1)
- desc "export iPhoto albums", "exports iPhoto albums into target directory"
- option :filter, aliases: '-e', default: '.*'
- option :output, aliases: '-o', default: DEFAULT_OUTPUT_DIRECTORY
- option :config, aliases: '-c', default: IPHOTO_ALBUM_PATH
- option :'date-prefix', aliases: '-d', default: false
+ desc "export [OPTIONS]", "exports iPhoto albums into target directory"
+ option :filter, desc: 'filter to only include albums that match the given regex', aliases: '-e', default: '.*'
+ option :output, desc: 'directory to export albums to', aliases: '-o', default: DEFAULT_OUTPUT_DIRECTORY
+ option :config, desc: 'iPhoto AlbumData.xml file to process', aliases: '-c', default: IPHOTO_ALBUM_PATH
+ option :'include-date-prefix', desc: 'automatically include ISO8601 date prefix to exported events', aliases: '-d', default: false, type: :boolean
def export
each_album do |folder_name, album_info|
say "\n\nProcessing Roll: #{folder_name}..."
each_image(album_info) do |image_info|
@@ -38,28 +38,33 @@
private
def each_album(&block)
albums = value_for_dictionary_key("List of Rolls").children.select {|n| n.name == 'dict' }
albums.each do |album_info|
- folder_name = value_for_dictionary_key('RollName', album_info).content
+ folder_name = album_name album_info
- if options[:'include-date-prefix'] && folder_name !~ /^\d{4}-\d{2}-\d{2} /
- album_date = nil
- each_image album_info do |image_info|
- next if album_date
- photo_interval = value_for_dictionary_key('DateAsTimerInterval', image_info).content.to_i
- album_date = (IPHOTO_EPOCH + photo_interval).to_date
- end
- say "Automatically adding #{album_date} prefix to folder: #{folder_name}"
- folder_name = "#{album_date} #{folder_name}"
- end
-
if folder_name.match(album_filter)
yield folder_name, album_info
else
say "\n\n#{folder_name} does not match the filter: #{album_filter.inspect}"
end
end
+ end
+
+ def album_name(album_info)
+ folder_name = value_for_dictionary_key('RollName', album_info).content
+
+ if options[:'include-date-prefix'] && folder_name !~ /^\d{4}-\d{2}-\d{2} /
+ album_date = nil
+ each_image album_info do |image_info|
+ next if album_date
+ photo_interval = value_for_dictionary_key('DateAsTimerInterval', image_info).content.to_i
+ album_date = (IPHOTO_EPOCH + photo_interval).strftime('%Y-%d-%m')
+ end
+ say "Automatically adding #{album_date} prefix to folder: #{folder_name}"
+ folder_name = "#{album_date} #{folder_name}"
+ end
+ folder_name
end
def each_image(album_info, &block)
album_images = value_for_dictionary_key('KeyList', album_info).css('string').map(&:content)
album_images.each do |image_id|