Metadata: Add patterns to unwanted descriptions list

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-07-11 10:19:06 +02:00
parent 2c6552ff73
commit 711522db68
4 changed files with 51 additions and 4 deletions

View file

@ -13,7 +13,6 @@ import (
"github.com/dsoprea/go-exif/v2/common"
"github.com/dsoprea/go-jpeg-image-structure"
"github.com/dsoprea/go-png-image-structure"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/txt"
"gopkg.in/ugjka/go-tz.v2/tz"
)
@ -47,7 +46,7 @@ func (data *Data) Exif(fileName string) (err error) {
logName := txt.Quote(filepath.Base(fileName))
ext := strings.ToLower(path.Ext(fileName))
if ext == fs.JpegExt || ext == ".jpeg" {
if ext == ".jpg" || ext == ".jpeg" {
jmp := jpegstructure.NewJpegMediaParser()
sl, err := jmp.ParseFile(fileName)

View file

@ -82,7 +82,7 @@ func TestExif(t *testing.T) {
assert.Equal(t, "2017-12-21T05:17:28Z", data.TakenAtLocal.Format("2006-01-02T15:04:05Z"))
assert.Equal(t, "", data.Title)
assert.Equal(t, "", data.Keywords)
assert.Equal(t, "DCIM\\100GOPRO", data.Description)
assert.Equal(t, "", data.Description)
assert.Equal(t, "", data.Copyright)
assert.Equal(t, 180, data.Height)
assert.Equal(t, 240, data.Width)

View file

@ -7,7 +7,21 @@ import (
)
var UnwantedDescriptions = map[string]bool{
"OLYMPUS DIGITAL CAMERA": true,
"OLYMPUS DIGITAL CAMERA": true, // Olympus
"rhdr": true, // Huawei
"hdrpl": true,
"fbt": true,
"mon": true,
"nor": true,
"dav": true,
"mde": true,
"edf": true,
"btfmdn": true,
"btf": true,
"btfhdr": true,
"frem": true,
"oznor": true,
"rpt": true,
}
// SanitizeString removes unwanted character from an exif value string.
@ -49,6 +63,8 @@ func SanitizeDescription(value string) string {
if remove := UnwantedDescriptions[value]; remove {
value = ""
} else if strings.HasPrefix(value, "DCIM\\") && !strings.Contains(value, " ") {
value = ""
}
return value

View file

@ -52,4 +52,36 @@ func TestSanitizeDescription(t *testing.T) {
t.Fatal("result should be empty")
}
})
t.Run("GoPro", func(t *testing.T) {
result := SanitizeDescription("DCIM\\108GOPRO\\GOPR2137.JPG")
if result != "" {
t.Fatal("result should be empty")
}
})
t.Run("hdrpl", func(t *testing.T) {
result := SanitizeDescription("hdrpl")
if result != "" {
t.Fatal("result should be empty")
}
})
t.Run("btf", func(t *testing.T) {
result := SanitizeDescription("btf")
if result != "" {
t.Fatal("result should be empty")
}
})
t.Run("wtf", func(t *testing.T) {
result := SanitizeDescription("wtf")
if result != "wtf" {
t.Fatal("result should be 'wtf'")
}
})
}