2020-01-07 17:36:49 +01:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-15 15:29:56 +02:00
|
|
|
"path/filepath"
|
2020-07-13 10:41:45 +02:00
|
|
|
"runtime/debug"
|
2020-05-15 15:29:56 +02:00
|
|
|
|
2021-12-14 20:01:39 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/sanitize"
|
2020-01-07 17:36:49 +01:00
|
|
|
)
|
|
|
|
|
2020-01-07 18:13:53 +01:00
|
|
|
// XMP parses an XMP file and returns a Data struct.
|
2020-05-13 20:53:15 +02:00
|
|
|
func XMP(fileName string) (data Data, err error) {
|
|
|
|
err = data.XMP(fileName)
|
|
|
|
|
|
|
|
return data, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// XMP parses an XMP file and returns a Data struct.
|
|
|
|
func (data *Data) XMP(fileName string) (err error) {
|
2020-01-07 17:36:49 +01:00
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
2021-12-14 20:01:39 +01:00
|
|
|
err = fmt.Errorf("metadata: %s in %s (xmp panic)\nstack: %s", e, sanitize.Log(filepath.Base(fileName)), debug.Stack())
|
2020-01-07 17:36:49 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-01-13 23:14:10 +01:00
|
|
|
doc := XmpDocument{}
|
2020-01-07 17:36:49 +01:00
|
|
|
|
2020-05-13 20:53:15 +02:00
|
|
|
if err := doc.Load(fileName); err != nil {
|
2022-01-05 11:40:44 +01:00
|
|
|
return fmt.Errorf("metadata: cannot read %s (xmp)", sanitize.Log(filepath.Base(fileName)))
|
2020-01-07 17:36:49 +01:00
|
|
|
}
|
|
|
|
|
2020-05-13 20:53:15 +02:00
|
|
|
if doc.Title() != "" {
|
|
|
|
data.Title = doc.Title()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.Artist() != "" {
|
|
|
|
data.Artist = doc.Artist()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.Description() != "" {
|
|
|
|
data.Description = doc.Description()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.Copyright() != "" {
|
|
|
|
data.Copyright = doc.Copyright()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.CameraMake() != "" {
|
|
|
|
data.CameraMake = doc.CameraMake()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.CameraModel() != "" {
|
|
|
|
data.CameraModel = doc.CameraModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
if doc.LensModel() != "" {
|
|
|
|
data.LensModel = doc.LensModel()
|
|
|
|
}
|
2020-01-07 17:36:49 +01:00
|
|
|
|
2021-04-26 13:54:14 +02:00
|
|
|
if takenAt := doc.TakenAt(); !takenAt.IsZero() {
|
|
|
|
data.TakenAt = takenAt
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(doc.Keywords()) != 0 {
|
|
|
|
data.AddKeywords(doc.Keywords())
|
|
|
|
}
|
|
|
|
|
2020-05-13 20:53:15 +02:00
|
|
|
return nil
|
2020-01-07 17:36:49 +01:00
|
|
|
}
|