Class: Aperture::Library
- Inherits:
-
Object
- Object
- Aperture::Library
- Defined in:
- lib/aperture/library.rb
Overview
Overview
The Library object parses and organizes the collection of objects that make up an aperture photo library. From the object you can access information about the Versions, Photos, Albums and Projects contained in the Library.
There is an optional second argument for parse the enable more verbose output.
Note: Depending on the size of the Aperture photo library parsing it into ruby objects may take serveral minutes.
Instance Attribute Summary collapse
-
#albums ⇒ Object
readonly
Returns the value of attribute albums.
-
#photos ⇒ Object
readonly
Returns the value of attribute photos.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Class Method Summary collapse
-
.parse(root_path, verbose = false) ⇒ Object
This the key method for parsing the library, it requires the path of where the library exists on disk.
Instance Method Summary collapse
-
#initialize(root) ⇒ Library
constructor
:nodoc:.
Constructor Details
#initialize(root) ⇒ Library
:nodoc:
21 22 23 24 25 26 27 28 |
# File 'lib/aperture/library.rb', line 21 def initialize(root) # :nodoc: raise ArgumentError, "Requires valid directory path" unless File.directory?(root) @root = root @photos = Aperture::PhotoSet.new @albums = {} @projects = {} @versions = {} end |
Instance Attribute Details
#albums ⇒ Object (readonly)
Returns the value of attribute albums.
19 20 21 |
# File 'lib/aperture/library.rb', line 19 def albums @albums end |
#photos ⇒ Object (readonly)
Returns the value of attribute photos.
19 20 21 |
# File 'lib/aperture/library.rb', line 19 def photos @photos end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
19 20 21 |
# File 'lib/aperture/library.rb', line 19 def projects @projects end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
19 20 21 |
# File 'lib/aperture/library.rb', line 19 def root @root end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
19 20 21 |
# File 'lib/aperture/library.rb', line 19 def versions @versions end |
Class Method Details
.parse(root_path, verbose = false) ⇒ Object
This the key method for parsing the library, it requires the path of where the library exists on disk. It returns a fully parsed Library object. The second arugment makes the method give more verbose output while it is processing. Using the ProgressBar gem, to install use: [sudo] gem install ruby-progressbar
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/aperture/library.rb', line 36 def self.parse(root_path, verbose=false) library = new(root_path) pb = nil files = [] if verbose print "Finding metadata files in library: " st = Time.now end Find.find(library.root) do |path| files << path end puts "#{(Time.now - st)} seconds" if verbose # Projects files_projects = files.select {|p| p =~ /\.approject$/ } # puts files_projects.size pb = ProgressBar.new("projects", files_projects.size) if defined?(ProgressBar) && verbose files_projects.each do |path| project = Project.new project.attributes = Plist::parse_xml(File.join(path, 'Info.apfolder')) library.projects[project.attributes['uuid']] = project pb.inc if pb end pb.finish if pb # Photo Masters files_masters = files.select {|p| p =~ /Info\.apmaster$/} # puts files_masters.size pb = ProgressBar.new("photo masters", files_masters.size) if defined?(ProgressBar) && verbose files_masters.each do |path| photo = Photo.new(File.dirname(path)) photo.master_attributes = Plist::parse_xml(path) photo.master_attributes['path'] library.photos << photo pb.inc if pb end pb.finish if pb # Photo Files files_files = files.select {|p| p =~ /\.apfile$/} # puts files_files.size pb = ProgressBar.new("photo files", files_files.size) if defined?(ProgressBar) && verbose files_files.each do |path| file_attributes = Plist::parse_xml(path) library.photos[file_attributes['masterUuid']].file_attributes = file_attributes pb.inc if pb end pb.finish if pb # Versions files_versions = files.select {|p| p =~ /Version-.+\.apversion$/} # puts files_versions.size pb = ProgressBar.new("versions", files_projects.size) if defined?(ProgressBar) && verbose files_versions.each do |path| directory, filename = File.dirname(path), File.basename(path) attributes = Plist::parse_xml(path) # find associated photo photo = library.photos[attributes['masterUuid']] # build version object version = Version.new(filename, attributes, photo) # add version to photo photo.versions << version # add verion to library library.versions[version.attributes['uuid']] = version # add version's photo to project library.projects[version.attributes['projectUuid']].photos << version.photo pb.inc if pb end pb.finish if pb # Albums files_albums = files.select {|p| p =~ /\.apalbum/ } # puts files_albums.size pb = ProgressBar.new("albums", files_albums.size) if defined?(ProgressBar) && verbose files_albums.each do |path| attributes = Plist::parse_xml(path) attributes['directory'] = File.dirname(path) attributes['filename'] = File.basename(path) album = Album.new(attributes) library.albums[album.attributes['InfoDictionary']['uuid']] = album if version_ids = album.attributes['InfoDictionary'] && album.attributes['InfoDictionary']['versionUuids'] version_ids.each do |id| album.photos[library.versions[id].attributes['masterUuid']] = library.versions[id].photo library.versions[id].photo.albums << album unless library.versions[id].photo.albums.include?(album) end end pb.inc if pb end pb.finish if pb return library end |