2020-04-24 13:21:18 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2020-04-25 14:22:47 +02:00
|
|
|
"time"
|
2020-04-24 13:21:18 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var QualityBlacklist = map[string]bool{
|
|
|
|
"screenshot": true,
|
|
|
|
"screenshots": true,
|
|
|
|
"info": true,
|
|
|
|
}
|
|
|
|
|
2020-04-25 14:22:47 +02:00
|
|
|
var (
|
2020-04-25 14:55:26 +02:00
|
|
|
year2008 = time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
|
|
year2012 = time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC)
|
2020-04-25 14:22:47 +02:00
|
|
|
)
|
|
|
|
|
2020-04-24 13:21:18 +02:00
|
|
|
// QualityScore returns a score based on photo properties like size and metadata.
|
|
|
|
func (m *Photo) QualityScore() (score int) {
|
|
|
|
if m.PhotoFavorite {
|
|
|
|
score += 3
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:18:41 +01:00
|
|
|
if SrcPriority[m.TakenSrc] > SrcPriority[SrcEstimate] {
|
2020-04-24 13:21:18 +02:00
|
|
|
score++
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:18:41 +01:00
|
|
|
if SrcPriority[m.PlaceSrc] > SrcPriority[SrcEstimate] {
|
2020-04-24 13:21:18 +02:00
|
|
|
score++
|
|
|
|
}
|
|
|
|
|
2020-04-25 14:22:47 +02:00
|
|
|
if m.TakenAt.Before(year2008) {
|
|
|
|
score++
|
|
|
|
} else if m.TakenAt.Before(year2012) && m.PhotoResolution >= 1 {
|
|
|
|
score++
|
|
|
|
} else if m.PhotoResolution >= 2 {
|
2020-04-24 13:21:18 +02:00
|
|
|
score++
|
|
|
|
}
|
|
|
|
|
|
|
|
blacklisted := false
|
|
|
|
|
2020-07-06 19:15:57 +02:00
|
|
|
details := m.GetDetails()
|
|
|
|
|
|
|
|
if details.Keywords != "" {
|
|
|
|
keywords := txt.Words(details.Keywords)
|
2020-04-24 13:21:18 +02:00
|
|
|
|
|
|
|
for _, w := range keywords {
|
|
|
|
w = strings.ToLower(w)
|
|
|
|
|
|
|
|
if _, ok := QualityBlacklist[w]; ok {
|
|
|
|
blacklisted = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !blacklisted {
|
|
|
|
score++
|
|
|
|
}
|
|
|
|
|
2020-05-21 13:26:28 +02:00
|
|
|
if score < 3 && (m.PhotoType != TypeImage || m.EditedAt != nil) {
|
2020-04-25 14:22:47 +02:00
|
|
|
score = 3
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:21:18 +02:00
|
|
|
return score
|
|
|
|
}
|
2020-12-27 07:43:39 +01:00
|
|
|
|
|
|
|
// UpdateQuality updates the photo quality attribute.
|
|
|
|
func (m *Photo) UpdateQuality() error {
|
|
|
|
if m.DeletedAt != nil || m.PhotoQuality < 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
m.PhotoQuality = m.QualityScore()
|
|
|
|
|
|
|
|
return m.Update("PhotoQuality", m.PhotoQuality)
|
|
|
|
}
|