Skip to content

Commit

Permalink
Simulot/issue673 (#711)
Browse files Browse the repository at this point in the history
* test: add cases for Google Photos supplemental metadata files

* refactor: update matching logic for Google Photos supplemental metadata files

Fixes  #698, #673, #674, #652

* refactor: fix linter message

* refactor: update linter directive for supplemental metadata matching
  • Loading branch information
simulot authored Feb 14, 2025
1 parent 95c3b33 commit 4a0a376
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
35 changes: 35 additions & 0 deletions adapters/googlePhotos/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,41 @@ func Test_matchers(t *testing.T) {
fileName: "MVIMG_20200207_134534~2.jpg",
want: "matchNormal",
},
{ //#673 Google photos supplemental metadata files
fileName: "Scan35(1).jpg",
jsonName: "Scan35.jpg.supplemental-metadata(1).json",
want: "matchNormal",
},
{ //#673 Google photos supplemental metadata files
fileName: "CLIP0001(10).AVI",
jsonName: "CLIP0001.AVI.supplemental-metadata(10).json",
want: "matchNormal",
},
{ //#698 Google photos supplemental metadata files
fileName: "IMAG0061-edited.JPG",
jsonName: "IMAG0061.JPG.supplemental-metadata.json",
want: "matchEditedName",
},
{ //#674 Google photos supplemental metadata files
fileName: "IMG-20230325-WA0122~2-edited.jpg",
jsonName: "IMG-20230325-WA0122~2.jpg.supplemental-metadat.json",
want: "matchEditedName",
},
{ //#674 Google photos supplemental metadata files
fileName: "2234089303984509579-edited.jpg",
jsonName: "2234089303984509579.supplemental-metadata.json",
want: "matchEditedName",
},
{ //#652 Google photos supplemental metadata files
fileName: "Screenshot_20231027_123303_Facebook-edited.jpg",
jsonName: "Screenshot_20231027_123303_Facebook.jpg.supple.json",
want: "matchEditedName",
},
{ //#652 Google photos supplemental metadata files
fileName: "Screenshot_20231027_123303_Facebook(1).jpg",
jsonName: "Screenshot_20231027_123303_Facebook.jpg.supple(1).json",
want: "matchNormal",
},
}
for _, tt := range tests {
t.Run(tt.fileName, func(t *testing.T) {
Expand Down
24 changes: 18 additions & 6 deletions adapters/googlePhotos/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ func matchNormal(jsonName string, fileName string, _ filetypes.SupportedMedia) b
return false
}

// When the file name is the same as the JSON name
if strings.HasPrefix(jsonName, fileName) {
return true
// supplemental-metadata check
p2 := strings.LastIndex(jsonName, ".")
if p2 > 1 {
p1 := strings.LastIndex(jsonName[:p2], ".")
if p1 > 1 {
if strings.HasPrefix("supplemental-metadata", jsonName[p1+1:p2]) { //nolint:all
jsonName = jsonName[:p1] + jsonName[p2:]
}
}
}

// Check if the file name is the same as the JSON name
Expand Down Expand Up @@ -66,13 +72,19 @@ func matchEditedName(jsonName string, fileName string, sm filetypes.SupportedMed
return false
}
base := strings.TrimSuffix(jsonName, path.Ext(jsonName))
p1 := strings.LastIndex(base, ".")
if p1 > 1 {
if strings.HasPrefix("supplemental-metadata", base[p1+1:]) { //nolint:all
base = jsonName[:p1]
}
}

ext := path.Ext(base)
if ext != "" && sm.IsMedia(ext) {
base = strings.TrimSuffix(base, ext)
fname := strings.TrimSuffix(fileName, path.Ext(fileName))
return strings.HasPrefix(fname, base)
fileName = strings.TrimSuffix(fileName, path.Ext(fileName))
}
return false
return strings.HasPrefix(fileName, base)
}

// matchForgottenDuplicates
Expand Down

0 comments on commit 4a0a376

Please # to comment.