-
-
Notifications
You must be signed in to change notification settings - Fork 111
add support for icloud takeouts #822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
imgName | ||
photo2.jpg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
imgName | ||
photo1.jpg | ||
photo2.jpg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
imgName | ||
photo1.jpg | ||
photo2.jpg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
imgName,fileChecksum,favorite,hidden,deleted,originalCreationDate,viewCount,importDate | ||
photo_wo_exif.jpg,ignored-checksum,no,no,no,"Friday October 06,2023 12:11 PM GMT",10,"Friday October 06,2023 12:11 PM GMT" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package folder | ||
|
||
import ( | ||
"encoding/csv" | ||
"errors" | ||
"io/fs" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/simulot/immich-go/internal/assets" | ||
"github.com/simulot/immich-go/internal/gen" | ||
) | ||
|
||
type iCloudMeta struct { | ||
albums []assets.Album | ||
originalCreationDate time.Time | ||
} | ||
|
||
func UseICloudAlbum(m *gen.SyncMap[string, iCloudMeta], fsys fs.FS, filename string) (string, error) { | ||
file, err := fsys.Open(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
|
||
albumName := strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename)) | ||
reader := csv.NewReader(file) | ||
records, err := reader.ReadAll() | ||
if err != nil { | ||
return "", errors.Join(err, errors.New("failed to read all csv records")) | ||
} | ||
for _, record := range records[1:] { | ||
if len(record) != 1 { | ||
return "", errors.Join(err, errors.New("invalid record")) | ||
} | ||
fileName := record[0] | ||
meta, _ := m.Load(fileName) | ||
simulot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
meta.albums = append(meta.albums, assets.Album{Title: albumName}) | ||
m.Store(fileName, meta) | ||
} | ||
|
||
return albumName, nil | ||
} | ||
|
||
// Example: | ||
// imgName,fileChecksum,favorite,hidden,deleted,originalCreationDate,viewCount,importDate | ||
// IMG_7938.HEIC,AfQj57ORF2JIumUCjO+PawZ9nqPg,no,no,no,"Saturday June 4,2022 12:11 PM GMT",10,"Saturday June 4,2022 12:11 PM GMT" | ||
func UseICloudPhotoDetails(m *gen.SyncMap[string, iCloudMeta], fsys fs.FS, filename string) error { | ||
file, err := fsys.Open(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
reader := csv.NewReader(file) | ||
records, err := reader.ReadAll() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't be the file too huge to be read in memory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at my own icloud takeout I see a lot of "Photo Details - n.csv" files. Non of them has more than 1500 lines. Its not clear to me what logic they apply for the splitting of the files but none of them are too big. |
||
if err != nil { | ||
return errors.Join(err, errors.New("failed to read all csv records")) | ||
} | ||
// skip header | ||
for _, record := range records[1:] { | ||
if len(record) != 8 { | ||
return errors.Join(err, errors.New("invalid record")) | ||
} | ||
fileName := record[0] | ||
originalCreationDate := record[5] | ||
t, err := time.Parse("Monday January 2,2006 15:04 PM GMT", originalCreationDate) | ||
if err != nil { | ||
return errors.Join(err, errors.New("invalid original creation date")) | ||
} | ||
meta, _ := m.Load(fileName) | ||
meta.originalCreationDate = t | ||
m.Store(fileName, meta) | ||
} | ||
|
||
return nil | ||
} |
Uh oh!
There was an error while loading. Please reload this page.