2020-07-13 14:20:43 +02:00
|
|
|
package meta
|
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
import (
|
|
|
|
"strings"
|
2021-04-26 12:37:52 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2021-04-25 14:17:34 +02:00
|
|
|
)
|
2020-07-13 14:20:43 +02:00
|
|
|
|
|
|
|
const (
|
2020-07-16 13:02:48 +02:00
|
|
|
KeywordFlash = "flash"
|
|
|
|
KeywordHdr = "hdr"
|
|
|
|
KeywordBurst = "burst"
|
|
|
|
KeywordPanorama = "panorama"
|
|
|
|
KeywordEquirectangular = "equirectangular"
|
2020-07-13 14:20:43 +02:00
|
|
|
)
|
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
// Keywords represents a list of metadata keywords.
|
|
|
|
type Keywords []string
|
|
|
|
|
|
|
|
// String returns a string containing all keywords.
|
|
|
|
func (w Keywords) String() string {
|
|
|
|
return strings.Join(w, ", ")
|
|
|
|
}
|
|
|
|
|
2020-07-16 13:02:48 +02:00
|
|
|
var AutoKeywords = []string{KeywordHdr, KeywordBurst, KeywordPanorama, KeywordEquirectangular}
|
2020-07-13 14:20:43 +02:00
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
// AddKeywords appends keywords.
|
|
|
|
func (data *Data) AddKeywords(w string) {
|
|
|
|
w = strings.ToLower(SanitizeMeta(w))
|
2020-07-13 14:20:43 +02:00
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
if len(w) < 1 {
|
2020-07-13 14:20:43 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
data.Keywords = txt.AddToWords(data.Keywords, w)
|
2020-07-13 14:20:43 +02:00
|
|
|
}
|
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
// AutoAddKeywords automatically appends relevant keywords from a string (e.g. description).
|
2020-07-13 14:20:43 +02:00
|
|
|
func (data *Data) AutoAddKeywords(s string) {
|
2021-04-25 14:17:34 +02:00
|
|
|
s = strings.ToLower(SanitizeMeta(s))
|
2020-07-13 14:20:43 +02:00
|
|
|
|
2021-04-25 14:17:34 +02:00
|
|
|
if len(s) < 1 {
|
2020-07-13 14:20:43 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, w := range AutoKeywords {
|
|
|
|
if strings.Contains(s, w) {
|
2021-04-25 14:17:34 +02:00
|
|
|
data.AddKeywords(w)
|
2022-01-05 16:37:19 +01:00
|
|
|
if w == KeywordHdr {
|
|
|
|
data.ImageType = ImageTypeHDR
|
|
|
|
}
|
2020-07-13 14:20:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|