PM-.snap-Import (FieldsToApply, Merge, Aufnahmedatum), Aufnahmeort/Copyright-Status/DataMining, FTP-Profile Beautiful Sports
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
1 parent
0b41f09206
commit
42ab9c9361
13 files changed
+470
-37
No files matched your search
+2
-1
@@ -18,7 +18,8 @@ let package = Package(
|
|||||||
.testTarget(
|
.testTarget(
|
||||||
name: "LichtkastenCoreTests",
|
name: "LichtkastenCoreTests",
|
||||||
dependencies: ["LichtkastenCore"],
|
dependencies: ["LichtkastenCore"],
|
||||||
path: "Tests/LichtkastenCoreTests"
|
path: "Tests/LichtkastenCoreTests",
|
||||||
|
resources: [.copy("Fixtures")]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -12,7 +12,7 @@ Schneller Foto-Browser und Metadaten-Editor für macOS (Apple Silicon), gedacht
|
|||||||
| **Culling** | Kontaktabzug über die eingebetteten RAW-Vorschauen (ImageIO), RAW+JPEG als Paar, Vollbildvorschau, 100-%-Ansicht (Z), Filter (Tag, Sterne, Farbe), Suche, Sortierung |
|
| **Culling** | Kontaktabzug über die eingebetteten RAW-Vorschauen (ImageIO), RAW+JPEG als Paar, Vollbildvorschau, 100-%-Ansicht (Z), Filter (Tag, Sterne, Farbe), Suche, Sortierung |
|
||||||
| **Bewertung** | Sterne, Farbmarkierungen und Tags. Gespeichert als `xmp:Rating`, `xmp:Label` und `photomechanic:Tagged/ColorClass`, damit Lightroom **und** PM die Werte lesen |
|
| **Bewertung** | Sterne, Farbmarkierungen und Tags. Gespeichert als `xmp:Rating`, `xmp:Label` und `photomechanic:Tagged/ColorClass`, damit Lightroom **und** PM die Werte lesen |
|
||||||
| **IPTC** | Alle Felder in der Reihenfolge des PM-Stationery-Pads. Geschrieben werden IIM **und** XMP synchron (UTF-8, `CodedCharacterSet`, `IPTCDigest`), bei RAWs als XMP-Sidecar. Byte-Zähler warnt bei IIM-Limits |
|
| **IPTC** | Alle Felder in der Reihenfolge des PM-Stationery-Pads. Geschrieben werden IIM **und** XMP synchron (UTF-8, `CodedCharacterSet`, `IPTCDigest`), bei RAWs als XMP-Sidecar. Byte-Zähler warnt bei IIM-Limits |
|
||||||
| **Vorlagen** | Vorlagen anlegen, Import von Photo-Mechanic-Vorlagen (`.xmp`), Import aus Bildern mit IPTC, Export als XMP, Stichwörter anhängen oder ersetzen |
|
| **Vorlagen** | Import von Photo-Mechanic-Vorlagen (`.snap` und `.xmp`) inklusive der PM-Häkchen, welche Felder angewendet werden, Stichwörter anhängen/ersetzen und „Datum = Aufnahmezeit“. Außerdem Import aus Bildern mit IPTC und Export als XMP |
|
||||||
| **Variablen & Codes** | `{date}`, `{city}`, `{filenamebase}`, `{model}` usw. sowie PM-Code-Ersetzungen `\code\` und `\code#2\` aus Tab-Dateien |
|
| **Variablen & Codes** | `{date}`, `{city}`, `{filenamebase}`, `{model}` usw. sowie PM-Code-Ersetzungen `\code\` und `\code#2\` aus Tab-Dateien |
|
||||||
| **Ingest** | Von einer oder mehreren Karten kopieren, mit Backup-Ziel, Ordner- und Umbenennungsmuster, Vorlage beim Ingest |
|
| **Ingest** | Von einer oder mehreren Karten kopieren, mit Backup-Ziel, Ordner- und Umbenennungsmuster, Vorlage beim Ingest |
|
||||||
| **Lightroom Classic** | ⌘⇧L importiert die Auswahl in den offenen Katalog. ⌘⌥L importiert, wendet die Entwicklungsvorgabe an und exportiert JPEGs, auf Wunsch mit automatischem Upload |
|
| **Lightroom Classic** | ⌘⇧L importiert die Auswahl in den offenen Katalog. ⌘⌥L importiert, wendet die Entwicklungsvorgabe an und exportiert JPEGs, auf Wunsch mit automatischem Upload |
|
||||||
@@ -77,3 +77,15 @@ Sources/Lichtkasten SwiftUI-App
|
|||||||
LightroomPlugin Lua-Plugin für Lightroom Classic
|
LightroomPlugin Lua-Plugin für Lightroom Classic
|
||||||
Tests XCTest für den Core
|
Tests XCTest für den Core
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Photo-Mechanic-Vorlagen (.snap)
|
||||||
|
|
||||||
|
PM speichert Vorlagen als `.snap`: ein XMP-Block plus Steuerdaten. Lichtkasten übernimmt daraus:
|
||||||
|
|
||||||
|
- **FieldsToApply**: nur die in PM angehakten Felder werden geschrieben. Die Codes sind `0x200 + IIM-Datensatz`,
|
||||||
|
z. B. `0x25a` = 2:90 Stadt. Die XMP-only-Felder nutzen PM-interne Codes. Bisher bekannt ist nur `0x8013` = Ereignis.
|
||||||
|
Unbekannte Codes zeigt der Vorlagen-Editor an.
|
||||||
|
- **FieldsToMerge**: Stehen die Stichwörter (`0x219`) dort nicht, werden sie **ersetzt** und nicht angehängt.
|
||||||
|
- **ApplyDateType/ApplyDateStyle = 2**: Datum und Uhrzeit (IIM 2:55/2:60, `photoshop:DateCreated`) kommen aus der Aufnahmezeit.
|
||||||
|
|
||||||
|
Alle Häkchen lassen sich im Vorlagen-Editor (⌘⇧T) pro Feld ändern.
|
||||||
@@ -66,9 +66,23 @@ final class AppState: ObservableObject {
|
|||||||
templates = Storage.load([IPTCTemplate].self, from: Storage.templatesURL) ?? []
|
templates = Storage.load([IPTCTemplate].self, from: Storage.templatesURL) ?? []
|
||||||
codes = Storage.load(CodeReplacements.self, from: Storage.codesURL) ?? CodeReplacements()
|
codes = Storage.load(CodeReplacements.self, from: Storage.codesURL) ?? CodeReplacements()
|
||||||
uploads.state = self
|
uploads.state = self
|
||||||
|
seedDefaultsIfNeeded()
|
||||||
startLightroomPolling()
|
startLightroomPolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// First launch: agency FTP profiles (host/user are placeholders – adjust in Settings → FTP).
|
||||||
|
private func seedDefaultsIfNeeded() {
|
||||||
|
guard settings.ftpDestinations.isEmpty, !UserDefaults.standard.bool(forKey: "seededFTP") else { return }
|
||||||
|
UserDefaults.standard.set(true, forKey: "seededFTP")
|
||||||
|
let host = "beautifulsports.ftp.xxx.com"
|
||||||
|
settings.ftpDestinations = [
|
||||||
|
FTPDestination(name: "Beautiful Sports – Sport", proto: .ftp, host: host, port: 21,
|
||||||
|
remoteDirectory: "/Tonhäuser_Sport", passive: true, variant: .jpeg),
|
||||||
|
FTPDestination(name: "Beautiful Sports – Stock", proto: .ftp, host: host, port: 21,
|
||||||
|
remoteDirectory: "/Tonhäuser_Stock", passive: true, variant: .jpeg),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: exiftool
|
// MARK: exiftool
|
||||||
|
|
||||||
var exiftool: ExifTool? {
|
var exiftool: ExifTool? {
|
||||||
@@ -329,11 +343,11 @@ final class AppState: ObservableObject {
|
|||||||
panel.allowedContentTypes = []
|
panel.allowedContentTypes = []
|
||||||
panel.allowsOtherFileTypes = true
|
panel.allowsOtherFileTypes = true
|
||||||
panel.allowsMultipleSelection = true
|
panel.allowsMultipleSelection = true
|
||||||
panel.message = "Photo Mechanic Vorlage(n) (.xmp) oder Bilder mit IPTC wählen"
|
panel.message = "Photo-Mechanic-Vorlage(n) (.snap / .xmp) oder Bilder mit IPTC wählen"
|
||||||
guard panel.runModal() == .OK else { return }
|
guard panel.runModal() == .OK else { return }
|
||||||
for url in panel.urls {
|
for url in panel.urls {
|
||||||
do {
|
do {
|
||||||
if url.pathExtension.lowercased() == "xmp" || url.pathExtension.lowercased() == "xml" {
|
if ["xmp", "xml", "snap"].contains(url.pathExtension.lowercased()) {
|
||||||
templates.append(try XMPTemplateIO.importTemplate(from: url))
|
templates.append(try XMPTemplateIO.importTemplate(from: url))
|
||||||
} else {
|
} else {
|
||||||
try templateFromImage(url)
|
try templateFromImage(url)
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ struct IPTCFieldsForm: View {
|
|||||||
var mixed: Set<String> = []
|
var mixed: Set<String> = []
|
||||||
var dirty: Set<String> = []
|
var dirty: Set<String> = []
|
||||||
var onEdit: (String) -> Void = { _ in }
|
var onEdit: (String) -> Void = { _ in }
|
||||||
|
/// PM-style "apply" checkboxes (template editor only).
|
||||||
|
var applied: Binding<Set<String>>? = nil
|
||||||
@AppStorage("collapsedIPTCSections") private var collapsedRaw = ""
|
@AppStorage("collapsedIPTCSections") private var collapsedRaw = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -32,10 +34,23 @@ struct IPTCFieldsForm: View {
|
|||||||
DisclosureGroup(isExpanded: expandedBinding(section)) {
|
DisclosureGroup(isExpanded: expandedBinding(section)) {
|
||||||
VStack(alignment: .leading, spacing: 6) {
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
ForEach(fields) { field in
|
ForEach(fields) { field in
|
||||||
|
HStack(alignment: .top, spacing: 6) {
|
||||||
|
if let applied {
|
||||||
|
Toggle("", isOn: Binding(
|
||||||
|
get: { applied.wrappedValue.contains(field.id) },
|
||||||
|
set: { on in
|
||||||
|
if on { applied.wrappedValue.insert(field.id) } else { applied.wrappedValue.remove(field.id) }
|
||||||
|
}))
|
||||||
|
.toggleStyle(.checkbox)
|
||||||
|
.labelsHidden()
|
||||||
|
.padding(.top, 16)
|
||||||
|
.help("Feld beim Anwenden schreiben (wie das Häkchen in Photo Mechanic)")
|
||||||
|
}
|
||||||
FieldRow(field: field, text: binding(field), isMixed: mixed.contains(field.id) && !dirty.contains(field.id),
|
FieldRow(field: field, text: binding(field), isMixed: mixed.contains(field.id) && !dirty.contains(field.id),
|
||||||
isDirty: dirty.contains(field.id))
|
isDirty: dirty.contains(field.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.padding(.top, 4)
|
.padding(.top, 4)
|
||||||
} label: {
|
} label: {
|
||||||
Text(section.rawValue).font(.headline)
|
Text(section.rawValue).font(.headline)
|
||||||
|
|||||||
@@ -103,16 +103,34 @@ struct TemplateManagerView: View {
|
|||||||
ForEach(ListMergeMode.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
ForEach(ListMergeMode.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||||||
}
|
}
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
Toggle("Leere Felder löschen beim Anwenden", isOn: $state.templates[i].clearEmptyFields)
|
Toggle("Nur angehakte Felder (wie PM)", isOn: Binding(
|
||||||
|
get: { state.templates[i].appliedFields != nil },
|
||||||
|
set: { on in
|
||||||
|
let t = state.templates[i]
|
||||||
|
state.templates[i].appliedFields = on
|
||||||
|
? Set(IPTCField.all.filter { !t.values.isEmpty($0) }.map(\.id)) : nil
|
||||||
|
}))
|
||||||
|
if state.templates[i].appliedFields == nil {
|
||||||
|
Toggle("Leere Felder löschen", isOn: $state.templates[i].clearEmptyFields)
|
||||||
|
}
|
||||||
|
Toggle("Datum = Aufnahmezeit", isOn: $state.templates[i].dateFromCapture)
|
||||||
|
.help("Erstellungsdatum/-zeit aus der EXIF-Aufnahmezeit jedes Bildes (PM: Apply Date → Capture Date)")
|
||||||
}
|
}
|
||||||
.font(.callout)
|
.font(.callout)
|
||||||
|
if !state.templates[i].unmappedPMCodes.isEmpty {
|
||||||
|
Text("Unbekannte PM-Feldcodes: \(state.templates[i].unmappedPMCodes.joined(separator: ", ")) – bitte Häkchen prüfen.")
|
||||||
|
.font(.caption).foregroundStyle(.orange)
|
||||||
|
}
|
||||||
if !state.templates[i].extras.isEmpty {
|
if !state.templates[i].extras.isEmpty {
|
||||||
Text("\(state.templates[i].extras.count) zusätzliche XMP-Felder aus PM werden beim Export beibehalten.")
|
Text("\(state.templates[i].extras.count) zusätzliche XMP-Felder aus PM werden beim Export beibehalten.")
|
||||||
.font(.caption).foregroundStyle(.secondary)
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
Divider()
|
Divider()
|
||||||
ScrollView {
|
ScrollView {
|
||||||
IPTCFieldsForm(texts: $texts) { _ in save() }
|
IPTCFieldsForm(texts: $texts, onEdit: { _ in save() },
|
||||||
|
applied: state.templates[i].appliedFields == nil ? nil : Binding(
|
||||||
|
get: { state.templates[i].appliedFields ?? [] },
|
||||||
|
set: { state.templates[i].appliedFields = $0 }))
|
||||||
.padding(.trailing, 8)
|
.padding(.trailing, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public struct PhotoItem: Identifiable, Hashable, Sendable {
|
|||||||
|
|
||||||
var values = IPTCValues()
|
var values = IPTCValues()
|
||||||
for field in IPTCField.all {
|
for field in IPTCField.all {
|
||||||
let v = xmp(field.xmpTag) ?? field.iimTag.flatMap { fileMeta[$0] }
|
let v = xmp(field.xmpReadKey) ?? field.iimTag.flatMap { fileMeta[$0] }
|
||||||
guard let v else { continue }
|
guard let v else { continue }
|
||||||
if field.kind == .list {
|
if field.kind == .list {
|
||||||
let l = v.list.filter { !$0.isEmpty }
|
let l = v.list.filter { !$0.isEmpty }
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public final class ExifTool: @unchecked Sendable {
|
|||||||
var args = ["-json", "-G1", "-fast", "-a",
|
var args = ["-json", "-G1", "-fast", "-a",
|
||||||
"-XMP-xmp:Rating#", "-XMP-xmp:Label", "-XMP-photomech:Tagged#", "-XMP-photomech:ColorClass#",
|
"-XMP-xmp:Rating#", "-XMP-xmp:Label", "-XMP-photomech:Tagged#", "-XMP-photomech:ColorClass#",
|
||||||
"-Make", "-Model", "-LensModel", "-LensID", "-SerialNumber", "-ISO", "-ExposureTime", "-FNumber",
|
"-Make", "-Model", "-LensModel", "-LensID", "-SerialNumber", "-ISO", "-ExposureTime", "-FNumber",
|
||||||
"-FocalLength", "-DateTimeOriginal", "-CreateDate", "-SubSecTimeOriginal", "-ImageWidth", "-ImageHeight",
|
"-FocalLength", "-DateTimeOriginal", "-CreateDate", "-SubSecTimeOriginal", "-OffsetTimeOriginal", "-ImageWidth", "-ImageHeight",
|
||||||
"-Orientation#", "-Artist", "-GPSLatitude#", "-GPSLongitude#"]
|
"-Orientation#", "-Artist", "-GPSLatitude#", "-GPSLongitude#"]
|
||||||
for f in IPTCField.all {
|
for f in IPTCField.all {
|
||||||
if let iim = f.iimTag { args.append("-" + iim) }
|
if let iim = f.iimTag { args.append("-" + iim) }
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ public enum XMPNamespace {
|
|||||||
public static let xmpRights = "http://ns.adobe.com/xap/1.0/rights/"
|
public static let xmpRights = "http://ns.adobe.com/xap/1.0/rights/"
|
||||||
public static let xmp = "http://ns.adobe.com/xap/1.0/"
|
public static let xmp = "http://ns.adobe.com/xap/1.0/"
|
||||||
public static let photomechanic = "http://ns.camerabits.com/photomechanic/1.0/"
|
public static let photomechanic = "http://ns.camerabits.com/photomechanic/1.0/"
|
||||||
|
public static let plus = "http://ns.useplus.org/ldf/xmp/1.0/"
|
||||||
public static let rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
public static let rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
|
||||||
/// Prefix normally used when we write a template file back out.
|
/// Prefix normally used when we write a template file back out.
|
||||||
public static let preferredPrefix: [String: String] = [
|
public static let preferredPrefix: [String: String] = [
|
||||||
dc: "dc", photoshop: "photoshop", iptcCore: "Iptc4xmpCore", iptcExt: "Iptc4xmpExt",
|
dc: "dc", photoshop: "photoshop", iptcCore: "Iptc4xmpCore", iptcExt: "Iptc4xmpExt",
|
||||||
xmpRights: "xmpRights", xmp: "xmp", photomechanic: "photomechanic",
|
xmpRights: "xmpRights", xmp: "xmp", photomechanic: "photomechanic", plus: "plus",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ public enum IPTCFieldKind: String, Codable, Sendable {
|
|||||||
public enum IPTCSection: String, CaseIterable, Codable, Sendable {
|
public enum IPTCSection: String, CaseIterable, Codable, Sendable {
|
||||||
case description = "Beschreibung"
|
case description = "Beschreibung"
|
||||||
case location = "Ort"
|
case location = "Ort"
|
||||||
|
case locationCreated = "Aufnahmeort (IPTC Ext)"
|
||||||
case creator = "Urheber & Rechte"
|
case creator = "Urheber & Rechte"
|
||||||
case contact = "Kontakt des Urhebers"
|
case contact = "Kontakt des Urhebers"
|
||||||
case extended = "Erweitert (IPTC Core/Ext)"
|
case extended = "Erweitert (IPTC Core/Ext)"
|
||||||
@@ -108,6 +110,20 @@ public extension IPTCField {
|
|||||||
f("countryCode", "Ländercode (ISO)", pm: "Country Code", .location,
|
f("countryCode", "Ländercode (ISO)", pm: "Country Code", .location,
|
||||||
iim: "IPTC:Country-PrimaryLocationCode", xmp: "XMP-iptcCore:CountryCode", ns: XMPNamespace.iptcCore, local: "CountryCode", max: 3),
|
iim: "IPTC:Country-PrimaryLocationCode", xmp: "XMP-iptcCore:CountryCode", ns: XMPNamespace.iptcCore, local: "CountryCode", max: 3),
|
||||||
|
|
||||||
|
// --- Aufnahmeort (Iptc4xmpExt:LocationCreated, Struktur in einer Bag) ---
|
||||||
|
f("lcSublocation", "Ortsdetail", pm: "Location Created: Sublocation", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedSublocation", ns: XMPNamespace.iptcExt, local: "Sublocation"),
|
||||||
|
f("lcCity", "Stadt", pm: "Location Created: City", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedCity", ns: XMPNamespace.iptcExt, local: "City"),
|
||||||
|
f("lcState", "Bundesland", pm: "Location Created: State/Province", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedProvinceState", ns: XMPNamespace.iptcExt, local: "ProvinceState"),
|
||||||
|
f("lcCountry", "Land", pm: "Location Created: Country", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedCountryName", ns: XMPNamespace.iptcExt, local: "CountryName"),
|
||||||
|
f("lcCountryCode", "Ländercode", pm: "Location Created: Country Code", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedCountryCode", ns: XMPNamespace.iptcExt, local: "CountryCode"),
|
||||||
|
f("lcWorldRegion", "Weltregion", pm: "Location Created: World Region", .locationCreated,
|
||||||
|
iim: nil, xmp: "XMP-iptcExt:LocationCreatedWorldRegion", ns: XMPNamespace.iptcExt, local: "WorldRegion"),
|
||||||
|
|
||||||
// --- Urheber & Rechte ---
|
// --- Urheber & Rechte ---
|
||||||
f("creator", "Fotograf", pm: "Photographer / Creator", .creator,
|
f("creator", "Fotograf", pm: "Photographer / Creator", .creator,
|
||||||
iim: "IPTC:By-line", xmp: "XMP-dc:Creator", ns: XMPNamespace.dc, local: "creator", container: .seq, max: 32),
|
iim: "IPTC:By-line", xmp: "XMP-dc:Creator", ns: XMPNamespace.dc, local: "creator", container: .seq, max: 32),
|
||||||
@@ -119,6 +135,10 @@ public extension IPTCField {
|
|||||||
iim: "IPTC:Source", xmp: "XMP-photoshop:Source", ns: XMPNamespace.photoshop, local: "Source", max: 32),
|
iim: "IPTC:Source", xmp: "XMP-photoshop:Source", ns: XMPNamespace.photoshop, local: "Source", max: 32),
|
||||||
f("copyright", "Copyright-Vermerk", pm: "Copyright Notice", .creator,
|
f("copyright", "Copyright-Vermerk", pm: "Copyright Notice", .creator,
|
||||||
iim: "IPTC:CopyrightNotice", xmp: "XMP-dc:Rights", ns: XMPNamespace.dc, local: "rights", container: .alt, max: 128),
|
iim: "IPTC:CopyrightNotice", xmp: "XMP-dc:Rights", ns: XMPNamespace.dc, local: "rights", container: .alt, max: 128),
|
||||||
|
f("copyrightMarked", "Copyright-Status (True = geschützt)", pm: "Copyright Status", .creator,
|
||||||
|
iim: nil, xmp: "XMP-xmpRights:Marked", ns: XMPNamespace.xmpRights, local: "Marked"),
|
||||||
|
f("dataMining", "Data Mining (PLUS)", pm: "Data Mining", .creator,
|
||||||
|
iim: nil, xmp: "XMP-plus:DataMining#", ns: XMPNamespace.plus, local: "DataMining"),
|
||||||
f("usageTerms", "Nutzungsbedingungen", pm: "Rights Usage Terms", .creator, .multiline,
|
f("usageTerms", "Nutzungsbedingungen", pm: "Rights Usage Terms", .creator, .multiline,
|
||||||
iim: nil, xmp: "XMP-xmpRights:UsageTerms", ns: XMPNamespace.xmpRights, local: "UsageTerms", container: .alt),
|
iim: nil, xmp: "XMP-xmpRights:UsageTerms", ns: XMPNamespace.xmpRights, local: "UsageTerms", container: .alt),
|
||||||
f("webStatement", "Copyright-URL", pm: "Copyright Info URL", .creator,
|
f("webStatement", "Copyright-URL", pm: "Copyright Info URL", .creator,
|
||||||
@@ -153,6 +173,19 @@ public extension IPTCField {
|
|||||||
iim: nil, xmp: "XMP-iptcExt:PersonInImage", ns: XMPNamespace.iptcExt, local: "PersonInImage", container: .bag),
|
iim: nil, xmp: "XMP-iptcExt:PersonInImage", ns: XMPNamespace.iptcExt, local: "PersonInImage", container: .bag),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/// Key in exiftool's JSON output (a trailing "#" only disables print conversion).
|
||||||
|
var xmpReadKey: String { xmpTag.hasSuffix("#") ? String(xmpTag.dropLast()) : xmpTag }
|
||||||
|
|
||||||
|
/// IIM dataset (record 2) per field. Photo Mechanic's .snap lists applied fields as
|
||||||
|
/// 0x200 + dataset (e.g. 0x25a = 2:90 City).
|
||||||
|
static let iimDataset: [String: Int] = [
|
||||||
|
"objectName": 5, "urgency": 10, "category": 15, "supplementalCategories": 20, "keywords": 25,
|
||||||
|
"instructions": 40, "dateCreated": 55, "creator": 80, "creatorJobTitle": 85, "city": 90,
|
||||||
|
"sublocation": 92, "state": 95, "countryCode": 100, "country": 101, "transmissionReference": 103,
|
||||||
|
"headline": 105, "credit": 110, "source": 115, "copyright": 116, "caption": 120, "captionWriter": 122,
|
||||||
|
"intellectualGenre": 4, "subjectCode": 12,
|
||||||
|
]
|
||||||
|
|
||||||
static let byID: [String: IPTCField] = Dictionary(uniqueKeysWithValues: all.map { ($0.id, $0) })
|
static let byID: [String: IPTCField] = Dictionary(uniqueKeysWithValues: all.map { ($0.id, $0) })
|
||||||
|
|
||||||
/// Lookup by XMP namespace + local name (used by the PM template importer).
|
/// Lookup by XMP namespace + local name (used by the PM template importer).
|
||||||
|
|||||||
@@ -47,41 +47,75 @@ public enum ListMergeMode: String, Codable, CaseIterable, Sendable {
|
|||||||
case replace = "Ersetzen"
|
case replace = "Ersetzen"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A metadata template (PM: "IPTC Stationery Pad" / "IPTC Template").
|
/// A metadata template (PM: "IPTC Stationery Pad" / "IPTC Template", .snap).
|
||||||
public struct IPTCTemplate: Codable, Identifiable, Hashable, Sendable {
|
public struct IPTCTemplate: Codable, Identifiable, Hashable, Sendable {
|
||||||
public var id: UUID
|
public var id: UUID
|
||||||
public var name: String
|
public var name: String
|
||||||
public var values: IPTCValues
|
public var values: IPTCValues
|
||||||
public var listMergeMode: ListMergeMode
|
public var listMergeMode: ListMergeMode
|
||||||
/// If true, empty template fields clear the target field (PM: "Replace all").
|
/// If true, empty template fields clear the target field (only used when `appliedFields` is nil).
|
||||||
public var clearEmptyFields: Bool
|
public var clearEmptyFields: Bool
|
||||||
/// XMP properties from an imported PM template we do not model; written back on export.
|
/// PM-style checkboxes: only these fields are applied (an empty checked field clears the target).
|
||||||
|
/// nil = apply every non-empty field.
|
||||||
|
public var appliedFields: Set<String>?
|
||||||
|
/// PM "Apply date: photo capture date" – Date Created comes from EXIF instead of the template value.
|
||||||
|
public var dateFromCapture: Bool
|
||||||
|
/// XMP properties from an imported PM template we do not model; written back on export only.
|
||||||
public var extras: [String: String]
|
public var extras: [String: String]
|
||||||
public var modified: Date
|
public var modified: Date
|
||||||
|
/// PM field codes from an imported .snap that Lichtkasten could not map (shown as hint in the editor).
|
||||||
|
public var unmappedPMCodes: [String] = []
|
||||||
|
|
||||||
public init(id: UUID = UUID(), name: String, values: IPTCValues = IPTCValues(),
|
public init(id: UUID = UUID(), name: String, values: IPTCValues = IPTCValues(),
|
||||||
listMergeMode: ListMergeMode = .append, clearEmptyFields: Bool = false,
|
listMergeMode: ListMergeMode = .append, clearEmptyFields: Bool = false,
|
||||||
|
appliedFields: Set<String>? = nil, dateFromCapture: Bool = false,
|
||||||
extras: [String: String] = [:], modified: Date = Date()) {
|
extras: [String: String] = [:], modified: Date = Date()) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.values = values
|
self.values = values
|
||||||
self.listMergeMode = listMergeMode
|
self.listMergeMode = listMergeMode
|
||||||
self.clearEmptyFields = clearEmptyFields
|
self.clearEmptyFields = clearEmptyFields
|
||||||
|
self.appliedFields = appliedFields
|
||||||
|
self.dateFromCapture = dateFromCapture
|
||||||
self.extras = extras
|
self.extras = extras
|
||||||
self.modified = modified
|
self.modified = modified
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case id, name, values, listMergeMode, clearEmptyFields, appliedFields, dateFromCapture, extras, modified, unmappedPMCodes
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(from decoder: Decoder) throws {
|
||||||
|
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
id = try c.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
|
||||||
|
name = try c.decodeIfPresent(String.self, forKey: .name) ?? "Vorlage"
|
||||||
|
values = try c.decodeIfPresent(IPTCValues.self, forKey: .values) ?? IPTCValues()
|
||||||
|
listMergeMode = try c.decodeIfPresent(ListMergeMode.self, forKey: .listMergeMode) ?? .append
|
||||||
|
clearEmptyFields = try c.decodeIfPresent(Bool.self, forKey: .clearEmptyFields) ?? false
|
||||||
|
appliedFields = try c.decodeIfPresent(Set<String>.self, forKey: .appliedFields)
|
||||||
|
dateFromCapture = try c.decodeIfPresent(Bool.self, forKey: .dateFromCapture) ?? false
|
||||||
|
extras = try c.decodeIfPresent([String: String].self, forKey: .extras) ?? [:]
|
||||||
|
modified = try c.decodeIfPresent(Date.self, forKey: .modified) ?? Date()
|
||||||
|
unmappedPMCodes = try c.decodeIfPresent([String].self, forKey: .unmappedPMCodes) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fields this template writes.
|
||||||
|
public var fieldsToWrite: [IPTCField] {
|
||||||
|
IPTCField.all.filter { f in
|
||||||
|
if let applied = appliedFields { return applied.contains(f.id) }
|
||||||
|
if f.id == "dateCreated" && dateFromCapture { return true }
|
||||||
|
return clearEmptyFields || !values.isEmpty(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Merges the template into existing image values. Variables / codes are NOT expanded here,
|
/// Merges the template into existing image values. Variables / codes are NOT expanded here,
|
||||||
/// that happens per image in `MetadataWriter`.
|
/// that happens per image in `MetadataWriter`.
|
||||||
public func apply(to existing: IPTCValues) -> IPTCValues {
|
public func apply(to existing: IPTCValues) -> IPTCValues {
|
||||||
var result = existing
|
var result = existing
|
||||||
for field in IPTCField.all {
|
for field in fieldsToWrite {
|
||||||
if field.kind == .list {
|
if field.kind == .list {
|
||||||
let tpl = values.list(field)
|
let tpl = values.list(field)
|
||||||
if tpl.isEmpty {
|
if tpl.isEmpty { result.lists[field.id] = nil; continue }
|
||||||
if clearEmptyFields { result.lists[field.id] = nil }
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch listMergeMode {
|
switch listMergeMode {
|
||||||
case .replace:
|
case .replace:
|
||||||
result.lists[field.id] = tpl
|
result.lists[field.id] = tpl
|
||||||
@@ -92,11 +126,7 @@ public struct IPTCTemplate: Codable, Identifiable, Hashable, Sendable {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let tpl = values.text[field.id] ?? ""
|
let tpl = values.text[field.id] ?? ""
|
||||||
if tpl.isEmpty {
|
result.text[field.id] = tpl.isEmpty ? nil : tpl
|
||||||
if clearEmptyFields { result.text[field.id] = nil }
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
result.text[field.id] = tpl
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -57,12 +57,10 @@ public struct MetadataWriter: Sendable {
|
|||||||
if list.isEmpty { args.append("-\(tag)=") }
|
if list.isEmpty { args.append("-\(tag)=") }
|
||||||
for item in list { args.append("-\(tag)=\(item)") }
|
for item in list { args.append("-\(tag)=\(item)") }
|
||||||
}
|
}
|
||||||
|
} else if field.id == "dateCreated" {
|
||||||
|
args += Self.dateArguments(values.text[field.id] ?? "", writeIIM: writeIIM)
|
||||||
} else {
|
} else {
|
||||||
var value = values.text[field.id] ?? ""
|
let value = values.text[field.id] ?? ""
|
||||||
if field.id == "dateCreated" {
|
|
||||||
value = value.replacingOccurrences(of: "-", with: ":")
|
|
||||||
if !value.isEmpty, value.count != 10 { continue } // ignore incomplete dates
|
|
||||||
}
|
|
||||||
for tag in tags {
|
for tag in tags {
|
||||||
if value.isEmpty {
|
if value.isEmpty {
|
||||||
args.append("-\(tag)=")
|
args.append("-\(tag)=")
|
||||||
@@ -79,6 +77,38 @@ public struct MetadataWriter: Sendable {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// "2026-11-02" or "2026-11-02 14:22:01[+01:00]" → XMP DateCreated (full) + IIM DateCreated/TimeCreated.
|
||||||
|
static func dateArguments(_ raw: String, writeIIM: Bool) -> [String] {
|
||||||
|
let v = raw.trimmingCharacters(in: .whitespaces)
|
||||||
|
if v.isEmpty {
|
||||||
|
return ["-XMP-photoshop:DateCreated="] + (writeIIM ? ["-IPTC:DateCreated=", "-IPTC:TimeCreated="] : [])
|
||||||
|
}
|
||||||
|
let normalized = v.replacingOccurrences(of: "T", with: " ")
|
||||||
|
let datePart = String(normalized.prefix(10)).replacingOccurrences(of: "-", with: ":")
|
||||||
|
guard datePart.count == 10, datePart.filter({ $0 == ":" }).count == 2 else { return [] } // invalid → skip
|
||||||
|
let timePart = normalized.count > 11 ? String(normalized.dropFirst(11)) : ""
|
||||||
|
var args = ["-XMP-photoshop:DateCreated=\(datePart)\(timePart.isEmpty ? "" : " " + timePart)"]
|
||||||
|
if writeIIM {
|
||||||
|
args.append("-IPTC:DateCreated=\(datePart)")
|
||||||
|
if !timePart.isEmpty { args.append("-IPTC:TimeCreated=\(timePart)") }
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Capture time from EXIF as "yyyy-MM-dd HH:mm:ss+hh:mm" (camera offset, else the Mac's offset at that date).
|
||||||
|
public static func captureDateValue(exif: [String: String]) -> String? {
|
||||||
|
guard let raw = exif["DateTimeOriginal"] ?? exif["CreateDate"], raw.count >= 19 else { return nil }
|
||||||
|
let clock = String(raw.prefix(19))
|
||||||
|
let datePart = String(clock.prefix(10)).replacingOccurrences(of: ":", with: "-")
|
||||||
|
let timePart = String(clock.suffix(8))
|
||||||
|
var offset = exif["OffsetTimeOriginal"] ?? ""
|
||||||
|
if offset.count != 6, let d = ExifDate.parse(clock) {
|
||||||
|
let secs = TimeZone.current.secondsFromGMT(for: d)
|
||||||
|
offset = String(format: "%@%02d:%02d", secs < 0 ? "-" : "+", abs(secs) / 3600, (abs(secs) % 3600) / 60)
|
||||||
|
}
|
||||||
|
return "\(datePart) \(timePart)\(offset)"
|
||||||
|
}
|
||||||
|
|
||||||
static func relevantMessages(_ stderr: String, file: URL) -> [String] {
|
static func relevantMessages(_ stderr: String, file: URL) -> [String] {
|
||||||
stderr.components(separatedBy: .newlines)
|
stderr.components(separatedBy: .newlines)
|
||||||
.filter { !$0.isEmpty && !$0.contains("image files updated") }
|
.filter { !$0.isEmpty && !$0.contains("image files updated") }
|
||||||
@@ -93,9 +123,12 @@ public extension MetadataWriter {
|
|||||||
dateFormat: String, progress: (@Sendable (Int) -> Void)? = nil) async throws -> [String: IPTCValues] {
|
dateFormat: String, progress: (@Sendable (Int) -> Void)? = nil) async throws -> [String: IPTCValues] {
|
||||||
var result: [String: IPTCValues] = [:]
|
var result: [String: IPTCValues] = [:]
|
||||||
// Fields touched by the template (non-empty, or all if clearEmptyFields).
|
// Fields touched by the template (non-empty, or all if clearEmptyFields).
|
||||||
let fields = IPTCField.all.filter { template.clearEmptyFields || !template.values.isEmpty($0) }
|
let fields = template.fieldsToWrite
|
||||||
for (i, item) in items.enumerated() {
|
for (i, item) in items.enumerated() {
|
||||||
let merged = template.apply(to: item.iptc)
|
var merged = template.apply(to: item.iptc)
|
||||||
|
if template.dateFromCapture, fields.contains(where: { $0.id == "dateCreated" }) {
|
||||||
|
merged.text["dateCreated"] = Self.captureDateValue(exif: item.exif) ?? merged.text["dateCreated"]
|
||||||
|
}
|
||||||
let ctx = VariableContext.make(fileURL: item.primary, exif: item.exif, iptc: merged, dateFormat: dateFormat)
|
let ctx = VariableContext.make(fileURL: item.primary, exif: item.exif, iptc: merged, dateFormat: dateFormat)
|
||||||
let expanded = VariableExpander.expand(merged, context: ctx, codes: codes)
|
let expanded = VariableExpander.expand(merged, context: ctx, codes: codes)
|
||||||
try await write(values: expanded, fields: fields, to: item)
|
try await write(values: expanded, fields: fields, to: item)
|
||||||
|
|||||||
@@ -23,36 +23,90 @@ public enum XMPTemplateIO {
|
|||||||
|
|
||||||
public static func importTemplate(from url: URL) throws -> IPTCTemplate {
|
public static func importTemplate(from url: URL) throws -> IPTCTemplate {
|
||||||
let data = try Data(contentsOf: url)
|
let data = try Data(contentsOf: url)
|
||||||
var t = try parse(data: data)
|
var t = try parseAny(data: data)
|
||||||
t.name = url.deletingPathExtension().lastPathComponent
|
// PM saves "<id>-<Name>.snap" – drop the numeric prefix for display.
|
||||||
|
var name = url.deletingPathExtension().lastPathComponent
|
||||||
|
if let dash = name.firstIndex(of: "-"), name[..<dash].allSatisfy(\.isNumber), name.distance(from: name.startIndex, to: dash) >= 4 {
|
||||||
|
name = String(name[name.index(after: dash)...])
|
||||||
|
}
|
||||||
|
t.name = name.replacingOccurrences(of: "_", with: " ")
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Accepts both a Photo Mechanic `.snap` (IPTCSettings wrapper) and plain XMP.
|
||||||
|
public static func parseAny(data: Data) throws -> IPTCTemplate {
|
||||||
|
if let snap = try? PMSnapFile.parse(data: data), let xmp = snap.xmpRecord {
|
||||||
|
var t = try parse(data: Data(xmp.utf8))
|
||||||
|
applySnapSettings(snap, to: &t)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
return try parse(data: data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PM bookkeeping properties inside the XMP record (not image metadata).
|
||||||
|
static let pmControlProperties: Set<String> = [
|
||||||
|
"FieldsToApply", "FieldsToMerge", "ColorClass", "Tagged", "PMVersion", "ColorClassEval", "ColorClassApply",
|
||||||
|
"RatingEval", "RatingApply", "TagEval", "TagApply", "CaptionMergeStyle", "ApplyDateType", "Prefs",
|
||||||
|
]
|
||||||
|
|
||||||
public static func parse(data: Data) throws -> IPTCTemplate {
|
public static func parse(data: Data) throws -> IPTCTemplate {
|
||||||
let props = try XMPPropertyCollector.collect(data: data)
|
let props = try XMPPropertyCollector.collect(data: data)
|
||||||
var values = IPTCValues()
|
var values = IPTCValues()
|
||||||
var extras: [String: String] = [:]
|
var extras: [String: String] = [:]
|
||||||
|
var pm: [String: [String]] = [:]
|
||||||
var found = 0
|
var found = 0
|
||||||
for p in props {
|
for p in props {
|
||||||
|
if p.namespace == XMPNamespace.photomechanic && pmControlProperties.contains(p.localName) {
|
||||||
|
pm[p.localName] = p.values
|
||||||
|
continue
|
||||||
|
}
|
||||||
if let field = IPTCField.forXMP(namespace: p.namespace, localName: p.localName) {
|
if let field = IPTCField.forXMP(namespace: p.namespace, localName: p.localName) {
|
||||||
found += 1
|
found += 1
|
||||||
if field.kind == .list {
|
if field.kind == .list {
|
||||||
var list = values.lists[field.id] ?? []
|
var list = values.lists[field.id] ?? []
|
||||||
list.append(contentsOf: p.values.filter { !$0.isEmpty })
|
list.append(contentsOf: p.values.filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty })
|
||||||
values.lists[field.id] = list.isEmpty ? nil : list
|
values.lists[field.id] = list.isEmpty ? nil : list
|
||||||
} else {
|
} else {
|
||||||
let v = p.values.joined(separator: field.xmpContainer == .seq ? "; " : "\n")
|
let v = p.values.joined(separator: field.xmpContainer == .seq ? "; " : "\n")
|
||||||
if !v.isEmpty { values.text[field.id] = v }
|
if !v.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { values.text[field.id] = v }
|
||||||
}
|
}
|
||||||
} else if p.namespace != XMPNamespace.rdf, !p.values.isEmpty,
|
} else if p.namespace != XMPNamespace.rdf,
|
||||||
|
p.values.contains(where: { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }),
|
||||||
!(p.namespace == XMPNamespace.iptcCore && p.localName == "CreatorContactInfo") {
|
!(p.namespace == XMPNamespace.iptcCore && p.localName == "CreatorContactInfo") {
|
||||||
extras["\(p.namespace)|\(p.localName)"] = p.values.joined(separator: "\u{1F}")
|
extras["\(p.namespace)|\(p.localName)"] = p.values.joined(separator: "\u{1F}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// PM stores IIM date as yyyy-mm-dd in photoshop:DateCreated – keep only the date part.
|
// Keep only the date part of a fixed Date Created ("2026-02-15T00:00:00+01:00").
|
||||||
if let d = values.text["dateCreated"], d.count > 10 { values.text["dateCreated"] = String(d.prefix(10)) }
|
if let d = values.text["dateCreated"], d.count > 10 { values.text["dateCreated"] = String(d.prefix(10)) }
|
||||||
guard found > 0 || !extras.isEmpty else { throw TemplateImportError.noFieldsFound }
|
guard found > 0 || !extras.isEmpty else { throw TemplateImportError.noFieldsFound }
|
||||||
return IPTCTemplate(name: "Importiert", values: values, extras: extras)
|
|
||||||
|
var t = IPTCTemplate(name: "Importiert", values: values, extras: extras)
|
||||||
|
// PM checkboxes: FieldsToApply holds 0x200 + IIM dataset (0x8000+ = PM extended fields).
|
||||||
|
if let apply = pm["FieldsToApply"] {
|
||||||
|
let codes = Set(apply.compactMap { Int($0.replacingOccurrences(of: "0x", with: ""), radix: 16) })
|
||||||
|
var applied = Set<String>()
|
||||||
|
for (fieldID, ds) in IPTCField.iimDataset where codes.contains(0x200 + ds) { applied.insert(fieldID) }
|
||||||
|
// Extended (XMP-only) fields use PM-internal codes ≥ 0x8000.
|
||||||
|
for c in codes where c >= 0x8000 {
|
||||||
|
if let id = pmExtendedCodes[c] { applied.insert(id) } else { t.unmappedPMCodes.append("0x" + String(c, radix: 16)) }
|
||||||
|
}
|
||||||
|
t.appliedFields = applied
|
||||||
|
}
|
||||||
|
// FieldsToMerge: keywords (0x219) listed → append, else replace (PM default for a template).
|
||||||
|
if let merge = pm["FieldsToMerge"] {
|
||||||
|
t.listMergeMode = merge.contains(where: { $0.lowercased() == "0x219" }) ? .append : .replace
|
||||||
|
}
|
||||||
|
if let dt = pm["ApplyDateType"]?.first { t.dateFromCapture = (dt == "2") }
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Known PM extended field codes (derived from real .snap files; extend when new ones show up).
|
||||||
|
static let pmExtendedCodes: [Int: String] = [
|
||||||
|
0x8013: "event",
|
||||||
|
]
|
||||||
|
|
||||||
|
static func applySnapSettings(_ snap: PMSnapFile, to t: inout IPTCTemplate) {
|
||||||
|
if let style = snap.applyDateStyle { t.dateFromCapture = (style == "2") }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Export
|
// MARK: Export
|
||||||
@@ -61,6 +115,7 @@ public enum XMPTemplateIO {
|
|||||||
var simpleAttrs: [String] = []
|
var simpleAttrs: [String] = []
|
||||||
var elements: [String] = []
|
var elements: [String] = []
|
||||||
var contact: [String] = []
|
var contact: [String] = []
|
||||||
|
var locationCreated: [String] = []
|
||||||
|
|
||||||
func esc(_ s: String) -> String {
|
func esc(_ s: String) -> String {
|
||||||
s.replacingOccurrences(of: "&", with: "&").replacingOccurrences(of: "<", with: "<")
|
s.replacingOccurrences(of: "&", with: "&").replacingOccurrences(of: "<", with: "<")
|
||||||
@@ -77,6 +132,10 @@ public enum XMPTemplateIO {
|
|||||||
contact.append(" <\(q)>\(esc(vals[0]))</\(q)>")
|
contact.append(" <\(q)>\(esc(vals[0]))</\(q)>")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if field.section == .locationCreated {
|
||||||
|
locationCreated.append(" <\(q)>\(esc(vals[0]))</\(q)>")
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch field.xmpContainer {
|
switch field.xmpContainer {
|
||||||
case .simple:
|
case .simple:
|
||||||
simpleAttrs.append(" \(q)=\"\(esc(vals[0]))\"")
|
simpleAttrs.append(" \(q)=\"\(esc(vals[0]))\"")
|
||||||
@@ -88,6 +147,9 @@ public enum XMPTemplateIO {
|
|||||||
elements.append(" <\(q)>\n <\(tag)>\n\(lis)\n </\(tag)>\n </\(q)>")
|
elements.append(" <\(q)>\n <\(tag)>\n\(lis)\n </\(tag)>\n </\(q)>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !locationCreated.isEmpty {
|
||||||
|
elements.append(" <Iptc4xmpExt:LocationCreated>\n <rdf:Bag>\n <rdf:li rdf:parseType=\"Resource\">\n\(locationCreated.joined(separator: "\n"))\n </rdf:li>\n </rdf:Bag>\n </Iptc4xmpExt:LocationCreated>")
|
||||||
|
}
|
||||||
if !contact.isEmpty {
|
if !contact.isEmpty {
|
||||||
elements.append(" <Iptc4xmpCore:CreatorContactInfo rdf:parseType=\"Resource\">\n\(contact.joined(separator: "\n"))\n </Iptc4xmpCore:CreatorContactInfo>")
|
elements.append(" <Iptc4xmpCore:CreatorContactInfo rdf:parseType=\"Resource\">\n\(contact.joined(separator: "\n"))\n </Iptc4xmpCore:CreatorContactInfo>")
|
||||||
}
|
}
|
||||||
@@ -184,7 +246,8 @@ final class XMPPropertyCollector: NSObject, XMLParserDelegate {
|
|||||||
|
|
||||||
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
|
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
|
||||||
guard let frame = stack.popLast() else { return }
|
guard let frame = stack.popLast() else { return }
|
||||||
let text = frame.text.trimmingCharacters(in: .whitespacesAndNewlines)
|
// Keep text exactly (captions may start with blank lines), but treat pure formatting whitespace as empty.
|
||||||
|
let text = frame.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? "" : frame.text
|
||||||
if frame.ns == XMPNamespace.rdf && frame.local == "li" {
|
if frame.ns == XMPNamespace.rdf && frame.local == "li" {
|
||||||
// Hand the li value up to the nearest real property.
|
// Hand the li value up to the nearest real property.
|
||||||
if let idx = stack.lastIndex(where: { !isContainer($0.ns, $0.local) }) {
|
if let idx = stack.lastIndex(where: { !isContainer($0.ns, $0.local) }) {
|
||||||
@@ -193,6 +256,7 @@ final class XMPPropertyCollector: NSObject, XMLParserDelegate {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if isContainer(frame.ns, frame.local) { return }
|
if isContainer(frame.ns, frame.local) { return }
|
||||||
|
if frame.ns == XMPNamespace.photomechanic && frame.liValues.isEmpty && frame.hasChildElements { return }
|
||||||
if !frame.liValues.isEmpty {
|
if !frame.liValues.isEmpty {
|
||||||
props.append(Property(namespace: frame.ns, localName: frame.local, values: frame.liValues))
|
props.append(Property(namespace: frame.ns, localName: frame.local, values: frame.liValues))
|
||||||
} else if !frame.hasChildElements {
|
} else if !frame.hasChildElements {
|
||||||
@@ -200,3 +264,42 @@ final class XMPPropertyCollector: NSObject, XMLParserDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Photo Mechanic `.snap` file: `<IPTCSettings><XMPRecord>…escaped XMP…</XMPRecord><ApplyFlags/>…`
|
||||||
|
struct PMSnapFile {
|
||||||
|
var xmpRecord: String?
|
||||||
|
var applyFlags: String?
|
||||||
|
var mergeFlags: String?
|
||||||
|
var applyDateStyle: String?
|
||||||
|
|
||||||
|
static func parse(data: Data) throws -> PMSnapFile {
|
||||||
|
final class Delegate: NSObject, XMLParserDelegate {
|
||||||
|
var root: String?
|
||||||
|
var current: String?
|
||||||
|
var buffer = ""
|
||||||
|
var result = PMSnapFile()
|
||||||
|
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?,
|
||||||
|
qualifiedName qName: String?, attributes attributeDict: [String: String] = [:]) {
|
||||||
|
if root == nil { root = elementName }
|
||||||
|
current = elementName
|
||||||
|
buffer = ""
|
||||||
|
}
|
||||||
|
func parser(_ parser: XMLParser, foundCharacters string: String) { buffer += string }
|
||||||
|
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
|
||||||
|
switch elementName {
|
||||||
|
case "XMPRecord": result.xmpRecord = buffer
|
||||||
|
case "ApplyFlags": result.applyFlags = buffer
|
||||||
|
case "MergeFlags": result.mergeFlags = buffer
|
||||||
|
case "ApplyDateStyle": result.applyDateStyle = buffer.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
default: break
|
||||||
|
}
|
||||||
|
buffer = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let d = Delegate()
|
||||||
|
let p = XMLParser(data: data)
|
||||||
|
p.delegate = d
|
||||||
|
guard p.parse(), d.root == "IPTCSettings" else { throw TemplateImportError.unreadable("keine .snap-Datei") }
|
||||||
|
return d.result
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,3 +91,49 @@ final class LightroomJobTests: XCTestCase {
|
|||||||
XCTAssertEqual(r.exported.map(\.path), ["/a/b.jpg"])
|
XCTAssertEqual(r.exported.map(\.path), ["/a/b.jpg"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class PMSnapTests: XCTestCase {
|
||||||
|
func fixture() throws -> URL {
|
||||||
|
let dir = try XCTUnwrap(Bundle.module.url(forResource: "Fixtures", withExtension: nil))
|
||||||
|
return dir.appendingPathComponent("42061495-VFL_Frauen_-_Hoffenheim.snap")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testImportsRealPMSnap() throws {
|
||||||
|
let t = try XMPTemplateIO.importTemplate(from: fixture())
|
||||||
|
XCTAssertEqual(t.name, "VFL Frauen - Hoffenheim")
|
||||||
|
XCTAssertEqual(t.values.text["city"], "Wolfsburg")
|
||||||
|
XCTAssertEqual(t.values.text["sublocation"], "AOK Stadion")
|
||||||
|
XCTAssertEqual(t.values.text["countryCode"], "DEU")
|
||||||
|
XCTAssertEqual(t.values.text["creator"], "Leon Tonhäuser")
|
||||||
|
XCTAssertEqual(t.values.text["copyright"], "© Beautiful Sports/Tonhäuser")
|
||||||
|
XCTAssertEqual(t.values.text["event"], "DFB-Pokal Frauen: VfL Wolfsburg - TSG 1899 Hoffenheim")
|
||||||
|
XCTAssertEqual(t.values.text["lcWorldRegion"], "Europa")
|
||||||
|
XCTAssertEqual(t.values.text["copyrightMarked"], "True")
|
||||||
|
XCTAssertEqual(t.values.lists["keywords"]?.count, 28)
|
||||||
|
XCTAssertEqual(t.values.lists["keywords"]?.first, "BLD")
|
||||||
|
// Caption keeps its leading blank lines exactly like PM.
|
||||||
|
XCTAssertTrue(t.values.text["caption"]?.hasPrefix("\n\n\n; Fußball, DFB-Pokal der Frauen") == true)
|
||||||
|
XCTAssertTrue(t.values.text["caption"]?.hasSuffix("QUASI-VIDEO.") == true)
|
||||||
|
// PM checkboxes → applied fields
|
||||||
|
XCTAssertEqual(t.appliedFields, ["dateCreated", "city", "state", "country", "countryCode", "keywords",
|
||||||
|
"creator", "caption", "headline", "copyright", "sublocation", "event"])
|
||||||
|
XCTAssertEqual(t.listMergeMode, .replace)
|
||||||
|
XCTAssertTrue(t.dateFromCapture)
|
||||||
|
XCTAssertTrue(t.unmappedPMCodes.isEmpty)
|
||||||
|
// PM bookkeeping does not leak into extras
|
||||||
|
XCTAssertNil(t.extras["\(XMPNamespace.photomechanic)|FieldsToApply"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSnapRoundTripThroughXMPExport() throws {
|
||||||
|
let t = try XMPTemplateIO.importTemplate(from: fixture())
|
||||||
|
let again = try XMPTemplateIO.parse(data: Data(XMPTemplateIO.export(t).utf8))
|
||||||
|
XCTAssertEqual(again.values, t.values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCaptureDateValue() {
|
||||||
|
XCTAssertEqual(MetadataWriter.captureDateValue(exif: ["DateTimeOriginal": "2026:11:02 14:22:01", "OffsetTimeOriginal": "+01:00"]),
|
||||||
|
"2026-11-02 14:22:01+01:00")
|
||||||
|
XCTAssertEqual(MetadataWriter.dateArguments("2026-11-02 14:22:01+01:00", writeIIM: true),
|
||||||
|
["-XMP-photoshop:DateCreated=2026:11:02 14:22:01+01:00", "-IPTC:DateCreated=2026:11:02", "-IPTC:TimeCreated=14:22:01+01:00"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<IPTCSettings>
|
||||||
|
<XMPRecord><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
|
||||||
|
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||||
|
<rdf:Description rdf:about=""
|
||||||
|
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
|
||||||
|
xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
|
||||||
|
xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"
|
||||||
|
xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/"
|
||||||
|
xmlns:plus="http://ns.useplus.org/ldf/xmp/1.0/"
|
||||||
|
xmlns:photomechanic="http://ns.camerabits.com/photomechanic/1.0/"
|
||||||
|
photoshop:City="Wolfsburg"
|
||||||
|
photoshop:State="Niedersachen"
|
||||||
|
photoshop:Country="Deutschland"
|
||||||
|
photoshop:Headline="DFB-Pokal Frauen: VfL Wolfsburg vs. TSG 1899 Hoffenheim, 02.11.2026"
|
||||||
|
photoshop:DateCreated="2026-02-15T00:00:00+01:00"
|
||||||
|
xmpRights:Marked="True"
|
||||||
|
xmp:CreateDate="2026-02-15T00:00:00+01:00"
|
||||||
|
xmp:Rating="0"
|
||||||
|
Iptc4xmpCore:CountryCode="DEU"
|
||||||
|
Iptc4xmpCore:Location="AOK Stadion"
|
||||||
|
plus:DataMining="http://ns.useplus.org/ldf/vocab/DMI-UNSPECIFIED"
|
||||||
|
photomechanic:ColorClass="0"
|
||||||
|
photomechanic:Tagged="False"
|
||||||
|
photomechanic:PMVersion="2026.6.9175"
|
||||||
|
photomechanic:ColorClassEval="0"
|
||||||
|
photomechanic:ColorClassApply="False"
|
||||||
|
photomechanic:RatingEval="0"
|
||||||
|
photomechanic:RatingApply="False"
|
||||||
|
photomechanic:TagEval="0"
|
||||||
|
photomechanic:TagApply="False"
|
||||||
|
photomechanic:CaptionMergeStyle="1"
|
||||||
|
photomechanic:ApplyDateType="2">
|
||||||
|
<dc:subject>
|
||||||
|
<rdf:Bag>
|
||||||
|
<rdf:li>BLD</rdf:li>
|
||||||
|
<rdf:li>Bundesliga</rdf:li>
|
||||||
|
<rdf:li>TSG 1899 Hoffenheim</rdf:li>
|
||||||
|
<rdf:li>TSG</rdf:li>
|
||||||
|
<rdf:li>Frauenfußball</rdf:li>
|
||||||
|
<rdf:li>Fußballspiel</rdf:li>
|
||||||
|
<rdf:li>VfL Wolfsburg</rdf:li>
|
||||||
|
<rdf:li>VfL</rdf:li>
|
||||||
|
<rdf:li>VFLTSG</rdf:li>
|
||||||
|
<rdf:li>Wölfe</rdf:li>
|
||||||
|
<rdf:li>Wolfsburg</rdf:li>
|
||||||
|
<rdf:li>ZDF</rdf:li>
|
||||||
|
<rdf:li>Frauen</rdf:li>
|
||||||
|
<rdf:li>Fußball</rdf:li>
|
||||||
|
<rdf:li>Frauen Bundesliga</rdf:li>
|
||||||
|
<rdf:li>Die Liga</rdf:li>
|
||||||
|
<rdf:li>GPFBL</rdf:li>
|
||||||
|
<rdf:li>Wölfinnen</rdf:li>
|
||||||
|
<rdf:li>Grün Weiß</rdf:li>
|
||||||
|
<rdf:li>AOK Stadion</rdf:li>
|
||||||
|
<rdf:li>Heimspiel</rdf:li>
|
||||||
|
<rdf:li>Womens Football</rdf:li>
|
||||||
|
<rdf:li>Womens Soccer</rdf:li>
|
||||||
|
<rdf:li>She Wolves</rdf:li>
|
||||||
|
<rdf:li>DFB Pokal</rdf:li>
|
||||||
|
<rdf:li>DFB Pokal Frauen</rdf:li>
|
||||||
|
<rdf:li>Achtelfinale</rdf:li>
|
||||||
|
<rdf:li>Saison 26/27</rdf:li>
|
||||||
|
</rdf:Bag>
|
||||||
|
</dc:subject>
|
||||||
|
<dc:description>
|
||||||
|
<rdf:Alt>
|
||||||
|
<rdf:li xml:lang="x-default">&#xA;&#xA;&#xA;; Fußball, DFB-Pokal der Frauen, Achtelfinale: VfL Wolfsburg vs. TSG 1899 Hoffenheim am 02.11.2026 im AOK Stadion, Wolfsburg&#xA;&#xA;DFB REGULATIONS PROHIBIT ANY USE OF PHOTOGRAPHS AS IMAGE SEQUENCES AND/OR QUASI-VIDEO.</rdf:li>
|
||||||
|
</rdf:Alt>
|
||||||
|
</dc:description>
|
||||||
|
<dc:creator>
|
||||||
|
<rdf:Seq>
|
||||||
|
<rdf:li>Leon Tonhäuser</rdf:li>
|
||||||
|
</rdf:Seq>
|
||||||
|
</dc:creator>
|
||||||
|
<dc:rights>
|
||||||
|
<rdf:Alt>
|
||||||
|
<rdf:li xml:lang="x-default">© Beautiful Sports/Tonhäuser</rdf:li>
|
||||||
|
</rdf:Alt>
|
||||||
|
</dc:rights>
|
||||||
|
<Iptc4xmpExt:LocationCreated>
|
||||||
|
<rdf:Bag>
|
||||||
|
<rdf:li
|
||||||
|
Iptc4xmpExt:Sublocation=""
|
||||||
|
Iptc4xmpExt:City="Wolfsburg"
|
||||||
|
Iptc4xmpExt:ProvinceState="Wolfsburg"
|
||||||
|
Iptc4xmpExt:CountryName="Deutschland"
|
||||||
|
Iptc4xmpExt:CountryCode="DEU"
|
||||||
|
Iptc4xmpExt:WorldRegion="Europa"/>
|
||||||
|
</rdf:Bag>
|
||||||
|
</Iptc4xmpExt:LocationCreated>
|
||||||
|
<Iptc4xmpExt:Event>
|
||||||
|
<rdf:Alt>
|
||||||
|
<rdf:li xml:lang="x-default">DFB-Pokal Frauen: VfL Wolfsburg - TSG 1899 Hoffenheim</rdf:li>
|
||||||
|
</rdf:Alt>
|
||||||
|
</Iptc4xmpExt:Event>
|
||||||
|
<photomechanic:FieldsToApply>
|
||||||
|
<rdf:Bag>
|
||||||
|
<rdf:li>0x00</rdf:li>
|
||||||
|
<rdf:li>0x237</rdf:li>
|
||||||
|
<rdf:li>0x25a</rdf:li>
|
||||||
|
<rdf:li>0x25f</rdf:li>
|
||||||
|
<rdf:li>0x265</rdf:li>
|
||||||
|
<rdf:li>0x264</rdf:li>
|
||||||
|
<rdf:li>0x219</rdf:li>
|
||||||
|
<rdf:li>0x250</rdf:li>
|
||||||
|
<rdf:li>0x278</rdf:li>
|
||||||
|
<rdf:li>0x269</rdf:li>
|
||||||
|
<rdf:li>0x274</rdf:li>
|
||||||
|
<rdf:li>0x25c</rdf:li>
|
||||||
|
<rdf:li>0x8013</rdf:li>
|
||||||
|
</rdf:Bag>
|
||||||
|
</photomechanic:FieldsToApply>
|
||||||
|
<photomechanic:FieldsToMerge>
|
||||||
|
<rdf:Bag>
|
||||||
|
<rdf:li>0x00</rdf:li>
|
||||||
|
</rdf:Bag>
|
||||||
|
</photomechanic:FieldsToMerge>
|
||||||
|
</rdf:Description>
|
||||||
|
</rdf:RDF>
|
||||||
|
</x:xmpmeta>
|
||||||
|
</XMPRecord>
|
||||||
|
<ApplyFlags>10111100000101000011000101000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000</ApplyFlags>
|
||||||
|
<MergeFlags>00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</MergeFlags>
|
||||||
|
<ApplyDateStyle>2</ApplyDateStyle>
|
||||||
|
</IPTCSettings>
|
||||||
Reference in new issue
Block a user