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:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-03 22:57:14 +00:00
1 parent 0b41f09206
commit 42ab9c9361
13 files changed
+472 -39

No files matched your search

@@ -47,41 +47,75 @@ public enum ListMergeMode: String, Codable, CaseIterable, Sendable {
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 var id: UUID
public var name: String
public var values: IPTCValues
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
/// 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 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(),
listMergeMode: ListMergeMode = .append, clearEmptyFields: Bool = false,
appliedFields: Set<String>? = nil, dateFromCapture: Bool = false,
extras: [String: String] = [:], modified: Date = Date()) {
self.id = id
self.name = name
self.values = values
self.listMergeMode = listMergeMode
self.clearEmptyFields = clearEmptyFields
self.appliedFields = appliedFields
self.dateFromCapture = dateFromCapture
self.extras = extras
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,
/// that happens per image in `MetadataWriter`.
public func apply(to existing: IPTCValues) -> IPTCValues {
var result = existing
for field in IPTCField.all {
for field in fieldsToWrite {
if field.kind == .list {
let tpl = values.list(field)
if tpl.isEmpty {
if clearEmptyFields { result.lists[field.id] = nil }
continue
}
if tpl.isEmpty { result.lists[field.id] = nil; continue }
switch listMergeMode {
case .replace:
result.lists[field.id] = tpl
@@ -92,11 +126,7 @@ public struct IPTCTemplate: Codable, Identifiable, Hashable, Sendable {
}
} else {
let tpl = values.text[field.id] ?? ""
if tpl.isEmpty {
if clearEmptyFields { result.text[field.id] = nil }
continue
}
result.text[field.id] = tpl
result.text[field.id] = tpl.isEmpty ? nil : tpl
}
}
return result