Skip to content
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

google takeout improvements #409

Merged
merged 18 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
465 changes: 249 additions & 216 deletions browser/gp/googlephotos.go

Large diffs are not rendered by default.

115 changes: 103 additions & 12 deletions browser/gp/googlephotos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,94 @@ import (
"github.com/simulot/immich-go/immich"
)

func Test_matchEditedName(t *testing.T) {
func Test_matchers(t *testing.T) {
tests := []struct {
jsonName string
fileName string
want bool
want string
}{
{
jsonName: "PXL_20211013_220651983.jpg.json",
fileName: "PXL_20211013_220651983.jpg",
want: "normalMatch",
},
{
jsonName: "PXL_20220405_090123740.PORTRAIT.jpg.json",
fileName: "PXL_20220405_090123740.PORTRAIT-modifié.jpg",
want: true,
want: "matchEditedName",
},
{
jsonName: "PXL_20220405_090123740.PORTRAIT.jpg.json",
fileName: "PXL_20220405_100123740.PORTRAIT-modifié.jpg",
want: false,
want: "",
},
{
jsonName: "DSC_0238.JPG.json",
fileName: "DSC_0238.JPG",
want: true,
want: "normalMatch",
},
{
jsonName: "DSC_0238.JPG(1).json",
fileName: "DSC_0238(1).JPG",
want: "matchDuplicateInYear",
},
{
jsonName: "IMG_2710.HEIC(1).json",
fileName: "IMG_2710(1).HEIC",
want: "matchDuplicateInYear",
},
{
jsonName: "PXL_20231118_035751175.MP.jpg.json",
fileName: "PXL_20231118_035751175.MP.jpg",
want: "normalMatch",
},
{
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",
},
{
jsonName: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jp.json",
fileName: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg",
want: "livePhotoMatch",
},
{
jsonName: "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋.json",
fileName: "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg",
want: "matchWithOneCharOmitted",
},
{
jsonName: "Backyard_ceremony_wedding_photography_xxxxxxx_(494).json",
fileName: "Backyard_ceremony_wedding_photography_xxxxxxx_m(494).jpg",
want: "matchVeryLongNameWithNumber",
},
{
jsonName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json",
fileName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_P.jpg",
want: "matchWithOneCharOmitted",
},
{
jsonName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json",
fileName: "original_1d4caa6f-16c6-4c3d-901b-9387de10e528_P(1).jpg",
want: "matchForgottenDuplicates",
},
// {
// jsonName: "DSC_0238.JPG.json",
// fileName: "DSC_0238(1).JPG",
// want: false,
// },
}
for _, tt := range tests {
t.Run(tt.fileName, func(t *testing.T) {
if got := matchEditedName(tt.jsonName, tt.fileName, immich.DefaultSupportedMedia); got != tt.want {
t.Errorf("matchEditedName() = %v, want %v", got, tt.want)
matcher := ""
for _, m := range matchers {
if m.fn(tt.jsonName, tt.fileName, immich.DefaultSupportedMedia) {
matcher = m.name
break
}
}
if matcher != tt.want {
t.Errorf("matcher is '%s', want %v", matcher, tt.want)
}
})
}
Expand Down Expand Up @@ -125,3 +182,37 @@ func Test_matchForgottenDuplicates(t *testing.T) {
})
}
}

/* 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)
}
}
2 changes: 1 addition & 1 deletion browser/gp/testgp_bigread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestReadBigTakeout(t *testing.T) {
return
}
cnt := 0
fsyss, err := fshelper.ParsePath(m, true)
fsyss, err := fshelper.ParsePath(m)
to, err := NewTakeout(context.Background(), j, immich.DefaultSupportedMedia, fsyss...)
if err != nil {
t.Error(err)
Expand Down
Loading