@@ -42,6 +42,7 @@ type LocalAssetBrowser struct {
42
42
requiresDateInformation bool // true if we need to read the date from the file for the options
43
43
picasaAlbums * gen.SyncMap [string , PicasaAlbum ] // ap[string]PicasaAlbum
44
44
icloudMetas * gen.SyncMap [string , iCloudMeta ]
45
+ icloudMetaPass bool
45
46
}
46
47
47
48
func NewLocalFiles (ctx context.Context , l * fileevent.Recorder , flags * ImportFolderOptions , fsyss ... fs.FS ) (* LocalAssetBrowser , error ) {
@@ -64,6 +65,7 @@ func NewLocalFiles(ctx context.Context, l *fileevent.Recorder, flags *ImportFold
64
65
}
65
66
if flags .ICloudTakeout {
66
67
la .icloudMetas = gen .NewSyncMap [string , iCloudMeta ]()
68
+ la .icloudMetaPass = true
67
69
}
68
70
69
71
if flags .InfoCollector == nil {
@@ -101,6 +103,14 @@ func (la *LocalAssetBrowser) Browse(ctx context.Context) chan *assets.Group {
101
103
gOut := make (chan * assets.Group )
102
104
go func () {
103
105
defer close (gOut )
106
+ // two passes for icloud takouts
107
+ if la .icloudMetaPass {
108
+ for _ , fsys := range la .fsyss {
109
+ la .concurrentParseDir (ctx , fsys , "." , gOut )
110
+ }
111
+ la .wg .Wait ()
112
+ la .icloudMetaPass = false
113
+ }
104
114
for _ , fsys := range la .fsyss {
105
115
la .concurrentParseDir (ctx , fsys , "." , gOut )
106
116
}
@@ -152,42 +162,55 @@ func (la *LocalAssetBrowser) parseDir(ctx context.Context, fsys fs.FS, dir strin
152
162
continue
153
163
}
154
164
155
- if la .flags .BannedFiles .Match (name ) {
156
- la .log .Record (ctx , fileevent .DiscoveredDiscarded , fshelper .FSName (fsys , entry .Name ()), "reason" , "banned file" )
157
- continue
165
+ // process csv files on icloud meta pass
166
+ if la .icloudMetaPass && ext == icloudMetadataExt {
167
+ if strings .HasSuffix (strings .ToLower (dir ), "albums" ) {
168
+ a , err := UseICloudAlbum (la .icloudMetas , fsys , name )
169
+ if err != nil {
170
+ la .log .Record (ctx , fileevent .Error , fshelper .FSName (fsys , name ), "error" , err .Error ())
171
+ } else {
172
+ la .log .Log ().Info ("iCloud album detected" , "file" , fshelper .FSName (fsys , name ), "album" , a )
173
+ }
174
+ continue
175
+ }
176
+ if la .flags .ICloudMemoriesAsAlbums && strings .HasSuffix (strings .ToLower (dir ), "memories" ) {
177
+ a , err := UseICloudMemory (la .icloudMetas , fsys , name )
178
+ if err != nil {
179
+ la .log .Record (ctx , fileevent .Error , fshelper .FSName (fsys , name ), "error" , err .Error ())
180
+ } else {
181
+ la .log .Log ().Info ("iCloud memory detected" , "file" , fshelper .FSName (fsys , name ), "album" , a )
182
+ }
183
+ continue
184
+ }
185
+ // iCloud photo details (csv). File name pattern: "Photo Details.csv"
186
+ if strings .HasPrefix (strings .ToLower (base ), "photo details" ) {
187
+ err := UseICloudPhotoDetails (la .icloudMetas , fsys , name )
188
+ if err != nil {
189
+ la .log .Record (ctx , fileevent .Error , fshelper .FSName (fsys , name ), "error" , err .Error ())
190
+ } else {
191
+ la .log .Log ().Info ("iCloud photo details detected" , "file" , fshelper .FSName (fsys , name ))
192
+ }
193
+ continue
194
+ }
158
195
}
159
196
160
- if la . flags . SupportedMedia . IsUseLess ( name ) {
161
- la .log . Record ( ctx , fileevent . DiscoveredUseless , fshelper . FSName ( fsys , entry . Name ()))
197
+ // skip all other files in icloud meta pass
198
+ if la .icloudMetaPass {
162
199
continue
163
200
}
164
201
165
- // iCloud albums
166
- if la .flags .ICloudTakeout && strings .ToLower (dir ) == "albums" && ext == icloudMetadataExt {
167
- a , err := UseICloudAlbum (la .icloudMetas , fsys , name )
168
- if err != nil {
169
- la .log .Record (ctx , fileevent .Error , fshelper .FSName (fsys , name ), "error" , err .Error ())
170
- } else {
171
- la .log .Log ().Info ("iCloud album detected" , "file" , fshelper .FSName (fsys , name ), "album" , a )
172
- }
202
+ // silently ignore .csv files after icloud meta pass
203
+ if la .flags .ICloudTakeout && ! la .icloudMetaPass && ext == icloudMetadataExt {
173
204
continue
174
205
}
175
206
176
- // iCloud memories
177
- if la .flags .ICloudTakeout && strings .ToLower (dir ) == "memories" && ext == ".csv" {
178
- // ignore
179
- la .log .Record (ctx , fileevent .DiscoveredDiscarded , fshelper .FSName (fsys , name ), "reason" , "iCloud memories ignored" )
207
+ if la .flags .BannedFiles .Match (name ) {
208
+ la .log .Record (ctx , fileevent .DiscoveredDiscarded , fshelper .FSName (fsys , entry .Name ()), "reason" , "banned file" )
180
209
continue
181
210
}
182
211
183
- // iCloud photo details (csv). File name pattern: "Photo Details.csv"
184
- if la .flags .ICloudTakeout && strings .HasPrefix (strings .ToLower (base ), "photo details" ) && ext == ".csv" {
185
- err := UseICloudPhotoDetails (la .icloudMetas , fsys , name )
186
- if err != nil {
187
- la .log .Record (ctx , fileevent .Error , fshelper .FSName (fsys , name ), "error" , err .Error ())
188
- } else {
189
- la .log .Log ().Info ("iCloud photo details detected" , "file" , fshelper .FSName (fsys , name ))
190
- }
212
+ if la .flags .SupportedMedia .IsUseLess (name ) {
213
+ la .log .Record (ctx , fileevent .DiscoveredUseless , fshelper .FSName (fsys , entry .Name ()))
191
214
continue
192
215
}
193
216
0 commit comments