Write ratings, keywords, hierarchy and IPTC to XMP
Sidecars and JPEG exports now carry xmp:Rating, xmp:Label, dc:subject and lr:hierarchicalSubject plus the IPTC core, and importing a sidecar applies its cataloguing fields independently of its develop settings. Hierarchical keywords keep leaf terms in the flat list, so search and filters are unchanged.
This commit is contained in:
+76
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { defaultEdits, defaultLocalLayer, normalizeEdits } from './edits';
|
||||
import { editsToXmp, xmpFileName, xmpToEdits } from './xmp';
|
||||
import { editsToXmp, xmpFileName, xmpToEdits, xmpToMetadata } from './xmp';
|
||||
|
||||
describe('xmp sidecars', () => {
|
||||
it('round-trips every develop field exactly', () => {
|
||||
@@ -55,3 +55,78 @@ describe('xmp sidecars', () => {
|
||||
expect(xmpFileName('no-extension')).toBe('no-extension.xmp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('xmp metadata', () => {
|
||||
const photo = {
|
||||
name: 'DSC0123.ARW',
|
||||
meta: {},
|
||||
rating: 4,
|
||||
color: 'green' as const,
|
||||
keywords: ['Birds', 'Robin'],
|
||||
keywordPaths: ['Nature', 'Nature > Birds', 'Nature > Birds > Robin'],
|
||||
iptc: {
|
||||
headline: 'Dawn chorus',
|
||||
credit: 'B. Hursey',
|
||||
source: 'Field notes',
|
||||
city: 'Bristol',
|
||||
state: 'Somerset',
|
||||
country: 'UK',
|
||||
location: 'Ashton Court',
|
||||
},
|
||||
title: 'Robin at dawn',
|
||||
caption: 'First light, heavy frost',
|
||||
creator: 'Brian Hursey',
|
||||
copyright: '© 2026 Brian Hursey',
|
||||
};
|
||||
|
||||
it('writes rating, label, keywords, hierarchy and IPTC, and reads them back', () => {
|
||||
const xml = editsToXmp(defaultEdits(), photo);
|
||||
expect(xml).toContain('xmp:Rating="4"');
|
||||
expect(xml).toContain('xmp:Label="Green"');
|
||||
expect(xml).toContain('<lr:hierarchicalSubject>');
|
||||
expect(xml).toContain('photoshop:City="Bristol"');
|
||||
expect(xml).toContain('Iptc4xmpCore:Location="Ashton Court"');
|
||||
|
||||
const meta = xmpToMetadata(xml);
|
||||
expect(meta.rating).toBe(4);
|
||||
expect(meta.label).toBe('green');
|
||||
expect(meta.keywords).toEqual(['Birds', 'Robin']);
|
||||
expect(meta.keywordPaths).toEqual([
|
||||
'Nature',
|
||||
'Nature > Birds',
|
||||
'Nature > Birds > Robin',
|
||||
]);
|
||||
expect(meta.iptc).toEqual(photo.iptc);
|
||||
expect(meta.title).toBe('Robin at dawn');
|
||||
expect(meta.caption).toBe('First light, heavy frost');
|
||||
expect(meta.creator).toBe('Brian Hursey');
|
||||
expect(meta.copyright).toBe('© 2026 Brian Hursey');
|
||||
});
|
||||
|
||||
it('reads a sidecar written by Lightroom', () => {
|
||||
const xml = `<?xpacket begin=""?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:lr="http://ns.adobe.com/lightroom/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmp:Rating="2" xmp:Label="Red" photoshop:Headline="Press day" photoshop:Country="Ireland"><dc:subject><rdf:Bag><rdf:li>Portrait</rdf:li><rdf:li>Maya</rdf:li></rdf:Bag></dc:subject><lr:hierarchicalSubject><rdf:Bag><rdf:li>People > Portrait</rdf:li></rdf:Bag></lr:hierarchicalSubject></rdf:Description></rdf:RDF></x:xmpmeta>`;
|
||||
const meta = xmpToMetadata(xml);
|
||||
expect(meta.rating).toBe(2);
|
||||
expect(meta.label).toBe('red');
|
||||
expect(meta.keywords).toEqual(['Portrait', 'Maya']);
|
||||
expect(meta.keywordPaths).toEqual(['People > Portrait']);
|
||||
expect(meta.iptc.headline).toBe('Press day');
|
||||
expect(meta.iptc.country).toBe('Ireland');
|
||||
// Nothing the file does not carry is invented.
|
||||
expect(meta.iptc.city).toBeUndefined();
|
||||
expect(meta.caption).toBeUndefined();
|
||||
});
|
||||
|
||||
it('stays quiet when the file has no metadata', () => {
|
||||
const meta = xmpToMetadata(editsToXmp(defaultEdits()));
|
||||
expect(meta.rating).toBeUndefined();
|
||||
expect(meta.label).toBeUndefined();
|
||||
expect(meta.keywords).toEqual([]);
|
||||
expect(meta.keywordPaths).toEqual([]);
|
||||
expect(meta.iptc).toEqual({});
|
||||
});
|
||||
|
||||
it('rejects a file that is not a sidecar', () => {
|
||||
expect(() => xmpToMetadata('<html></html>')).toThrow(/not an XMP/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user