PM-Prefs (Tag/Farbe/Sterne) lesen+schreiben, Datum Capture Time, Zoom bis einstellbarem Maximum, Ingest im PM-Aufbau (gesperrt/RAW-Filter, Sequenz, inkrementell, Auswerfen), App-Icon
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
c0ee93995f
commit
8effd1af0c
25 files changed
+885
-131
No files matched your search
@@ -121,6 +121,7 @@ public final class ExifTool: @unchecked Sendable {
|
||||
guard !files.isEmpty else { return [:] }
|
||||
var args = ["-json", "-G1", "-fast2", "-a",
|
||||
"-XMP-xmp:Rating#", "-XMP-xmp:Label", "-XMP-photomech:Tagged#", "-XMP-photomech:ColorClass#",
|
||||
"-IPTC:Prefs#", "-XMP-photomech:Prefs#",
|
||||
"-Make", "-Model", "-LensModel", "-Lens", "-SerialNumber", "-ISO", "-ExposureTime", "-FNumber",
|
||||
"-FocalLength", "-DateTimeOriginal", "-CreateDate", "-SubSecTimeOriginal", "-OffsetTimeOriginal", "-ImageWidth", "-ImageHeight",
|
||||
"-Orientation#", "-Artist", "-GPSLatitude#", "-GPSLongitude#"]
|
||||
|
||||
@@ -36,6 +36,26 @@ public struct MetadataWriter: Sendable {
|
||||
try await writeFlags(["-XMP-photomech:Tagged=\(tagged ? "Yes" : "No")"], item: item)
|
||||
}
|
||||
|
||||
/// Writes tag, color class and stars in one go – in every place PM and Lightroom look:
|
||||
/// xmp:Rating, xmp:Label, photomechanic:Tagged/ColorClass/Prefs and (JPEG/TIFF) IPTC 2:221 Prefs.
|
||||
public func writeState(of item: PhotoItem) async throws {
|
||||
let prefs = item.pmPrefsString
|
||||
for target in item.metadataTargets {
|
||||
var args = ["-overwrite_original", "-m",
|
||||
"-XMP-xmp:Rating=\(max(0, min(5, item.rating)))",
|
||||
"-XMP-photomech:Tagged=\(item.tagged ? "Yes" : "No")",
|
||||
"-XMP-photomech:Prefs=\(prefs)"]
|
||||
if let l = item.label {
|
||||
args += ["-XMP-xmp:Label=\(l.xmpValue)", "-XMP-photomech:ColorClass=\(l.pmColorClass)"]
|
||||
} else {
|
||||
args += ["-XMP-xmp:Label=", "-XMP-photomech:ColorClass=0"]
|
||||
}
|
||||
if target.kind.supportsIIM { args += ["-IPTC:Prefs=\(prefs)"] }
|
||||
let (_, err) = try await exiftool.execute(args + [target.url.path])
|
||||
if err.contains("Error:") { throw ExifToolError.failed(err) }
|
||||
}
|
||||
}
|
||||
|
||||
private func writeFlags(_ args: [String], item: PhotoItem) async throws {
|
||||
for target in item.metadataTargets {
|
||||
let (_, err) = try await exiftool.execute(["-overwrite_original", "-m"] + args + [target.url.path])
|
||||
|
||||
@@ -24,6 +24,12 @@ public struct VariableContext: Sendable {
|
||||
v["shutter"] = exif["ExposureTime"]
|
||||
v["focallength"] = exif["FocalLength"]
|
||||
v["artist"] = exif["Artist"]
|
||||
// Date field popup (PM "Capture Time" / "Today")
|
||||
v["capturetime"] = MetadataWriter.captureDateValue(exif: exif)
|
||||
let today = DateFormatter()
|
||||
today.locale = Locale(identifier: "en_US_POSIX")
|
||||
today.dateFormat = "yyyy-MM-dd"
|
||||
v["today"] = today.string(from: Date())
|
||||
if let seq = sequence {
|
||||
v["seqn"] = String(seq)
|
||||
v["seqn3"] = String(format: "%03d", seq)
|
||||
|
||||
@@ -77,7 +77,7 @@ public enum XMPTemplateIO {
|
||||
}
|
||||
}
|
||||
// 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, d.first?.isNumber == true { values.text["dateCreated"] = String(d.prefix(10)) }
|
||||
guard found > 0 || !extras.isEmpty else { throw TemplateImportError.noFieldsFound }
|
||||
|
||||
var t = IPTCTemplate(name: "Importiert", values: values, extras: extras)
|
||||
@@ -97,6 +97,7 @@ public enum XMPTemplateIO {
|
||||
t.listMergeMode = merge.contains(where: { $0.lowercased() == "0x219" }) ? .append : .replace
|
||||
}
|
||||
if let dt = pm["ApplyDateType"]?.first { t.dateFromCapture = (dt == "2") }
|
||||
if t.dateFromCapture { t.values.text["dateCreated"] = "{capturetime}" }
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -107,6 +108,7 @@ public enum XMPTemplateIO {
|
||||
|
||||
static func applySnapSettings(_ snap: PMSnapFile, to t: inout IPTCTemplate) {
|
||||
if let style = snap.applyDateStyle { t.dateFromCapture = (style == "2") }
|
||||
if t.dateFromCapture { t.values.text["dateCreated"] = "{capturetime}" }
|
||||
}
|
||||
|
||||
// MARK: Export
|
||||
|
||||
Reference in new issue
Block a user