2020-04-16 20:57:00 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
2021-11-18 13:13:48 +01:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2020-04-18 23:20:54 +02:00
|
|
|
"time"
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2021-11-25 14:52:26 +01:00
|
|
|
"github.com/dustin/go-humanize/english"
|
|
|
|
|
2020-04-16 20:57:00 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/classify"
|
2020-05-28 15:12:18 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/maps"
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2021-11-22 18:18:41 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/geo"
|
2021-11-18 13:13:48 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2021-07-17 15:21:03 +02:00
|
|
|
"gopkg.in/photoprism/go-tz.v2/tz"
|
2020-04-16 20:57:00 +02:00
|
|
|
)
|
|
|
|
|
2021-11-24 14:32:40 +01:00
|
|
|
// SetCoordinates changes the photo lat, lng and altitude if not empty and from an acceptable source.
|
2023-02-09 11:51:26 +01:00
|
|
|
func (m *Photo) SetCoordinates(lat, lng float32, altitude float64, source string) {
|
2021-11-24 14:32:40 +01:00
|
|
|
m.SetAltitude(altitude, source)
|
|
|
|
|
|
|
|
if lat == 0.0 && lng == 0.0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if SrcPriority[source] < SrcPriority[m.PlaceSrc] && m.HasLatLng() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
m.PhotoLat = lat
|
|
|
|
m.PhotoLng = lng
|
|
|
|
m.PlaceSrc = source
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAltitude sets the photo altitude if not empty and from an acceptable source.
|
2023-02-09 11:51:26 +01:00
|
|
|
func (m *Photo) SetAltitude(altitude float64, source string) {
|
|
|
|
a := clean.Altitude(altitude)
|
|
|
|
|
|
|
|
if a == 0 && source != SrcManual {
|
2021-11-24 14:32:40 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if SrcPriority[source] < SrcPriority[m.PlaceSrc] {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-09 11:51:26 +01:00
|
|
|
m.PhotoAltitude = a
|
2021-11-24 14:32:40 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
// UnknownLocation tests if the photo has an unknown location.
|
|
|
|
func (m *Photo) UnknownLocation() bool {
|
|
|
|
return m.CellID == "" || m.CellID == UnknownLocation.ID || m.NoLatLng()
|
|
|
|
}
|
|
|
|
|
2021-11-24 16:56:57 +01:00
|
|
|
// SetPosition sets a position estimate.
|
|
|
|
func (m *Photo) SetPosition(pos geo.Position, source string, force bool) {
|
|
|
|
if SrcPriority[m.PlaceSrc] > SrcPriority[source] && !force {
|
|
|
|
return
|
|
|
|
} else if pos.Lat == 0 && pos.Lng == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.CellID != UnknownID && pos.InRange(float64(m.PhotoLat), float64(m.PhotoLng), geo.Meter*50) {
|
|
|
|
log.Debugf("photo: %s keeps position %f, %f", m.String(), m.PhotoLat, m.PhotoLng)
|
|
|
|
} else {
|
|
|
|
if pos.Estimate {
|
|
|
|
pos.Randomize(geo.Meter * 5)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.PhotoLat = float32(pos.Lat)
|
|
|
|
m.PhotoLng = float32(pos.Lng)
|
|
|
|
m.PlaceSrc = source
|
|
|
|
m.CellAccuracy = pos.Accuracy
|
2023-02-09 11:51:26 +01:00
|
|
|
m.SetAltitude(pos.Altitude, source)
|
2021-11-24 16:56:57 +01:00
|
|
|
|
|
|
|
log.Debugf("photo: %s %s", m.String(), pos.String())
|
|
|
|
|
|
|
|
m.UpdateLocation()
|
|
|
|
|
|
|
|
if m.Place == nil {
|
|
|
|
log.Warnf("photo: failed updating position of %s", m)
|
|
|
|
} else {
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Debugf("photo: approximate place of %s is %s (id %s)", m, clean.Log(m.Place.Label()), m.PlaceID)
|
2021-11-24 16:56:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AdoptPlace sets the place based on another photo.
|
|
|
|
func (m *Photo) AdoptPlace(other Photo, source string, force bool) {
|
|
|
|
if SrcPriority[m.PlaceSrc] > SrcPriority[source] && !force {
|
|
|
|
return
|
|
|
|
} else if other.Place == nil {
|
|
|
|
return
|
2021-11-25 14:52:26 +01:00
|
|
|
} else if other.Place.Unknown() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove existing location labels if place changes.
|
|
|
|
if other.Place.ID != m.PlaceID {
|
|
|
|
m.RemoveLocationLabels()
|
2021-11-24 16:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m.RemoveLocation(source, force)
|
|
|
|
|
|
|
|
m.Place = other.Place
|
|
|
|
m.PlaceID = other.PlaceID
|
|
|
|
m.PhotoCountry = other.PhotoCountry
|
|
|
|
m.PlaceSrc = source
|
|
|
|
|
|
|
|
m.UpdateTimeZone(other.TimeZone)
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Debugf("photo: %s now located at %s (id %s)", m.String(), clean.Log(m.Place.Label()), m.PlaceID)
|
2021-11-24 16:56:57 +01:00
|
|
|
}
|
|
|
|
|
2021-11-22 18:18:41 +01:00
|
|
|
// RemoveLocation removes the current location.
|
2021-11-24 16:56:57 +01:00
|
|
|
func (m *Photo) RemoveLocation(source string, force bool) {
|
|
|
|
if SrcPriority[m.PlaceSrc] > SrcPriority[source] && !force {
|
2021-11-24 12:49:20 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset latitude and longitude.
|
2021-11-22 18:18:41 +01:00
|
|
|
m.PhotoLat = 0
|
|
|
|
m.PhotoLng = 0
|
2021-11-24 12:49:20 +01:00
|
|
|
|
|
|
|
// Reset cell reference.
|
2021-11-22 18:18:41 +01:00
|
|
|
m.Cell = &UnknownLocation
|
|
|
|
m.CellID = UnknownLocation.ID
|
2021-11-23 19:23:10 +01:00
|
|
|
m.CellAccuracy = 0
|
2021-11-24 12:49:20 +01:00
|
|
|
|
|
|
|
// Reset country code.
|
|
|
|
m.PhotoCountry = UnknownCountry.ID
|
|
|
|
|
|
|
|
// Reset place reference.
|
2021-11-23 19:23:10 +01:00
|
|
|
m.Place = &UnknownPlace
|
|
|
|
m.PlaceID = UnknownPlace.ID
|
2021-11-24 12:49:20 +01:00
|
|
|
|
|
|
|
// Reset place source.
|
|
|
|
m.PlaceSrc = SrcAuto
|
2021-11-22 18:18:41 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 14:52:26 +01:00
|
|
|
// RemoveLocationLabels removes existing location labels.
|
|
|
|
func (m *Photo) RemoveLocationLabels() {
|
|
|
|
if len(m.Labels) == 0 {
|
|
|
|
res := Db().Delete(PhotoLabel{}, "photo_id = ? AND label_src = ?", m.ID, SrcLocation)
|
|
|
|
|
|
|
|
if res.Error != nil {
|
|
|
|
Log("photo", "remove location labels", res.Error)
|
|
|
|
} else if res.RowsAffected > 0 {
|
|
|
|
log.Infof("photo: removed %s from %s",
|
|
|
|
english.Plural(int(res.RowsAffected), "location label", "location labels"), m)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
labels := make([]PhotoLabel, 0, len(m.Labels))
|
|
|
|
|
|
|
|
for _, l := range m.Labels {
|
|
|
|
if l.LabelSrc != SrcLocation {
|
|
|
|
labels = append(labels, l)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
Log("photo", "remove location label", l.Delete())
|
|
|
|
}
|
|
|
|
|
|
|
|
removed := len(m.Labels) - len(labels)
|
|
|
|
|
|
|
|
if removed > 0 {
|
|
|
|
log.Infof("photo: removed %s from %s",
|
|
|
|
english.Plural(removed, "location label", "location labels"), m)
|
|
|
|
m.Labels = labels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
// HasLocation tests if the photo has a known location.
|
|
|
|
func (m *Photo) HasLocation() bool {
|
|
|
|
return !m.UnknownLocation()
|
|
|
|
}
|
|
|
|
|
2021-11-24 14:32:40 +01:00
|
|
|
// TrustedLocation tests if the photo has a known location from a trusted source.
|
|
|
|
func (m *Photo) TrustedLocation() bool {
|
|
|
|
return m.HasLocation() && SrcPriority[m.PlaceSrc] > SrcPriority[SrcEstimate]
|
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
// LocationLoaded tests if the photo has a known location that is currently loaded.
|
|
|
|
func (m *Photo) LocationLoaded() bool {
|
|
|
|
if m.Cell == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Cell.Place == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return !m.Cell.Unknown() && m.Cell.ID == m.CellID
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadLocation loads the photo location from the database if not done already.
|
|
|
|
func (m *Photo) LoadLocation() error {
|
|
|
|
if m.LocationLoaded() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.UnknownLocation() {
|
|
|
|
return fmt.Errorf("photo: unknown location (%s)", m)
|
|
|
|
}
|
|
|
|
|
|
|
|
var location Cell
|
|
|
|
|
|
|
|
err := Db().Preload("Place").First(&location, "id = ?", m.CellID).Error
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if location.Place == nil {
|
|
|
|
location.Place = &UnknownPlace
|
|
|
|
location.PlaceID = UnknownPlace.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Cell = &location
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PlaceLoaded checks if the photo has a known place that is currently loaded.
|
|
|
|
func (m *Photo) PlaceLoaded() bool {
|
|
|
|
if m.Place == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return !m.Place.Unknown() && m.Place.ID == m.PlaceID
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadPlace loads the photo place from the database if not done already.
|
|
|
|
func (m *Photo) LoadPlace() error {
|
|
|
|
if m.PlaceLoaded() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.UnknownPlace() {
|
|
|
|
return fmt.Errorf("photo: unknown place (%s)", m)
|
|
|
|
}
|
|
|
|
|
|
|
|
var place Place
|
|
|
|
|
|
|
|
err := Db().First(&place, "id = ?", m.PlaceID).Error
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Place = &place
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:18:41 +01:00
|
|
|
// Position returns the coordinates as geo.Position.
|
|
|
|
func (m *Photo) Position() geo.Position {
|
2021-11-23 19:23:10 +01:00
|
|
|
return geo.Position{Name: m.String(), Time: m.TakenAt.UTC(),
|
|
|
|
Lat: float64(m.PhotoLat), Lng: float64(m.PhotoLng), Altitude: float64(m.PhotoAltitude)}
|
2021-11-22 18:18:41 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
// HasLatLng checks if the photo has a latitude and longitude.
|
|
|
|
func (m *Photo) HasLatLng() bool {
|
|
|
|
return m.PhotoLat != 0.0 || m.PhotoLng != 0.0
|
|
|
|
}
|
|
|
|
|
|
|
|
// NoLatLng checks if latitude and longitude are missing.
|
|
|
|
func (m *Photo) NoLatLng() bool {
|
|
|
|
return !m.HasLatLng()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownPlace checks if the photo has an unknown place.
|
|
|
|
func (m *Photo) UnknownPlace() bool {
|
|
|
|
return m.PlaceID == "" || m.PlaceID == UnknownPlace.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasPlace checks if the photo has a known place.
|
|
|
|
func (m *Photo) HasPlace() bool {
|
|
|
|
return !m.UnknownPlace()
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasCountry checks if the photo has a known country.
|
|
|
|
func (m *Photo) HasCountry() bool {
|
|
|
|
return !m.UnknownCountry()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnknownCountry checks if the photo has an unknown country.
|
|
|
|
func (m *Photo) UnknownCountry() bool {
|
|
|
|
return m.CountryCode() == UnknownCountry.ID
|
|
|
|
}
|
|
|
|
|
2020-04-18 23:20:54 +02:00
|
|
|
// GetTimeZone uses PhotoLat and PhotoLng to guess the time zone of the photo.
|
|
|
|
func (m *Photo) GetTimeZone() string {
|
|
|
|
result := "UTC"
|
|
|
|
|
|
|
|
if m.HasLatLng() {
|
|
|
|
zones, err := tz.GetZone(tz.Point{
|
2020-04-26 11:41:54 +02:00
|
|
|
Lat: float64(m.PhotoLat),
|
|
|
|
Lon: float64(m.PhotoLng),
|
2020-04-18 23:20:54 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if err == nil && len(zones) > 0 {
|
|
|
|
result = zones[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-05-28 15:12:18 +02:00
|
|
|
// CountryName returns the photo country name.
|
|
|
|
func (m *Photo) CountryName() string {
|
2020-05-31 17:45:58 +02:00
|
|
|
if name, ok := maps.CountryNames[m.CountryCode()]; ok {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
return UnknownCountry.CountryName
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CountryCode returns the photo country code.
|
|
|
|
func (m *Photo) CountryCode() string {
|
2020-05-31 17:45:58 +02:00
|
|
|
if len(m.PhotoCountry) != 2 {
|
|
|
|
m.PhotoCountry = UnknownCountry.ID
|
|
|
|
}
|
|
|
|
|
2020-05-28 15:12:18 +02:00
|
|
|
return m.PhotoCountry
|
|
|
|
}
|
|
|
|
|
2020-04-18 23:20:54 +02:00
|
|
|
// GetTakenAt returns UTC time for TakenAtLocal.
|
|
|
|
func (m *Photo) GetTakenAt() time.Time {
|
2021-01-26 19:18:37 +01:00
|
|
|
location, err := time.LoadLocation(m.TimeZone)
|
2020-04-18 23:20:54 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return m.TakenAt
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:18:37 +01:00
|
|
|
if takenAt, err := time.ParseInLocation("2006-01-02T15:04:05", m.TakenAtLocal.Format("2006-01-02T15:04:05"), location); err != nil {
|
2020-04-18 23:20:54 +02:00
|
|
|
return m.TakenAt
|
|
|
|
} else {
|
|
|
|
return takenAt.UTC()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:18:37 +01:00
|
|
|
// GetTakenAtLocal returns local time for TakenAt.
|
|
|
|
func (m *Photo) GetTakenAtLocal() time.Time {
|
|
|
|
location, err := time.LoadLocation(m.TimeZone)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return m.TakenAtLocal
|
|
|
|
}
|
|
|
|
|
|
|
|
if takenAtLocal, err := time.ParseInLocation("2006-01-02T15:04:05", m.TakenAt.In(location).Format("2006-01-02T15:04:05"), time.UTC); err != nil {
|
|
|
|
return m.TakenAtLocal
|
|
|
|
} else {
|
|
|
|
return takenAtLocal.UTC()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 23:20:54 +02:00
|
|
|
// UpdateLocation updates location and labels based on latitude and longitude.
|
2020-12-05 00:13:44 +01:00
|
|
|
func (m *Photo) UpdateLocation() (keywords []string, labels classify.Labels) {
|
2020-05-28 15:12:18 +02:00
|
|
|
if m.HasLatLng() {
|
2021-12-09 01:10:15 +01:00
|
|
|
var loc = NewCell(m.PhotoLat, m.PhotoLng)
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2021-12-09 01:10:15 +01:00
|
|
|
if loc.Unknown() {
|
|
|
|
// Empty or unknown S2 cell id... should not happen, unless coordinates are invalid.
|
|
|
|
log.Warnf("photo: unknown cell id for lat %f, lng %f (uid %s)", m.PhotoLat, m.PhotoLng, m.PhotoUID)
|
|
|
|
} else if err := loc.Find(GeoApi); err != nil {
|
2021-11-23 19:23:10 +01:00
|
|
|
log.Errorf("photo: %s (find location)", err)
|
2021-12-09 01:10:15 +01:00
|
|
|
} else if loc.Place == nil {
|
|
|
|
log.Warnf("photo: failed fetching geo data (uid %s, cell %s)", m.PhotoUID, loc.ID)
|
|
|
|
} else if loc.ID != UnknownLocation.ID {
|
|
|
|
changed := m.CellID != loc.ID
|
2021-11-23 19:23:10 +01:00
|
|
|
|
|
|
|
if changed {
|
2021-12-09 01:10:15 +01:00
|
|
|
log.Debugf("photo: changing location of %s from %s to %s", m.String(), m.CellID, loc.ID)
|
2021-11-25 14:52:26 +01:00
|
|
|
m.RemoveLocationLabels()
|
2021-11-23 19:23:10 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 01:10:15 +01:00
|
|
|
m.Cell = loc
|
|
|
|
m.CellID = loc.ID
|
|
|
|
m.Place = loc.Place
|
|
|
|
m.PlaceID = loc.PlaceID
|
|
|
|
m.PhotoCountry = loc.CountryCode()
|
2020-04-18 23:20:54 +02:00
|
|
|
|
2021-11-23 19:23:10 +01:00
|
|
|
if changed && m.TakenSrc != SrcManual {
|
|
|
|
m.UpdateTimeZone(m.GetTimeZone())
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2021-12-09 01:10:15 +01:00
|
|
|
FirstOrCreateCountry(NewCountry(loc.CountryCode(), loc.CountryName()))
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2021-12-09 01:10:15 +01:00
|
|
|
locCategory := loc.Category()
|
|
|
|
keywords = append(keywords, loc.Keywords()...)
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2020-05-28 15:12:18 +02:00
|
|
|
// Append category from reverse location lookup
|
|
|
|
if locCategory != "" {
|
2021-02-21 17:18:36 +01:00
|
|
|
labels = append(labels, classify.LocationLabel(locCategory, 0))
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return keywords, labels
|
2020-04-16 20:57:00 +02:00
|
|
|
}
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
keywords = []string{}
|
|
|
|
labels = classify.Labels{}
|
2020-04-16 20:57:00 +02:00
|
|
|
|
2020-05-28 15:12:18 +02:00
|
|
|
if m.UnknownLocation() {
|
2020-07-12 08:27:05 +02:00
|
|
|
m.Cell = &UnknownLocation
|
|
|
|
m.CellID = UnknownLocation.ID
|
2021-02-11 19:48:33 +01:00
|
|
|
|
|
|
|
// Remove place estimate if better data is available.
|
|
|
|
if SrcPriority[m.PlaceSrc] > SrcPriority[SrcEstimate] {
|
|
|
|
m.Place = &UnknownPlace
|
|
|
|
m.PlaceID = UnknownPlace.ID
|
|
|
|
}
|
2020-06-04 22:26:00 +02:00
|
|
|
} else if err := m.LoadLocation(); err == nil {
|
2020-07-12 08:27:05 +02:00
|
|
|
m.Place = m.Cell.Place
|
|
|
|
m.PlaceID = m.Cell.PlaceID
|
2020-06-05 10:17:00 +02:00
|
|
|
} else {
|
2021-02-11 19:48:33 +01:00
|
|
|
log.Warnf("photo: location %s not found in %s", m.CellID, m.PhotoName)
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if m.UnknownPlace() {
|
2020-04-25 14:22:47 +02:00
|
|
|
m.Place = &UnknownPlace
|
2020-05-29 12:56:24 +02:00
|
|
|
m.PlaceID = UnknownPlace.ID
|
2020-06-04 22:26:00 +02:00
|
|
|
} else if err := m.LoadPlace(); err == nil {
|
2020-05-28 15:12:18 +02:00
|
|
|
m.PhotoCountry = m.Place.CountryCode()
|
2020-06-05 10:17:00 +02:00
|
|
|
} else {
|
2021-02-11 19:48:33 +01:00
|
|
|
log.Warnf("photo: place %s not found in %s", m.PlaceID, m.PhotoName)
|
2020-05-28 15:12:18 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 19:23:10 +01:00
|
|
|
if m.UnknownCountry() && m.CellID == UnknownID && m.PlaceID == UnknownID {
|
2020-06-01 09:45:24 +02:00
|
|
|
m.EstimateCountry()
|
2020-04-16 20:57:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 15:12:18 +02:00
|
|
|
if m.HasCountry() {
|
|
|
|
FirstOrCreateCountry(NewCountry(m.CountryCode(), m.CountryName()))
|
2020-04-16 20:57:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return keywords, labels
|
|
|
|
}
|
2021-11-18 13:13:48 +01:00
|
|
|
|
|
|
|
// SaveLocation updates location data and saves the photo metadata back to the index.
|
|
|
|
func (m *Photo) SaveLocation() error {
|
|
|
|
locKeywords, labels := m.UpdateLocation()
|
|
|
|
|
|
|
|
m.AddLabels(labels)
|
|
|
|
|
|
|
|
w := txt.UniqueWords(txt.Words(m.GetDetails().Keywords))
|
|
|
|
w = append(w, locKeywords...)
|
|
|
|
|
|
|
|
m.GetDetails().Keywords = strings.Join(txt.UniqueWords(w), ", ")
|
|
|
|
|
|
|
|
if err := m.SyncKeywordLabels(); err != nil {
|
2021-11-25 14:52:26 +01:00
|
|
|
log.Errorf("photo: %s %s while syncing keywords and labels", m.String(), err)
|
2021-11-18 13:13:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.UpdateTitle(m.ClassifyLabels()); err != nil {
|
|
|
|
log.Info(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.IndexKeywords(); err != nil {
|
2021-11-25 14:52:26 +01:00
|
|
|
log.Errorf("photo: %s %s while indexing keywords", m.String(), err)
|
2021-11-18 13:13:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return m.Save()
|
|
|
|
}
|