2020-01-07 17:36:49 +01:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-15 15:29:56 +02:00
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
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 {
|
2020-05-15 15:29:56 +02:00
|
|
|
err = fmt.Errorf("%s (xmp metadata)", e)
|
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 {
|
2020-05-15 15:29:56 +02:00
|
|
|
return fmt.Errorf("can't read %s (xmp)", txt.Quote(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
|
|
|
|
2020-05-13 20:53:15 +02:00
|
|
|
return nil
|
2020-01-07 17:36:49 +01:00
|
|
|
}
|