photoprism/internal/meta/sanitize.go
Michael Mayer bfd73932e5 Improve UX and title generation from file names
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-06-29 11:10:24 +02:00

55 lines
1.1 KiB
Go

package meta
import (
"strings"
"github.com/photoprism/photoprism/pkg/fs"
)
var UnwantedDescriptions = map[string]bool{
"OLYMPUS DIGITAL CAMERA": true,
}
// SanitizeString removes unwanted character from an exif value string.
func SanitizeString(value string) string {
value = strings.TrimSpace(value)
return strings.Replace(value, "\"", "", -1)
}
// SanitizeUID normalizes unique IDs found in XMP or Exif metadata.
func SanitizeUID(value string) string {
value = SanitizeString(value)
if start := strings.LastIndex(value, ":"); start != -1 {
value = value[start+1:]
}
// Not a unique ID?
if len(value) < 15 || len(value) > 36 {
value = ""
}
return strings.ToLower(value)
}
// SanitizeTitle normalizes titles and removes unwanted information.
func SanitizeTitle(value string) string {
value = SanitizeString(value)
if fs.IsID(value) {
value = ""
}
return value
}
// SanitizeDescription normalizes descriptions and removes unwanted information.
func SanitizeDescription(value string) string {
value = SanitizeString(value)
if remove := UnwantedDescriptions[value]; remove {
value = ""
}
return value
}