PM-Oberfläche: Favoriten/Navigator/Aufgaben, Tabs, PM-Filter, PM-Kacheln, IPTC-Layout wie PM, ⌘I Mass-Edit, ⌘U Upload, Code-Ersetzung live, 8 Farbklassen, paralleles + gecachtes Metadaten-Laden, BILDER/INPUT+SENT

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 23:51:33 +00:00
1 parent d100249c12
commit c0ee93995f
18 files changed
+1311 -515

No files matched your search

@@ -0,0 +1,69 @@
import Foundation
/// On-disk cache of exiftool results per folder (keyed by file size + modification date),
/// so re-opening a folder with thousands of images is instant – like PM's preview/metadata cache.
public final class MetadataCache: @unchecked Sendable {
public struct Entry: Codable, Sendable {
public var size: Int64
public var mtime: Double
public var sidecarMtime: Double?
public var file: [String: MetadataValue]
public var sidecar: [String: MetadataValue]?
}
private let url: URL
private var entries: [String: Entry] = [:]
private let lock = NSLock()
private var dirty = false
public static var directory: URL {
let d = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
.appendingPathComponent("Lichtkasten/metadata", isDirectory: true)
try? FileManager.default.createDirectory(at: d, withIntermediateDirectories: true)
return d
}
public init(folder: URL) {
// FNV-1a hash of the path as file name
var h: UInt64 = 0xcbf29ce484222325
for b in folder.standardizedFileURL.path.utf8 { h = (h ^ UInt64(b)) &* 0x100000001b3 }
url = MetadataCache.directory.appendingPathComponent(String(h, radix: 16) + ".json")
if let d = try? Data(contentsOf: url), let e = try? JSONDecoder().decode([String: Entry].self, from: d) {
entries = e
}
}
static func stamp(_ u: URL) -> (Int64, Double)? {
guard let a = try? FileManager.default.attributesOfItem(atPath: u.path) else { return nil }
let size = (a[.size] as? NSNumber)?.int64Value ?? 0
let m = (a[.modificationDate] as? Date)?.timeIntervalSince1970 ?? 0
return (size, m)
}
/// Valid cached entry for an item (file and sidecar unchanged), else nil.
public func lookup(_ item: PhotoItem) -> Entry? {
lock.lock(); let e = entries[item.primary.path]; lock.unlock()
guard let e, let (size, m) = MetadataCache.stamp(item.primary), size == e.size, m == e.mtime else { return nil }
if item.kind.usesSidecar {
let sm = MetadataCache.stamp(item.sidecarURL)?.1
if sm != e.sidecarMtime { return nil }
}
return e
}
public func store(_ item: PhotoItem, file: [String: MetadataValue], sidecar: [String: MetadataValue]?) {
guard let (size, m) = MetadataCache.stamp(item.primary) else { return }
let sm = item.kind.usesSidecar ? MetadataCache.stamp(item.sidecarURL)?.1 : nil
lock.lock()
entries[item.primary.path] = Entry(size: size, mtime: m, sidecarMtime: sm, file: file, sidecar: sidecar)
dirty = true
lock.unlock()
}
public func save() {
lock.lock(); defer { lock.unlock() }
guard dirty, let d = try? JSONEncoder().encode(entries) else { return }
try? d.write(to: url, options: .atomic)
dirty = false
}
}
@@ -29,21 +29,29 @@ public enum FileKind: String, Sendable, Codable {
public var supportsIIM: Bool { self == .jpeg || self == .tiff || self == .dng }
}
/// Photo Mechanic color classes 1–8 (keys 1–8). Classes 1–5 map to Lightroom's label colors.
public enum ColorLabel: String, CaseIterable, Codable, Sendable {
case red = "Red", yellow = "Yellow", green = "Green", blue = "Blue", purple = "Purple"
case cyan = "Cyan", orange = "Orange", gray = "Gray"
/// Value written to Lightroom's xmp:Label (LR default label set, German UI uses the same English keys
/// only if the label set is "Lightroom-Standard"; see README).
/// Value written to xmp:Label (Lightroom default label set understands Red…Purple).
public var xmpValue: String { rawValue }
/// Photo Mechanic color class number for compatibility.
/// Photo Mechanic color class number.
public var pmColorClass: Int { (ColorLabel.allCases.firstIndex(of: self) ?? 0) + 1 }
/// PM's default class names.
public var pmName: String {
["Winner", "Winner alt", "Superior", "Superior alt", "Typical", "Typical alt", "Extras", "Trash"][pmColorClass - 1]
}
public var germanName: String {
switch self {
case .red: return "Rot"
case .yellow: return "Gelb"
case .green: return "Grün"
case .blue: return "Blau"
case .purple: return "Lila"
case .purple: return "Magenta"
case .cyan: return "Cyan"
case .orange: return "Orange"
case .gray: return "Grau"
}
}
@@ -51,7 +59,8 @@ public enum ColorLabel: String, CaseIterable, Codable, Sendable {
let l = xmp.lowercased()
let map: [String: ColorLabel] = ["red": .red, "rot": .red, "yellow": .yellow, "gelb": .yellow,
"green": .green, "grün": .green, "blue": .blue, "blau": .blue,
"purple": .purple, "lila": .purple, "violett": .purple]
"purple": .purple, "lila": .purple, "violett": .purple, "magenta": .purple,
"cyan": .cyan, "orange": .orange, "gray": .gray, "grey": .gray, "grau": .gray]
guard let c = map[l] else { return nil }
self = c
}
@@ -132,8 +141,9 @@ public struct PhotoItem: Identifiable, Hashable, Sendable {
func xmp(_ tag: String) -> MetadataValue? { xmpSource[tag] ?? fileMeta[tag] }
rating = xmp("XMP-xmp:Rating")?.int ?? 0
label = xmp("XMP-xmp:Label").flatMap { ColorLabel(xmp: $0.string) }
?? xmp("XMP-photomech:ColorClass")?.int.flatMap { ColorLabel(pmColorClass: $0) }
// PM color class first (it knows all 8 classes), then Lightroom's label.
label = xmp("XMP-photomech:ColorClass")?.int.flatMap { ColorLabel(pmColorClass: $0) }
?? xmp("XMP-xmp:Label").flatMap { ColorLabel(xmp: $0.string) }
tagged = xmp("XMP-photomech:Tagged")?.bool ?? false
var values = IPTCValues()