XMP sidecars: a tag list with several items is ignored, and a sidecar with a single rdf:Description yields nothing but GPS
Summary
Layouts of .xmp sidecar that immich-go reads wrongly (v0.32.0, internal/exif/sidecars/xmpsidecar/read.go):
- a
digiKam:TagsListwith more than onerdf:li: none of the tags is applied (a list with a single item works); - a description repeated in several languages (an
rdf:Altwith more than onerdf:li): the description is dropped; - all properties in one
rdf:Descriptionelement: nothing is read except the GPS coordinates; description, date, rating and tags are dropped.
Cause
The reader walks the parsed document and matches property paths such as TagsList/Seq/li. walk appends an index to the elements of a list (Description[2], li[1]), and filter strips only the index of the Description element:
- with several
rdf:li, each item's path gets ali[N]segment and matches nothing; - with a single
rdf:Descriptionthere is no index, the prefix/xmpmeta/RDF/Description/is never stripped, and the properties' paths match nothing; the GPS cases are written for exactly that unindexed form, which is why they are the only ones that work in this layout (and they never match in the multi-Description layout).
walk also reassigns its path variable when it meets a list, so the keys that follow the list in the same element are looked up under a wrong prefix.
Reproduction
Two of the sidecars added as test data in the PR (excerpted):
<!-- multi-tags.jpg.xmp: three tags, several rdf:Description elements -->
<rdf:Description xmlns:digiKam='http://www.digikam.org/ns/1.0/'>
<digiKam:TagsList><rdf:Seq><rdf:li>ari</rdf:li><rdf:li>baldur</rdf:li><rdf:li>people/jakob</rdf:li></rdf:Seq></digiKam:TagsList>
</rdf:Description><!-- single-description.jpg.xmp: everything in one rdf:Description -->
<rdf:Description rdf:about='' xmlns:tiff='…' xmlns:digiKam='…' xmlns:exif='…' xmlns:xmp='…'>
<tiff:ImageDescription><rdf:Alt><rdf:li xml:lang='x-default'>All in one</rdf:li></rdf:Alt></tiff:ImageDescription>
<digiKam:TagsList><rdf:Seq><rdf:li>solo</rdf:li></rdf:Seq></digiKam:TagsList>
<exif:DateTimeOriginal>2020-02-02T10:20:30Z</exif:DateTimeOriginal>
<exif:GPSLatitude>48,24.50256879N</exif:GPSLatitude>
<exif:GPSLongitude>3,5.43538761W</exif:GPSLongitude>
<xmp:Rating>3</xmp:Rating>
</rdf:Description>ReadXMP reads no tags from the first (expected 3 tags, got 0), and from the second only the latitude and longitude: description, date, rating and tags all stay at their zero values.
Seen in practice with upload from-folder on a tree with 1,918 generated sidecars: files with one keyword were tagged, files with two or more got no tags at all (e.g. a keyword present in 711 sidecars was applied to 453 assets, only where it was the single item).
Fix
PR #1431: strip every list index and the /xmpmeta/RDF/Description/ prefix before matching, match GPS on the normalised path like the other properties, take the first entry of a multi-language description (the XMP specification puts x-default first), and keep walk's path local.
Source: simulot/immich-go