2020-05-26 21:51:34 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-06-29 13:16:55 +02:00
|
|
|
"reflect"
|
2020-05-26 21:51:34 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
|
|
|
)
|
|
|
|
|
2020-06-29 13:16:55 +02:00
|
|
|
// Optimize photo data, improve if possible.
|
2020-12-30 11:11:58 +01:00
|
|
|
func (m *Photo) Optimize(mergeMeta, mergeUuid, estimatePlace bool) (updated bool, merged Photos, err error) {
|
2020-05-26 21:51:34 +02:00
|
|
|
if !m.HasID() {
|
2020-12-09 22:15:10 +01:00
|
|
|
return false, merged, errors.New("photo: can't maintain, id is empty")
|
2020-05-26 21:51:34 +02:00
|
|
|
}
|
|
|
|
|
2020-06-29 13:16:55 +02:00
|
|
|
current := *m
|
2020-05-26 21:51:34 +02:00
|
|
|
|
2020-12-05 00:13:44 +01:00
|
|
|
if m.HasLatLng() && !m.HasLocation() {
|
|
|
|
m.UpdateLocation()
|
|
|
|
}
|
|
|
|
|
2020-12-12 22:02:14 +01:00
|
|
|
if original, photos, err := m.Merge(mergeMeta, mergeUuid); err != nil {
|
|
|
|
return updated, merged, err
|
|
|
|
} else if len(photos) > 0 && original.ID == m.ID {
|
|
|
|
merged = photos
|
|
|
|
} else if len(photos) > 0 && original.ID != m.ID {
|
|
|
|
return false, photos, nil
|
2020-12-09 21:44:04 +01:00
|
|
|
}
|
|
|
|
|
2020-12-30 11:11:58 +01:00
|
|
|
if estimatePlace {
|
|
|
|
m.EstimatePlace()
|
|
|
|
}
|
2020-05-26 21:51:34 +02:00
|
|
|
|
|
|
|
labels := m.ClassifyLabels()
|
|
|
|
|
2020-07-06 07:41:33 +02:00
|
|
|
m.UpdateDateFields()
|
2020-05-26 21:51:34 +02:00
|
|
|
|
|
|
|
if err := m.UpdateTitle(labels); err != nil {
|
2020-07-02 08:16:27 +02:00
|
|
|
log.Info(err)
|
2020-05-26 21:51:34 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 19:15:57 +02:00
|
|
|
details := m.GetDetails()
|
|
|
|
w := txt.UniqueWords(txt.Words(details.Keywords))
|
|
|
|
w = append(w, labels.Keywords()...)
|
|
|
|
details.Keywords = strings.Join(txt.UniqueWords(w), ", ")
|
2020-05-26 21:51:34 +02:00
|
|
|
|
|
|
|
if err := m.IndexKeywords(); err != nil {
|
2020-05-28 21:20:42 +02:00
|
|
|
log.Errorf("photo: %s", err.Error())
|
2020-05-26 21:51:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m.PhotoQuality = m.QualityScore()
|
|
|
|
|
2021-08-29 13:26:05 +02:00
|
|
|
checked := TimeStamp()
|
2020-06-29 13:16:55 +02:00
|
|
|
|
|
|
|
if reflect.DeepEqual(*m, current) {
|
2020-12-09 22:15:10 +01:00
|
|
|
return false, merged, m.Update("CheckedAt", &checked)
|
2020-06-29 13:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m.CheckedAt = &checked
|
|
|
|
|
2020-12-09 22:15:10 +01:00
|
|
|
return true, merged, m.Save()
|
2020-05-26 21:51:34 +02:00
|
|
|
}
|