Skip to content

Commit

Permalink
Fix for #35: weird name cases in google photos takeout: truncated nam…
Browse files Browse the repository at this point in the history
…e or jp.json
  • Loading branch information
simulot committed Oct 14, 2023
1 parent ebf8152 commit 6073872
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 52 deletions.
15 changes: 13 additions & 2 deletions assets/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,19 @@ func (to *Takeout) jsonMatchInDir(dir, base string) *googleMetaData {
}

// may be the file name has been shortened by 1 char
_, size := utf8.DecodeLastRuneInString(base)
jsonBase = jsonBase[:len(base)-size] + ".json"
// json named like verylong.jp.json
jsonBase = base
_, size := utf8.DecodeLastRuneInString(jsonBase)
jsonBase = jsonBase[:len(jsonBase)-size] + ".json"
if md, ok := list[jsonBase]; ok {
return md
}

// may the base name without the extension is shorten by 1 char
ext := path.Ext(base)
jsonBase = strings.TrimSuffix(base, ext)
_, size = utf8.DecodeLastRuneInString(jsonBase)
jsonBase = jsonBase[:len(jsonBase)-size] + ".json"
if md, ok := list[jsonBase]; ok {
return md
}
Expand Down
4 changes: 3 additions & 1 deletion assets/gp/testgp_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ func namesTruncated() *inMemFS {
}`)).
addImage("TakeoutGoogle Photos/Photos from 2023/😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg", 10).
addJSONImage("TakeoutGoogle Photos/Photos from 2023/PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGIN.json", generateJSONTitle("PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINAL.jpg")).
addImage("TakeoutGoogle Photos/Photos from 2023/PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg", 40)
addImage("TakeoutGoogle Photos/Photos from 2023/PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg", 40).
addJSONImage("TakeoutGoogle Photos/Photos from 2023/05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jp.json", generateJSONTitle("05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg")).
addImage("TakeoutGoogle Photos/Photos from 2023/05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg", 25)
}

func imagesWithoutJSON() *inMemFS {
Expand Down
48 changes: 2 additions & 46 deletions assets/gp/testgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func TestBrowse(t *testing.T) {
},
{"namesTruncated", namesTruncated,
map[string]string{
"TakeoutGoogle Photos/Photos from 2023/😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg": "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🥸🤩🥳😏😒😞😔😟😕🙁☹️😣😖😫😩🥺😢😭😤😠😡🤬🤯😳🥵🥶.jpg",
"TakeoutGoogle Photos/Photos from 2023/05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg": "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg",
"TakeoutGoogle Photos/Photos from 2023/PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg": "PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINAL.jpg",
"TakeoutGoogle Photos/Photos from 2023/😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg": "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🥸🤩🥳😏😒😞😔😟😕🙁☹️😣😖😫😩🥺😢😭😤😠😡🤬🤯😳🥵🥶.jpg",
},
},
{"imagesWithoutJSON", imagesWithoutJSON,
Expand Down Expand Up @@ -170,48 +171,3 @@ func TestAlbums(t *testing.T) {
}

}

// func TestTruncatedNames(t *testing.T) {
// type result struct {
// filename string
// title string
// }
// tc := []struct {
// name string
// gen func() *inMemFS
// results []result
// }{
// {"namesTruncated", namesTruncated, []result{
// {filename: "TakeoutGoogle Photos/Photos from 2023/😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg",
// title: "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🥸🤩🥳😏😒😞😔😟😕🙁☹️😣😖😫😩🥺😢😭😤😠😡🤬🤯😳🥵🥶.jpg",
// },
// }},
// }

// for _, c := range tc {
// t.Run(c.name, func(t *testing.T) {

// fsys := c.gen()
// if fsys.err != nil {
// t.Error(fsys.err)
// return
// }
// ctx := context.Background()

// b, err := gp.NewTakeout(ctx, fsys)
// if err != nil {
// t.Error(err)
// }

// results := []result{}
// for a := range b.Browse(ctx) {
// results = append(results, result{a.FileName, a.Title})
// }

// if !reflect.DeepEqual(results, c.results) {
// t.Errorf("expecting %v, got %v", c.results, results)
// }
// })
// }

// }
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e
github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31
github.com/yalue/merged_fs v1.2.3
golang.org/x/sys v0.12.0
)

require (
Expand All @@ -21,4 +20,5 @@ require (
github.com/pkg/sftp v1.13.6 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Use this command for uploading photos and videos from a local directory, a zippe
`-dry-run` Preview all actions as they would be done.<br>
`-delete` Delete local assets after successful upload. <br>
`-create-album-folder <bool>` Generate immich albums after folder names.<br>
`-force-sidecar <bool>` Force sending a .xmp sidecar file beside images. With Google photos date and GPS coordinates are taken from metadata.json files. (default: FALSE).<br>
` <bool>` Force sending a .xmp sidecar file beside images. With Google photos date and GPS coordinates are taken from metadata.json files. (default: FALSE).<br>


### Date selection:
Expand Down Expand Up @@ -250,13 +250,13 @@ Additionally, deploying a Node.js program on user machines presents challenges.

## Release 0.3.5

### Fix for #35 weird name cases in google photos takeout: truncated name or jp.json
Once, I have a folder full of JSON files for an album, but it doesn't have any pictures. Instead, the pictures are in a folder organized by years. To fix this, I tried to match the JSON files with the pictures by their names.

The problem is that sometimes pictures have the same name in different years, so it's hard to be sure which picture goes with which JSON file. Because of this, created album contains image found in its folder, but also images having same name, taken in different years.

I decided to remove this feature. Now, if the image isn't found beside the JSON file, the JSON is ignored.

### Fix for #32

## Release 0.3.2, 0.3.3, 0.3.4
### Fix for #30 panic: time: missing Location in call to Time.In with release Windows_x86_64_0.3.1
Expand Down

0 comments on commit 6073872

Please sign in to comment.