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:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-04 00:05:21 +00:00
1 parent c0ee93995f
commit 8effd1af0c
25 files changed
+885 -131

No files matched your search

@@ -88,6 +88,8 @@ public struct PhotoItem: Identifiable, Hashable, Sendable {
public var exif: [String: String] = [:]
public var captureDate: Date?
public var metadataLoaded = false
/// Frame number part of PM's Prefs ("Tagged:ColorClass:Rating:Frame"), kept when we rewrite it.
public var pmFrame = "-00001"
public init(primary: URL, companions: [URL] = [], fileSize: Int64 = 0, modified: Date = Date()) {
self.primary = primary
@@ -128,6 +130,26 @@ public struct PhotoItem: Identifiable, Hashable, Sendable {
public var rawFile: URL? { kind.isRawLike ? primary : companions.first { FileKind(url: $0).isRawLike } }
public struct PMPrefs: Equatable, Sendable {
public var tagged: Bool; public var colorClass: Int; public var rating: Int; public var frame: String
}
/// Parses PM's Prefs value, raw ("1:3:0:-00001") or exiftool-printed ("Tagged:1, ColorClass:3, …").
public static func parsePMPrefs(_ raw: String) -> PMPrefs? {
var s = raw
if s.contains("Tagged") {
s = s.replacingOccurrences(of: "Tagged:", with: "").replacingOccurrences(of: "ColorClass:", with: "")
.replacingOccurrences(of: "Rating:", with: "").replacingOccurrences(of: "FrameNum:", with: "")
.replacingOccurrences(of: ", ", with: ":").replacingOccurrences(of: " ", with: "")
}
let parts = s.split(separator: ":", omittingEmptySubsequences: false).map { $0.trimmingCharacters(in: .whitespaces) }
guard parts.count >= 3, let t = Int(parts[0]), let c = Int(parts[1]), let r = Int(parts[2]) else { return nil }
return PMPrefs(tagged: t != 0, colorClass: c, rating: r, frame: parts.count > 3 ? parts[3] : "-00001")
}
/// PM Prefs string for the current state.
public var pmPrefsString: String { "\(tagged ? 1 : 0):\(label?.pmColorClass ?? 0):\(rating):\(pmFrame)" }
/// Applies exiftool output (primary file + optional sidecar) to the item.
public mutating func apply(fileMeta: [String: MetadataValue], sidecarMeta: [String: MetadataValue]?) {
// EXIF from the image itself
@@ -140,11 +162,17 @@ public struct PhotoItem: Identifiable, Hashable, Sendable {
let xmpSource = sidecarMeta ?? [:]
func xmp(_ tag: String) -> MetadataValue? { xmpSource[tag] ?? fileMeta[tag] }
rating = xmp("XMP-xmp:Rating")?.int ?? 0
// Photo Mechanic keeps tag/color/rating in "Prefs" (IPTC 2:221 and photomechanic:Prefs):
// "1:3:0:-00001" = tagged, color class 3, no stars, frame. Many PM files only have this.
let prefs = (xmp("XMP-photomech:Prefs") ?? fileMeta["IPTC:Prefs"]).flatMap { PhotoItem.parsePMPrefs($0.string) }
if let p = prefs { pmFrame = p.frame }
rating = xmp("XMP-xmp:Rating")?.int ?? prefs?.rating ?? 0
// PM color class first (it knows all 8 classes), then Lightroom's label.
label = xmp("XMP-photomech:ColorClass")?.int.flatMap { ColorLabel(pmColorClass: $0) }
?? prefs.flatMap { ColorLabel(pmColorClass: $0.colorClass) }
?? xmp("XMP-xmp:Label").flatMap { ColorLabel(xmp: $0.string) }
tagged = xmp("XMP-photomech:Tagged")?.bool ?? false
tagged = xmp("XMP-photomech:Tagged")?.bool ?? prefs?.tagged ?? false
var values = IPTCValues()
for field in IPTCField.all {