photoprism/internal/meta/xmp.go
Michael Mayer 1c72f88e8c Backend: Improve logging #369
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-06-29 13:16:55 +02:00

60 lines
1.1 KiB
Go

package meta
import (
"fmt"
"path/filepath"
"github.com/photoprism/photoprism/pkg/txt"
)
// XMP parses an XMP file and returns a Data struct.
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) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("metadata: %s (xmp panic)", e)
}
}()
doc := XmpDocument{}
if err := doc.Load(fileName); err != nil {
return fmt.Errorf("metadata: can't read %s (xmp)", txt.Quote(filepath.Base(fileName)))
}
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()
}
return nil
}