photoprism/internal/entity/photo_quality.go
Michael Mayer 77cea5d719 Implement score to sort photos by quality #288
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-04-24 13:21:18 +02:00

53 lines
789 B
Go

package entity
import (
"strings"
"github.com/photoprism/photoprism/pkg/txt"
)
var QualityBlacklist = map[string]bool{
"screenshot": true,
"screenshots": true,
"info": true,
}
// QualityScore returns a score based on photo properties like size and metadata.
func (m *Photo) QualityScore() (score int) {
if m.PhotoFavorite {
score += 3
}
if m.TakenSrc != SrcAuto {
score++
}
if m.HasLatLng() {
score++
}
if m.PhotoResolution >= 2 {
score++
}
blacklisted := false
if m.Description.PhotoKeywords != "" {
keywords := txt.Words(m.Description.PhotoKeywords)
for _, w := range keywords {
w = strings.ToLower(w)
if _, ok := QualityBlacklist[w]; ok {
blacklisted = true
break
}
}
}
if !blacklisted {
score++
}
return score
}