XMP: Add support for reading fstop:favorite flag (#1873)
* Add support for fstop:favorite in XMP files * Incorporate suggestions
This commit is contained in:
parent
062495b6f2
commit
5ca3329e2d
6 changed files with 52 additions and 14 deletions
|
@ -30,6 +30,7 @@ type Data struct {
|
|||
Title string `meta:"Headline,Title" xmp:"dc:title" dc:"title,title.Alt"`
|
||||
Subject string `meta:"Subject,PersonInImage,ObjectName,HierarchicalSubject,CatalogSets" xmp:"Subject"`
|
||||
Keywords Keywords `meta:"Keywords"`
|
||||
Favorite bool `meta:"Favorite"`
|
||||
Notes string `meta:"Comment,UserComment"`
|
||||
Artist string `meta:"Artist,Creator,By-line,OwnerName,Owner" xmp:"Creator"`
|
||||
Description string `meta:"Description,Caption-Abstract" xmp:"Description,Description.Alt"`
|
||||
|
|
9
internal/meta/testdata/fstop-favorite.xmp
vendored
Normal file
9
internal/meta/testdata/fstop-favorite.xmp
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:fstop="http://www.fstopapp.com/xmp/"
|
||||
fstop:favorite="1"/>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
<?xpacket end="w"?>
|
|
@ -76,5 +76,7 @@ func (data *Data) XMP(fileName string) (err error) {
|
|||
data.AddKeywords(doc.Keywords())
|
||||
}
|
||||
|
||||
data.Favorite = doc.Favorite()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -32,20 +32,21 @@ type XmpDocument struct {
|
|||
XmpRights string `xml:"xmpRights,attr" json:"xmprights,omitempty"`
|
||||
Iptc4xmpCore string `xml:"Iptc4xmpCore,attr" json:"iptc4xmpcore,omitempty"`
|
||||
Iptc4xmpExt string `xml:"Iptc4xmpExt,attr" json:"iptc4xmpext,omitempty"`
|
||||
CreatorTool string `xml:"CreatorTool"` // ELE-L29 10.0.0.168(C431E2...
|
||||
ModifyDate string `xml:"ModifyDate"` // 2020-01-01T17:28:23.89961...
|
||||
CreateDate string `xml:"CreateDate"` // 2020-01-01T17:28:23
|
||||
MetadataDate string `xml:"MetadataDate"` // 2020-01-01T17:28:23.89961...
|
||||
Rating string `xml:"Rating"` // 4
|
||||
Lens string `xml:"Lens"` // HUAWEI P30 Rear Main Came...
|
||||
LensModel string `xml:"LensModel"` // HUAWEI P30 Rear Main Came...
|
||||
DateCreated string `xml:"DateCreated"` // 2020-01-01T17:28:25.72962...
|
||||
ColorMode string `xml:"ColorMode"` // 3
|
||||
ICCProfile string `xml:"ICCProfile"` // sRGB IEC61966-2.1
|
||||
AuthorsPosition string `xml:"AuthorsPosition"` // Maintainer
|
||||
DocumentID string `xml:"DocumentID"` // 2C678C1811D7095FD79CC822B...
|
||||
InstanceID string `xml:"InstanceID"` // 2C678C1811D7095FD79CC822B...
|
||||
Format string `xml:"format"` // image/jpeg
|
||||
CreatorTool string `xml:"CreatorTool"` // ELE-L29 10.0.0.168(C431E2...
|
||||
ModifyDate string `xml:"ModifyDate"` // 2020-01-01T17:28:23.89961...
|
||||
CreateDate string `xml:"CreateDate"` // 2020-01-01T17:28:23
|
||||
MetadataDate string `xml:"MetadataDate"` // 2020-01-01T17:28:23.89961...
|
||||
Rating string `xml:"Rating"` // 4
|
||||
FStopFavorite string `xml:"http://www.fstopapp.com/xmp/ favorite,attr"` // 1
|
||||
Lens string `xml:"Lens"` // HUAWEI P30 Rear Main Came...
|
||||
LensModel string `xml:"LensModel"` // HUAWEI P30 Rear Main Came...
|
||||
DateCreated string `xml:"DateCreated"` // 2020-01-01T17:28:25.72962...
|
||||
ColorMode string `xml:"ColorMode"` // 3
|
||||
ICCProfile string `xml:"ICCProfile"` // sRGB IEC61966-2.1
|
||||
AuthorsPosition string `xml:"AuthorsPosition"` // Maintainer
|
||||
DocumentID string `xml:"DocumentID"` // 2C678C1811D7095FD79CC822B...
|
||||
InstanceID string `xml:"InstanceID"` // 2C678C1811D7095FD79CC822B...
|
||||
Format string `xml:"format"` // image/jpeg
|
||||
Title struct {
|
||||
Text string `xml:",chardata" json:"text,omitempty"`
|
||||
Alt struct {
|
||||
|
@ -283,3 +284,12 @@ func (doc *XmpDocument) Keywords() string {
|
|||
|
||||
return strings.Join(s, ", ")
|
||||
}
|
||||
|
||||
// Favorite returns a favorite status in the XMP document.
|
||||
func (doc *XmpDocument) Favorite() bool {
|
||||
fstop := doc.RDF.Description.FStopFavorite
|
||||
if fstop == "1" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -68,6 +68,17 @@ func TestXMP(t *testing.T) {
|
|||
assert.Equal(t, "Apple", data.CameraMake)
|
||||
assert.Equal(t, "iPhone 7", data.CameraModel)
|
||||
assert.Equal(t, "iPhone 7 back camera 3.99mm f/1.8", data.LensModel)
|
||||
assert.Equal(t, false, data.Favorite)
|
||||
})
|
||||
|
||||
t.Run("fstop", func(t *testing.T) {
|
||||
data, err := XMP("testdata/fstop-favorite.xmp")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, true, data.Favorite)
|
||||
})
|
||||
|
||||
t.Run("DateHeic", func(t *testing.T) {
|
||||
|
|
|
@ -437,6 +437,11 @@ func (ind *Index) UserMediaFile(m *MediaFile, o IndexOptions, originalName, phot
|
|||
details.SetCopyright(metaData.Copyright, entity.SrcXmp)
|
||||
details.SetLicense(metaData.License, entity.SrcXmp)
|
||||
details.SetSoftware(metaData.Software, entity.SrcXmp)
|
||||
|
||||
// Update externally marked as favorite.
|
||||
if metaData.Favorite {
|
||||
photo.SetFavorite(metaData.Favorite)
|
||||
}
|
||||
} else {
|
||||
log.Warn(err.Error())
|
||||
file.FileError = err.Error()
|
||||
|
|
Loading…
Reference in a new issue