import Foundation /// XMP namespaces as written by Photo Mechanic, Lightroom and Photoshop. public enum XMPNamespace { public static let dc = "http://purl.org/dc/elements/1.1/" public static let photoshop = "http://ns.adobe.com/photoshop/1.0/" public static let iptcCore = "http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/" public static let iptcExt = "http://iptc.org/std/Iptc4xmpExt/2008-02-29/" 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 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#" /// Prefix normally used when we write a template file back out. public static let preferredPrefix: [String: String] = [ dc: "dc", photoshop: "photoshop", iptcCore: "Iptc4xmpCore", iptcExt: "Iptc4xmpExt", xmpRights: "xmpRights", xmp: "xmp", photomechanic: "photomechanic", plus: "plus", ] } public enum IPTCFieldKind: String, Codable, Sendable { case text // single line case multiline // caption / instructions case list // keywords etc. – stored as [String] } public enum IPTCSection: String, CaseIterable, Codable, Sendable { case description = "Beschreibung" case location = "Ort" case locationCreated = "Aufnahmeort (IPTC Ext)" case creator = "Urheber & Rechte" case contact = "Kontakt des Urhebers" case extended = "Erweitert (IPTC Core/Ext)" } /// How an XMP property is stored inside rdf. public enum XMPContainer: String, Codable, Sendable { case simple, alt, seq, bag } /// One IPTC field. The order of `IPTCField.all` mirrors the Photo Mechanic /// IPTC Stationery Pad so agency workflows stay the same. public struct IPTCField: Identifiable, Hashable, Sendable { public let id: String public let label: String /// Name as shown in Photo Mechanic (helps when switching). public let pmLabel: String public let section: IPTCSection public let kind: IPTCFieldKind /// exiftool tag for the legacy IPTC-IIM record (nil = XMP only). public let iimTag: String? /// exiftool tag for XMP. public let xmpTag: String /// XMP property (namespace URI + local name) used in PM templates. public let xmpNamespace: String public let xmpLocalName: String public let xmpContainer: XMPContainer /// Byte limit of the IIM dataset (UTF-8 bytes). Agencies truncate/reject above this. public let iimMaxBytes: Int? public static func == (a: IPTCField, b: IPTCField) -> Bool { a.id == b.id } public func hash(into h: inout Hasher) { h.combine(id) } } public extension IPTCField { private static func f(_ id: String, _ label: String, pm: String, _ section: IPTCSection, _ kind: IPTCFieldKind = .text, iim: String?, xmp: String, ns: String, local: String, container: XMPContainer = .simple, max: Int? = nil) -> IPTCField { IPTCField(id: id, label: label, pmLabel: pm, section: section, kind: kind, iimTag: iim, xmpTag: xmp, xmpNamespace: ns, xmpLocalName: local, xmpContainer: container, iimMaxBytes: max) } static let all: [IPTCField] = [ // --- Beschreibung --- f("caption", "Bildunterschrift", pm: "Caption", .description, .multiline, iim: "IPTC:Caption-Abstract", xmp: "XMP-dc:Description", ns: XMPNamespace.dc, local: "description", container: .alt, max: 2000), f("captionWriter", "Verfasser Bildunterschrift", pm: "Caption Writer", .description, iim: "IPTC:Writer-Editor", xmp: "XMP-photoshop:CaptionWriter", ns: XMPNamespace.photoshop, local: "CaptionWriter", max: 32), f("headline", "Überschrift", pm: "Headline", .description, iim: "IPTC:Headline", xmp: "XMP-photoshop:Headline", ns: XMPNamespace.photoshop, local: "Headline", max: 256), f("instructions", "Anweisungen", pm: "Special Instructions", .description, .multiline, iim: "IPTC:SpecialInstructions", xmp: "XMP-photoshop:Instructions", ns: XMPNamespace.photoshop, local: "Instructions", max: 256), f("transmissionReference", "Job-ID / Übertragungsreferenz", pm: "Transmission Reference", .description, iim: "IPTC:OriginalTransmissionReference", xmp: "XMP-photoshop:TransmissionReference", ns: XMPNamespace.photoshop, local: "TransmissionReference", max: 32), f("objectName", "Titel (Objektname)", pm: "Object Name", .description, iim: "IPTC:ObjectName", xmp: "XMP-dc:Title", ns: XMPNamespace.dc, local: "title", container: .alt, max: 64), f("keywords", "Stichwörter", pm: "Keywords", .description, .list, iim: "IPTC:Keywords", xmp: "XMP-dc:Subject", ns: XMPNamespace.dc, local: "subject", container: .bag, max: 64), f("category", "Kategorie", pm: "Category", .description, iim: "IPTC:Category", xmp: "XMP-photoshop:Category", ns: XMPNamespace.photoshop, local: "Category", max: 3), f("supplementalCategories", "Zusatzkategorien", pm: "Supplemental Categories", .description, .list, iim: "IPTC:SupplementalCategories", xmp: "XMP-photoshop:SupplementalCategories", ns: XMPNamespace.photoshop, local: "SupplementalCategories", container: .bag, max: 32), f("urgency", "Dringlichkeit", pm: "Urgency", .description, iim: "IPTC:Urgency", xmp: "XMP-photoshop:Urgency", ns: XMPNamespace.photoshop, local: "Urgency", max: 1), f("dateCreated", "Erstellungsdatum (JJJJ-MM-TT)", pm: "Date Created", .description, iim: "IPTC:DateCreated", xmp: "XMP-photoshop:DateCreated", ns: XMPNamespace.photoshop, local: "DateCreated", max: 8), // --- Ort --- f("event", "Ereignis", pm: "Event", .location, iim: nil, xmp: "XMP-iptcExt:Event", ns: XMPNamespace.iptcExt, local: "Event", container: .alt), f("sublocation", "Ortsdetail", pm: "Location / Sublocation", .location, iim: "IPTC:Sub-location", xmp: "XMP-iptcCore:Location", ns: XMPNamespace.iptcCore, local: "Location", max: 32), f("city", "Stadt", pm: "City", .location, iim: "IPTC:City", xmp: "XMP-photoshop:City", ns: XMPNamespace.photoshop, local: "City", max: 32), f("state", "Bundesland", pm: "State / Province", .location, iim: "IPTC:Province-State", xmp: "XMP-photoshop:State", ns: XMPNamespace.photoshop, local: "State", max: 32), f("country", "Land", pm: "Country", .location, iim: "IPTC:Country-PrimaryLocationName", xmp: "XMP-photoshop:Country", ns: XMPNamespace.photoshop, local: "Country", max: 64), f("countryCode", "Ländercode (ISO)", pm: "Country Code", .location, 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 --- f("creator", "Fotograf", pm: "Photographer / Creator", .creator, iim: "IPTC:By-line", xmp: "XMP-dc:Creator", ns: XMPNamespace.dc, local: "creator", container: .seq, max: 32), f("creatorJobTitle", "Position des Fotografen", pm: "Photographer's Title", .creator, iim: "IPTC:By-lineTitle", xmp: "XMP-photoshop:AuthorsPosition", ns: XMPNamespace.photoshop, local: "AuthorsPosition", max: 32), f("credit", "Credit / Anbieter", pm: "Credit", .creator, iim: "IPTC:Credit", xmp: "XMP-photoshop:Credit", ns: XMPNamespace.photoshop, local: "Credit", max: 32), f("source", "Quelle", pm: "Source", .creator, iim: "IPTC:Source", xmp: "XMP-photoshop:Source", ns: XMPNamespace.photoshop, local: "Source", max: 32), f("copyright", "Copyright-Vermerk", pm: "Copyright Notice", .creator, 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, iim: nil, xmp: "XMP-xmpRights:UsageTerms", ns: XMPNamespace.xmpRights, local: "UsageTerms", container: .alt), f("webStatement", "Copyright-URL", pm: "Copyright Info URL", .creator, iim: nil, xmp: "XMP-xmpRights:WebStatement", ns: XMPNamespace.xmpRights, local: "WebStatement"), // --- Kontakt (IPTC Core CreatorContactInfo) --- f("ciAddress", "Adresse", pm: "Address", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorAddress", ns: XMPNamespace.iptcCore, local: "CiAdrExtadr"), f("ciCity", "Stadt", pm: "City (Contact)", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorCity", ns: XMPNamespace.iptcCore, local: "CiAdrCity"), f("ciRegion", "Bundesland", pm: "State (Contact)", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorRegion", ns: XMPNamespace.iptcCore, local: "CiAdrRegion"), f("ciPostalCode", "PLZ", pm: "Postal Code", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorPostalCode", ns: XMPNamespace.iptcCore, local: "CiAdrPcode"), f("ciCountry", "Land", pm: "Country (Contact)", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorCountry", ns: XMPNamespace.iptcCore, local: "CiAdrCtry"), f("ciPhone", "Telefon", pm: "Phone", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorWorkTelephone", ns: XMPNamespace.iptcCore, local: "CiTelWork"), f("ciEmail", "E-Mail", pm: "E-Mail", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorWorkEmail", ns: XMPNamespace.iptcCore, local: "CiEmailWork"), f("ciURL", "Website", pm: "Web URL", .contact, iim: nil, xmp: "XMP-iptcCore:CreatorWorkURL", ns: XMPNamespace.iptcCore, local: "CiUrlWork"), // --- Erweitert --- f("intellectualGenre", "Genre", pm: "Intellectual Genre", .extended, iim: "IPTC:ObjectAttributeReference", xmp: "XMP-iptcCore:IntellectualGenre", ns: XMPNamespace.iptcCore, local: "IntellectualGenre", max: 68), f("scene", "Szenen-Code", pm: "IPTC Scene", .extended, .list, iim: nil, xmp: "XMP-iptcCore:Scene", ns: XMPNamespace.iptcCore, local: "Scene", container: .bag), f("subjectCode", "Themen-Code", pm: "IPTC Subject Code", .extended, .list, iim: "IPTC:SubjectReference", xmp: "XMP-iptcCore:SubjectCode", ns: XMPNamespace.iptcCore, local: "SubjectCode", container: .bag, max: 236), f("personInImage", "Abgebildete Personen", pm: "Person Shown", .extended, .list, 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) }) /// Lookup by XMP namespace + local name (used by the PM template importer). static func forXMP(namespace: String, localName: String) -> IPTCField? { all.first { $0.xmpNamespace == namespace && $0.xmpLocalName == localName } } /// Byte length check against the IIM limit. Returns overflow in bytes (0 = ok). func overflow(of value: String) -> Int { guard let max = iimMaxBytes else { return 0 } return Swift.max(0, value.utf8.count - max) } }