diff --git a/adapters/googlePhotos/googlephotos.go b/adapters/googlePhotos/googlephotos.go index 6ce231e..990a8a5 100644 --- a/adapters/googlePhotos/googlephotos.go +++ b/adapters/googlePhotos/googlephotos.go @@ -322,13 +322,10 @@ var matchers = []struct { name string fn matcherFn }{ - {name: "normalMatch", fn: normalMatch}, - // {name: "livePhotoMatch", fn: livePhotoMatch}, - {name: "matchWithOneCharOmitted", fn: matchWithOneCharOmitted}, - {name: "matchVeryLongNameWithNumber", fn: matchVeryLongNameWithNumber}, - {name: "matchDuplicateInYear", fn: matchDuplicateInYear}, - {name: "matchEditedName", fn: matchEditedName}, + {name: "matchFastTrack", fn: matchFastTrack}, + {name: "matchNormal", fn: matchNormal}, {name: "matchForgottenDuplicates", fn: matchForgottenDuplicates}, + {name: "matchEditedName", fn: matchEditedName}, } func (to *Takeout) solvePuzzle(ctx context.Context) error { @@ -468,7 +465,9 @@ func (to *Takeout) handleDir(ctx context.Context, dir string, gOut chan *assets. if to.flags.PartnerSharedAlbum != "" && a.FromPartner { a.Albums = append(a.Albums, assets.Album{Title: to.flags.PartnerSharedAlbum}) } - a.FromApplication.Albums = a.Albums + if a.FromApplication != nil { + a.FromApplication.Albums = a.Albums + } } // If the asset has no GPS information, but the album has, use the album's location if a.Latitude == 0 && a.Longitude == 0 { @@ -580,6 +579,9 @@ func (to *Takeout) filterOnMetadata(ctx context.Context, a *assets.Asset) fileev if to.flags.ImportFromAlbum != "" { keep := false dir := path.Dir(a.File.Name()) + if dir == "." { + dir = "" + } if album, ok := to.albums[dir]; ok { keep = keep || album.Title == to.flags.ImportFromAlbum } diff --git a/adapters/googlePhotos/matcher_test.go b/adapters/googlePhotos/matcher_test.go index 38c74ad..096673d 100644 --- a/adapters/googlePhotos/matcher_test.go +++ b/adapters/googlePhotos/matcher_test.go @@ -6,124 +6,6 @@ import ( "github.com/simulot/immich-go/internal/filetypes" ) -func Test_matchVeryLongNameWithNumber(t *testing.T) { - tests := []struct { - jsonName string - fileName string - want bool - }{ - { - jsonName: "Backyard_ceremony_wedding_photography_xxxxxxx_(494).json", - fileName: "Backyard_ceremony_wedding_photography_xxxxxxx_m(494).jpg", - want: true, - }, - { - jsonName: "Backyard_ceremony_wedding_photography_xxxxxxx_(494).json", - fileName: "Backyard_ceremony_wedding_photography_xxxxxxx_m(185).jpg", - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.fileName, func(t *testing.T) { - if got := matchVeryLongNameWithNumber(tt.jsonName, tt.fileName, filetypes.DefaultSupportedMedia); got != tt.want { - t.Errorf("matchVeryLongNameWithNumber() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_matchDuplicateInYear(t *testing.T) { - tests := []struct { - name string - jsonName string - fileName string - want bool - }{ - { - name: "match", - jsonName: "IMG_3479.JPG(2).json", - fileName: "IMG_3479(2).JPG", - want: true, - }, - { - name: "doesn't match", - jsonName: "IMG_3479.JPG(2).json", - fileName: "IMG_3479(3).JPG", - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := matchDuplicateInYear(tt.jsonName, tt.fileName, filetypes.DefaultSupportedMedia); got != tt.want { - t.Errorf("matchDuplicateInYear() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_matchForgottenDuplicates(t *testing.T) { - tests := []struct { - name string - jsonName string - fileName string - want bool - }{ - { - name: "match1", - jsonName: "1556189729458-8d2e2d13-bca5-467e-a242-9e4cb238.json", - fileName: "1556189729458-8d2e2d13-bca5-467e-a242-9e4cb238e.jpg", - want: true, - }, - { - name: "match2", - jsonName: "1556189729458-8d2e2d13-bca5-467e-a242-9e4cb238.json", - fileName: "1556189729458-8d2e2d13-bca5-467e-a242-9e4cb238e(1).jpg", - want: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := matchForgottenDuplicates(tt.jsonName, tt.fileName, filetypes.DefaultSupportedMedia); got != tt.want { - t.Errorf("matchDuplicateInYear() = %v, want %v", got, tt.want) - } - }) - } -} - -/* indexes, but false -goos: linux -goarch: amd64 -pkg: github.com/simulot/immich-go/browser/gp -cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz -Benchmark_matchDuplicateInYear-12 27067428 52.06 ns/op 0 B/op 0 allocs/op -PASS -ok github.com/simulot/immich-go/browser/gp 1.458s - -goos: linux -goarch: amd64 -pkg: github.com/simulot/immich-go/browser/gp -cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz -Benchmark_matchDuplicateInYear-12 881652 1491 ns/op 240 B/op 4 allocs/op -PASS -ok github.com/simulot/immich-go/browser/gp 1.332s - - -goos: linux -goarch: amd64 -pkg: github.com/simulot/immich-go/browser/gp -cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz -Benchmark_matchDuplicateInYear-12 25737067 43.88 ns/op 0 B/op 0 allocs/op -PASS -ok github.com/simulot/immich-go/browser/gp 1.180s - -*/ - -func Benchmark_matchDuplicateInYear(b *testing.B) { - for i := 0; i < b.N; i++ { - matchDuplicateInYear("IMG_3479.JPG(2).json", "IMG_3479(2).JPG", nil) - } -} - func Test_matchers(t *testing.T) { tests := []struct { jsonName string @@ -133,7 +15,7 @@ func Test_matchers(t *testing.T) { { jsonName: "PXL_20211013_220651983.jpg.json", fileName: "PXL_20211013_220651983.jpg", - want: "normalMatch", + want: "matchFastTrack", }, { jsonName: "PXL_20211013_220651983.jpg.json", @@ -147,64 +29,80 @@ func Test_matchers(t *testing.T) { }, { jsonName: "PXL_20220405_090123740.PORTRAIT.jpg.json", - fileName: "PXL_20220405_100123740.PORTRAIT-modifiΓ©.jpg", + fileName: "PXL_20220405_090123741.PORTRAIT-modifiΓ©.jpg", want: "", }, { - jsonName: "DSC_0238.JPG.json", - fileName: "DSC_0238.JPG", - want: "normalMatch", + jsonName: "DSC_0100.JPG.json", + fileName: "DSC_0100.JPG", + want: "matchFastTrack", + }, + + { + jsonName: "DSC_0101.JPG(1).json", + fileName: "DSC_0101(1).JPG", + want: "matchNormal", }, { - jsonName: "DSC_0238.JPG(1).json", - fileName: "DSC_0238(1).JPG", - want: "matchDuplicateInYear", + jsonName: "DSC_0102.JPG(2).json", + fileName: "DSC_0102(1).JPG", + want: "", + }, + + { + jsonName: "DSC_0103.JPG(1).json", + fileName: "DSC_0103.JPG", + want: "", }, + { - jsonName: "DSC_0238.JPG(1).json", - fileName: "DSC_0238.JPG", + jsonName: "DSC_0104.JPG.json", + fileName: "DSC_0104(1).JPG", want: "", }, + { jsonName: "IMG_2710.HEIC(1).json", fileName: "IMG_2710(1).HEIC", - want: "matchDuplicateInYear", + want: "matchNormal", }, { jsonName: "PXL_20231118_035751175.MP.jpg.json", fileName: "PXL_20231118_035751175.MP.jpg", - want: "normalMatch", + want: "matchFastTrack", }, - // { // MP are now ignored - // jsonName: "PXL_20231118_035751175.MP.jpg.json", - // fileName: "PXL_20231118_035751175.MP", - // want: "livePhotoMatch", - // }, { jsonName: "PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGIN.json", fileName: "PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg", - want: "matchWithOneCharOmitted", + want: "matchNormal", }, { jsonName: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jp.json", fileName: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg", - want: "matchWithOneCharOmitted", + want: "matchNormal", }, + { jsonName: "πŸ˜€πŸ˜ƒπŸ˜„πŸ˜πŸ˜†πŸ˜…πŸ˜‚πŸ€£πŸ₯²β˜ΊοΈπŸ˜ŠπŸ˜‡πŸ™‚πŸ™ƒπŸ˜‰πŸ˜ŒπŸ˜πŸ₯°πŸ˜˜πŸ˜—πŸ˜™πŸ˜šπŸ˜‹.json", fileName: "πŸ˜€πŸ˜ƒπŸ˜„πŸ˜πŸ˜†πŸ˜…πŸ˜‚πŸ€£πŸ₯²β˜ΊοΈπŸ˜ŠπŸ˜‡πŸ™‚πŸ™ƒπŸ˜‰πŸ˜ŒπŸ˜πŸ₯°πŸ˜˜πŸ˜—πŸ˜™πŸ˜šπŸ˜‹πŸ˜›.jpg", - want: "matchWithOneCharOmitted", + want: "matchNormal", }, { jsonName: "Backyard_ceremony_wedding_photography_xxxxxxx_(494).json", fileName: "Backyard_ceremony_wedding_photography_xxxxxxx_m(494).jpg", - want: "matchVeryLongNameWithNumber", + want: "matchNormal", + }, + { + jsonName: "Backyard_ceremony_wedding_photography_xxxxxxx_(494).json", + fileName: "Backyard_ceremony_wedding_photography_xxxxxxx_m(185).jpg", + want: "", }, { jsonName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json", fileName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_P.jpg", - want: "matchWithOneCharOmitted", + want: "matchNormal", }, + { jsonName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json", fileName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_P(1).jpg", @@ -213,18 +111,32 @@ func Test_matchers(t *testing.T) { { // #405 jsonName: "PXL_20210102_221126856.MP~2.jpg.json", fileName: "PXL_20210102_221126856.MP~2.jpg", - want: "normalMatch", + want: "matchFastTrack", + }, + + { //#613 + // 13039_327707840323_537645323_9470255_27214_n.j.json + // 13039_327707840323_537645323_9470255_27214_n.jpg + + jsonName: "13039_327707840323_537645323_9470255_27214_n.j(1).json", + fileName: "13039_327707840323_537645323_9470255_27214_n(1).jpg", + want: "matchNormal", }, - // { // #405 - // jsonName: "PXL_20210102_221126856.MP~2.jpg.json", - // fileName: "PXL_20210102_221126856.MP~2", - // want: "livePhotoMatch", - // }, } for _, tt := range tests { t.Run(tt.fileName, func(t *testing.T) { matcher := "" - for _, m := range matchers { + tmatchers := []struct { + name string + fn matcherFn + }{ + {name: "matchFastTrack", fn: matchFastTrack}, + {name: "matchNormal", fn: matchNormal}, + {name: "matchForgottenDuplicates", fn: matchForgottenDuplicates}, + {name: "matchEditedName", fn: matchEditedName}, + } + + for _, m := range tmatchers { if m.fn(tt.jsonName, tt.fileName, filetypes.DefaultSupportedMedia) { matcher = m.name break diff --git a/adapters/googlePhotos/matchers.go b/adapters/googlePhotos/matchers.go index ae8911e..5ee821e 100644 --- a/adapters/googlePhotos/matchers.go +++ b/adapters/googlePhotos/matchers.go @@ -2,173 +2,64 @@ package gp import ( "path" + "strconv" "strings" "unicode/utf8" "github.com/simulot/immich-go/internal/filetypes" ) -// normalMatch -// -// PXL_20230922_144936660.jpg.json -// PXL_20230922_144936660.jpg -func normalMatch(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { - base := strings.TrimSuffix(jsonName, path.Ext(jsonName)) - return base == fileName -} - -// livePhotoMatch -// 20231227_152817.jpg.json -// 20231227_152817.MP4 -// -// PXL_20231118_035751175.MP.jpg.json -// PXL_20231118_035751175.MP.jpg -// PXL_20231118_035751175.MP -// func livePhotoMatch(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { -// fileExt := path.Ext(fileName) -// fileName = strings.TrimSuffix(fileName, fileExt) -// base := strings.TrimSuffix(jsonName, path.Ext(jsonName)) -// base = strings.TrimSuffix(base, path.Ext(base)) -// if base == fileName { -// return true -// } -// base = strings.TrimSuffix(base, path.Ext(base)) -// return base == fileName -// } - -// matchWithOneCharOmitted -// -// PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGIN.json -// PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg -// -// 05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jp.json <-- match also with LivePhoto matcher -// 05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg -// -// πŸ˜€πŸ˜ƒπŸ˜„πŸ˜πŸ˜†πŸ˜…πŸ˜‚πŸ€£πŸ₯²β˜ΊοΈπŸ˜ŠπŸ˜‡πŸ™‚πŸ™ƒπŸ˜‰πŸ˜ŒπŸ˜πŸ₯°πŸ˜˜πŸ˜—πŸ˜™πŸ˜šπŸ˜‹.json -// πŸ˜€πŸ˜ƒπŸ˜„πŸ˜πŸ˜†πŸ˜…πŸ˜‚πŸ€£πŸ₯²β˜ΊοΈπŸ˜ŠπŸ˜‡πŸ™‚πŸ™ƒπŸ˜‰πŸ˜ŒπŸ˜πŸ₯°πŸ˜˜πŸ˜—πŸ˜™πŸ˜šπŸ˜‹πŸ˜›.jpg - -func matchWithOneCharOmitted(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { - baseJSON := strings.TrimSuffix(jsonName, path.Ext(jsonName)) - ext := path.Ext(baseJSON) - if sm.IsExtensionPrefix(ext) { - baseJSON = strings.TrimSuffix(baseJSON, ext) - } - fileName = strings.TrimSuffix(fileName, path.Ext(fileName)) - if fileName == baseJSON { - return true - } - if strings.HasPrefix(fileName, baseJSON) { - a, b := utf8.RuneCountInString(fileName), utf8.RuneCountInString(baseJSON) - if a-b <= 1 { - return true - } - } - return false -} - -// matchVeryLongNameWithNumber -// -// Backyard_ceremony_wedding_photography_xxxxxxx_(494).json -// Backyard_ceremony_wedding_photography_xxxxxxx_m(494).jpg -func matchVeryLongNameWithNumber(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { +func matchFastTrack(jsonName string, fileName string, _ filetypes.SupportedMedia) bool { + // fast track: if the file name is the same as the JSON name jsonName = strings.TrimSuffix(jsonName, path.Ext(jsonName)) - - p1JSON := strings.Index(jsonName, "(") - if p1JSON < 0 { - return false - } - p2JSON := strings.Index(jsonName, ")") - if p2JSON < 0 || p2JSON != len(jsonName)-1 { - return false - } - p1File := strings.Index(fileName, "(") - if p1File < 0 || p1File != p1JSON+1 { - return false - } - if jsonName[:p1JSON] != fileName[:p1JSON] { - return false - } - p2File := strings.Index(fileName, ")") - return jsonName[p1JSON+1:p2JSON] == fileName[p1File+1:p2File] + return jsonName == fileName } -// matchDuplicateInYear -// -// IMG_3479.JPG(2).json -// IMG_3479(2).JPG -// +func matchNormal(jsonName string, fileName string, _ filetypes.SupportedMedia) bool { + // Extract the index from the file name + fileName, fileIndex := getFileIndex(fileName) + // Extract the index from the JSON name + jsonName, jsonIndex := getFileIndex(jsonName) -// Fast implementation, but does't work with live photos -func matchDuplicateInYear(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { - jsonName = strings.TrimSuffix(jsonName, path.Ext(jsonName)) - p1JSON := strings.Index(jsonName, "(") - if p1JSON < 1 { - return false - } - p1File := strings.Index(fileName, "(") - if p1File < 0 { + // Check if the indexes are the same + if fileIndex != jsonIndex { return false } - jsonExt := path.Ext(jsonName[:p1JSON]) - p2JSON := strings.Index(jsonName, ")") - if p2JSON < 0 || p2JSON != len(jsonName)-1 { - return false - } - - p2File := strings.Index(fileName, ")") - if p2File < 0 || p2File < p1File { - return false - } - - fileExt := path.Ext(fileName) - - if fileExt != jsonExt { - return false - } - - jsonBase := strings.TrimSuffix(jsonName[:p1JSON], path.Ext(jsonName[:p1JSON])) - - if jsonBase != fileName[:p1File] { - return false - } - - if fileName[p1File+1:p2File] != jsonName[p1JSON+1:p2JSON] { - return false + // Check if the file name is the same as the JSON name + jsonName = strings.TrimSuffix(jsonName, path.Ext(jsonName)) + if jsonName == fileName { + return true } - return true -} - -/* -// Regexp implementation, work with live photos, 10 times slower -var ( - reDupInYearJSON = regexp.MustCompile(`(.*)\.(.{2,4})\((\d+)\)\..{2,4}$`) - reDupInYearFile = regexp.MustCompile(`(.*)\((\d+)\)\..{2,4}$`) -) - -func matchDuplicateInYear(jsonName string, fileName string, sm immich.SupportedMedia) bool { - mFile := reDupInYearFile.FindStringSubmatch(fileName) - if len(mFile) < 3 { - return false - } - mJSON := reDupInYearJSON.FindStringSubmatch(jsonName) - if len(mJSON) < 4 { - return false - } - if mFile[1] == mJSON[1] && mFile[2] == mJSON[3] { - return true + if len(fileName) > 46 { + if utf8.RuneCountInString(fileName) > 46 { + fileName = string([]rune(fileName)[:46]) + if fileName == jsonName { + return true + } + } else { + fileName = strings.TrimSuffix(fileName, path.Ext(fileName)) + _, size := utf8.DecodeLastRuneInString(fileName) + fileName = fileName[:len(fileName)-size] + if fileName == jsonName { + return true + } + } } return false } -*/ // matchEditedName // PXL_20220405_090123740.PORTRAIT.jpg.json // PXL_20220405_090123740.PORTRAIT.jpg // PXL_20220405_090123740.PORTRAIT-modifiΓ©.jpg +// but not DSC_0104.JPG.json with DSC_0104(1).JPG func matchEditedName(jsonName string, fileName string, sm filetypes.SupportedMedia) bool { + if _, index := getFileIndex(fileName); index != "" { + return false + } base := strings.TrimSuffix(jsonName, path.Ext(jsonName)) ext := path.Ext(base) if ext != "" && sm.IsMedia(ext) { @@ -179,8 +70,6 @@ func matchEditedName(jsonName string, fileName string, sm filetypes.SupportedMed return false } -// TODO: This one interferes with matchVeryLongNameWithNumber - // matchForgottenDuplicates // "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json" // original_1d4caa6f-16c6-4c3d-901b-9387de10e528_P.jpg @@ -197,3 +86,18 @@ func matchForgottenDuplicates(jsonName string, fileName string, sm filetypes.Sup } return false } + +func getFileIndex(name string) (string, string) { + // Extract the index from the file name + p1File := strings.LastIndex(name, "(") + if p1File >= 0 { + p2File := strings.LastIndex(name, ")") + if p2File >= 0 && p2File > p1File { + fileIndex := name[p1File+1 : p2File] + if _, err := strconv.Atoi(fileIndex); err == nil { + return name[:p1File] + name[p2File+1:], fileIndex + } + } + } + return name, "" +} diff --git a/internal/e2eTests/upload/e2e_from_folder_test.go b/internal/e2eTests/upload/e2e_from_folder_test.go index 61bf92b..c682e3b 100644 --- a/internal/e2eTests/upload/e2e_from_folder_test.go +++ b/internal/e2eTests/upload/e2e_from_folder_test.go @@ -18,83 +18,6 @@ import ( "golang.org/x/exp/rand" ) -func TestResetImmich(t *testing.T) { - e2e.InitMyEnv() - e2e.ResetImmich(t) -} - -func TestUploadFromGooglePhotos(t *testing.T) { - e2e.InitMyEnv() - e2e.ResetImmich(t) - - ctx := context.Background() - - c, a := cmd.RootImmichGoCommand(ctx) - c.SetArgs([]string{ - "upload", "from-google-photos", - "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), - "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), - // "--no-ui", - e2e.MyEnv("IMMICHGO_TESTFILES") + "/demo takeout/Takeout", - }) - - // let's start - err := c.ExecuteContext(ctx) - if err != nil && a.Log().GetSLog() != nil { - a.Log().Error(err.Error()) - } -} - -func TestUploadFromGooglePhotosZipped(t *testing.T) { - e2e.InitMyEnv() - e2e.ResetImmich(t) - - ctx := context.Background() - - c, a := cmd.RootImmichGoCommand(ctx) - c.SetArgs([]string{ - "upload", "from-google-photos", - "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), - "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), - // "--no-ui", - e2e.MyEnv("IMMICHGO_TESTFILES") + "/demo takeout/zip/takeout*.zip", - }) - - // let's start - err := c.ExecuteContext(ctx) - if err != nil && a.Log().GetSLog() != nil { - a.Log().Error(err.Error()) - } -} - -func TestUploadFromFolder(t *testing.T) { - e2e.InitMyEnv() - e2e.ResetImmich(t) - tmp, list, cleanup := create_test_folder(t, 10, 50) - defer cleanup() - - ctx := context.Background() - - c, a := cmd.RootImmichGoCommand(ctx) - c.SetArgs([]string{ - "upload", "from-folder", - "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), - "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), - "--no-ui", - "--folder-as-album=FOLDER", - tmp, - }) - - // let's start - err := c.ExecuteContext(ctx) - if err != nil && a.Log().GetSLog() != nil { - a.Log().Error(err.Error()) - } - - _ = tmp - _ = list -} - // TestUploadBurstInAlbums show the immich problem when a stack is included into an album // immich version v1.123.0 func TestUploadBurstInAlbums(t *testing.T) { diff --git a/internal/e2eTests/upload/e2e_from_google_photos_test.go b/internal/e2eTests/upload/e2e_from_google_photos_test.go new file mode 100644 index 0000000..d440ec4 --- /dev/null +++ b/internal/e2eTests/upload/e2e_from_google_photos_test.go @@ -0,0 +1,125 @@ +//go:build e2e +// +build e2e + +package upload_test + +import ( + "context" + "os" + "testing" + + "github.com/simulot/immich-go/app/cmd" + "github.com/simulot/immich-go/internal/e2eTests/e2e" +) + +func TestResetImmich(t *testing.T) { + e2e.InitMyEnv() + e2e.ResetImmich(t) +} + +func TestUploadFromGooglePhotos(t *testing.T) { + e2e.InitMyEnv() + e2e.ResetImmich(t) + + ctx := context.Background() + + c, a := cmd.RootImmichGoCommand(ctx) + c.SetArgs([]string{ + "upload", "from-google-photos", + "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), + "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), + // "--no-ui", + e2e.MyEnv("IMMICHGO_TESTFILES") + "/demo takeout/Takeout", + }) + + // let's start + err := c.ExecuteContext(ctx) + if err != nil && a.Log().GetSLog() != nil { + a.Log().Error(err.Error()) + } +} + +func TestUploadFromGooglePhotosZipped(t *testing.T) { + e2e.InitMyEnv() + e2e.ResetImmich(t) + + ctx := context.Background() + + c, a := cmd.RootImmichGoCommand(ctx) + c.SetArgs([]string{ + "upload", "from-google-photos", + "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), + "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), + // "--no-ui", + e2e.MyEnv("IMMICHGO_TESTFILES") + "/demo takeout/zip/takeout-*.zip", + }) + + // let's start + err := c.ExecuteContext(ctx) + if err != nil && a.Log().GetSLog() != nil { + a.Log().Error(err.Error()) + } +} + +func TestUploadFromGPInCurrent(t *testing.T) { + curDir, err := os.Getwd() + if err != nil { + t.Fatal(err) + return + } + + t.Cleanup(func() { + _ = os.Chdir(curDir) + }) + + e2e.InitMyEnv() + e2e.ResetImmich(t) + + ctx := context.Background() + d := e2e.MyEnv("IMMICHGO_TESTFILES") + "/demo takeout/Takeout" + err = os.Chdir(d) + if err != nil { + t.Fatal(err) + return + } + + c, a := cmd.RootImmichGoCommand(ctx) + c.SetArgs([]string{ + "upload", "from-google-photos", + "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), + "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), + "--from-album-name=Duplicated album", + // "--no-ui", + ".", + }) + + // let's start + err = c.ExecuteContext(ctx) + if err != nil && a.Log().GetSLog() != nil { + a.Log().Error(err.Error()) + } +} + +func TestUploadFromGP_issue613(t *testing.T) { + e2e.InitMyEnv() + e2e.ResetImmich(t) + + ctx := context.Background() + + c, a := cmd.RootImmichGoCommand(ctx) + c.SetArgs([]string{ + "upload", "from-google-photos", + "--server=" + e2e.MyEnv("IMMICHGO_SERVER"), + "--api-key=" + e2e.MyEnv("IMMICHGO_APIKEY"), + "-u", + "--from-album-name", "Family & friends", + // "--no-ui", + e2e.MyEnv("IMMICHGO_TESTFILES") + "/#613 Segfault on Album/Family & friends", + }) + + // let's start + err := c.ExecuteContext(ctx) + if err != nil && a.Log().GetSLog() != nil { + a.Log().Error(err.Error()) + } +}