-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
photo_quality.go
80 lines (61 loc) Β· 1.38 KB
/
photo_quality.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package entity
import (
"strings"
"time"
"github.com/photoprism/photoprism/pkg/txt"
)
var QualityBlacklist = map[string]bool{
"screenshot": true,
"screenshots": true,
"info": true,
}
var (
year2008 = time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC)
year2012 = time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC)
)
// QualityScore returns a score based on photo properties like size and metadata.
func (m *Photo) QualityScore() (score int) {
if m.PhotoFavorite {
score += 3
}
if SrcPriority[m.TakenSrc] > SrcPriority[SrcEstimate] {
score++
}
if m.TrustedLocation() {
score++
}
if m.TakenAt.Before(year2008) {
score++
} else if m.TakenAt.Before(year2012) && m.PhotoResolution >= 1 {
score++
} else if m.PhotoResolution >= 2 {
score++
}
blacklisted := false
details := m.GetDetails()
if details.Keywords != "" {
keywords := txt.Words(details.Keywords)
for _, w := range keywords {
w = strings.ToLower(w)
if _, ok := QualityBlacklist[w]; ok {
blacklisted = true
break
}
}
}
if !blacklisted {
score++
}
if score < 3 && (m.PhotoType != MediaImage || m.EditedAt != nil) {
score = 3
}
return score
}
// 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)
}