forked from iMediaSandboxing/iMedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMBApertureParserConfiguration.m
209 lines (181 loc) · 8.96 KB
/
IMBApertureParserConfiguration.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//
// IMBApertureParserConfiguration.m
// iMedia
//
// Created by Jörg Jacobsen on 11.03.15.
//
//
#import "IMBApertureParserConfiguration.h"
#import "NSImage+iMedia.h"
#import "IMBIconCache.h"
#import "IMBImageProcessor.h"
#import "IMBNodeObject.h"
/**
Reverse-engineered values of the iPhoto app media group type identifiers.
Apple doesn't seem to yet publicly define these constants anywhere.
*/
NSString *kIMBApertureMediaGroupTypeIdentifierFaces = @"com.apple.Aperture.FacesAlbum";
/**
Reverse-engineered keys of the Photos app media source's attributes.
Apple doesn't seem to yet publicly define these constants anywhere.
*/
/* Top Level Groups*/
NSString *kIMBApertureMediaGroupIdentifierAllProjects = @"AllProjectsItem";
NSString *kIMBApertureMediaGroupIdentifierLastViewedEvent = @"eventFilterBarAlbum";
NSString *kIMBApertureMediaGroupIdentifierFaces = @"peopleAlbum";
/**
Parser configuration factory for Apple iPhoto app.
*/
IMBMLParserConfigurationFactory IMBMLApertureParserConfigurationFactory =
^id<IMBAppleMediaLibraryParserDelegate>(MLMediaType mediaType)
{
NSSet *identifiersOfNonUserCreatedGroups = [NSSet set];
return [[IMBApertureParserConfiguration alloc] initWithMediaSourceIdentifier:MLMediaSourceApertureIdentifier
AppleMediaLibraryMediaType:mediaType
identifiersOfNonUserCreatedGroups:identifiersOfNonUserCreatedGroups];
};
@implementation IMBApertureParserConfiguration
/**
Hardcoded library name.
*/
- (NSString *)libraryName
{
return @"Aperture";
}
- (NSURL *)sourceURLForMediaGroup:(MLMediaGroup *)mediaGroup
{
return mediaGroup.attributes[@"URL"];
}
- (BOOL)shouldUseMediaGroup:(MLMediaGroup *)mediaGroup
{
NSSet *unqualifiedGroupIdentifiers = [NSSet setWithObjects:
kIMBApertureMediaGroupIdentifierAllProjects,
kIMBApertureMediaGroupIdentifierLastViewedEvent,
nil];
return (![unqualifiedGroupIdentifiers containsObject:mediaGroup.identifier]);
}
- (BOOL)shouldReuseMediaObjectsOfParentGroupForGroup:(MLMediaGroup *)mediaGroup
{
NSSet *qualifiedGroupIdentifiers = [NSSet set];
return [qualifiedGroupIdentifiers containsObject:mediaGroup.identifier];
}
/**
Returns whether group (aka node) is populated with child group objects rather than real media objects.
@discussion This default implementation returns NO.
*/
- (BOOL)shouldUseChildGroupsAsMediaObjectsForMediaGroup:(MLMediaGroup *)mediaGroup
{
NSSet *qualifiedGroupIdentifiers = [NSSet setWithObjects:
kIMBApertureMediaGroupIdentifierFaces,
nil];
return [qualifiedGroupIdentifiers containsObject:mediaGroup.identifier];
}
- (MLMediaObject *)keyMediaObjectForMediaGroup:(MLMediaGroup *)mediaGroup
{
NSString *keyPhotoKey = mediaGroup.attributes[@"KeyPhotoKey"];
if (keyPhotoKey) {
return [self.mediaSource mediaObjectForIdentifier:keyPhotoKey];
} else {
return [super keyMediaObjectForMediaGroup:mediaGroup];
}
return nil;
}
- (NSString *)countFormatForGroup:(MLMediaGroup *)mediaGroup plural:(BOOL)plural
{
NSDictionary *typeIdentifierToLocalizationKey =
@{
@"com.apple.Aperture.FacesAlbum" : @"IMBFaceObjectViewController.countFormat"
};
NSString *localizationKey = typeIdentifierToLocalizationKey[mediaGroup.typeIdentifier];
NSString *localizationKeyPostfix = plural ? @"Plural" : @"Singular";
if (localizationKey) {
localizationKey = [localizationKey stringByAppendingString:localizationKeyPostfix];
return NSLocalizedStringWithDefaultValue(localizationKey,
nil, IMBBundle(), nil,
@"Format string for object count");
}
return nil;
}
- (NSImage *)groupIconForTypeIdentifier:(NSString *)typeIdentifier highlight:(BOOL)highlight
{
// Note that for icon types starting with "v3-" we havn't yet found a matching type identifier replacement
static const IMBIconTypeMappingEntry kIconTypeMappingEntries[] =
{
// Icon Type Application Icon Name Fallback Icon Name
{@"com.apple.Aperture.PhotoStreamAlbum", @"SL-stream", @"folder", nil, nil}, // photo stream
{@"com.apple.Aperture.FacesAlbum", @"SL-faces", @"folder", nil, nil}, // faces
{@"com.apple.Aperture.PlacesAlbum", @"SL-places", @"folder", nil, nil}, // faces
{@"com.apple.Aperture.MonthAlbum", @"SL-customLast", @"folder", nil, nil}, // faces
{@"com.apple.Aperture.UserAlbum", @"SL-album", @"folder", nil, nil}, // album
{@"com.apple.Aperture.LibraryAlbums", @"SL-smartAlbum", @"folder", nil, nil}, // smart album
{@"com.apple.Aperture.UserSmartAlbum", @"SL-smartAlbum", @"folder", nil, nil}, // library **** ... 200X
{@"com.apple.Aperture.ProjectAlbum", @"SL-project", @"folder", nil, nil}, // project
{@"com.apple.Aperture.LastViewedEvent", @"SL-project", @"folder", nil, nil}, // project
{@"com.apple.Aperture.AllProjects", @"SL-allProjects", @"folder", nil, nil}, // library (top level)
{@"com.apple.Aperture.FolderAlbum", @"SL-folder", @"folder", nil, nil}, // folder
{@"v3-7", @"SL-folder", @"folder", nil, nil}, // sub-folder of project
{@"v3-8", @"SL-book", @"folder", nil, nil}, // book
{@"v3-9", @"SL-webpage", @"folder", nil, nil}, // web gallery
{@"v3-9", @"Project_I_WebGallery", @"folder", nil, nil}, // web gallery (alternate image)
{@"v3-10", @"SL-webJournal", @"folder", nil, nil}, // web journal
{@"v3-11", @"SL-lightTable", @"folder", nil, nil}, // light table
{@"v3-13", @"sl-icon-small_webGallery", @"folder", nil, nil}, // smart web gallery
{@"v3-19", @"SL-slideshow", @"folder", nil, nil}, // slideshow
{@"com.apple.Aperture.AllPhotos", @"SL-photos", @"folder", nil, nil}, // photos
{@"com.apple.Aperture.Flagged", @"SL-flag", @"folder", nil, nil}, // flagged
{@"v3-96", @"SL-smartLibrary", @"folder", nil, nil}, // library albums
{@"v3-97", @"SL-allProjects", @"folder", nil, nil}, // library
{@"v3-98", @"AppIcon.icns", @"folder", nil, nil}, // library
{@"v3-99", @"List_Icons_Library", @"folder", nil, nil}, // library (knot holding all images)
{@"com.apple.Aperture.LastImportAlbum", @"SL-LastImport", @"folder", nil, nil}, // last import
};
static const IMBIconTypeMapping kIconTypeMapping =
{
sizeof(kIconTypeMappingEntries) / sizeof(kIconTypeMappingEntries[0]),
kIconTypeMappingEntries,
@"_S"
};
// // Since icons are different for different versions of Aperture, we are adding the prefix v2- or v3-
// // to the album type so that we can store different icons (for each version) in the icon cache...
//
// NSString* type = [@"v3-" stringByAppendingString:typeIdentifier];
return [[IMBIconCache sharedIconCache] iconForType:typeIdentifier
fromBundleID:@"com.apple.Aperture"
withMappingTable:&kIconTypeMapping
highlight:highlight
considerGenericFallbackImage:NO];
}
- (NSImage *)thumbnailForObject:(IMBObject *)object baseThumbnail:(NSImage *)thumbnail
{
if ([object isKindOfClass:[IMBNodeObject class]]) {
NSString *parentGroupIdentifier = object.preliminaryMetadata[@"Parent"];
if ([parentGroupIdentifier isEqualToString:kIMBApertureMediaGroupIdentifierFaces]) {
return [[IMBImageProcessor sharedInstance] imageSquaredWithCornerRadius:255 fromImage:thumbnail];
}
}
return thumbnail;
}
/**
*/
- (NSImage *)thumbnailForMediaGroup:(MLMediaGroup *)mediaGroup baseThumbnail:(NSImage *)thumbnail
{
NSString *groupTypeIdentifier = mediaGroup.typeIdentifier;
CGFloat cornerRadius = 0;
if ([groupTypeIdentifier isEqualToString:kIMBApertureMediaGroupTypeIdentifierFaces]) {
cornerRadius = 255.0;
}
thumbnail = [[IMBImageProcessor sharedInstance] imageSquaredWithCornerRadius:cornerRadius fromImage:thumbnail];
return thumbnail;
}
/**
*/
- (NSImage *)thumbnailForMediaGroup:(MLMediaGroup *)mediaGroup
{
MLMediaObject *keyMediaObject = [self keyMediaObjectForMediaGroup:mediaGroup];
if (keyMediaObject) {
NSImage *baseThumbnail = [self thumbnailForMediaObject:keyMediaObject];
return [self thumbnailForMediaGroup:mediaGroup baseThumbnail:baseThumbnail];
}
return nil;
}
@end