Immich: Albumname aus IPTC-Variablen pro Bild ({event}), Fallback-Muster, Vorschau im Upload-Fenster
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
1e72b97164
commit
12f61b5d66
5 files changed
+73
-15
No files matched your search
@@ -144,6 +144,10 @@ final class AppState: ObservableObject {
|
||||
/// First launch: agency FTP profiles (host/user are placeholders – adjust in Settings → FTP).
|
||||
private func seedDefaultsIfNeeded() {
|
||||
// Leon's folder layout: ~/Desktop/BILDER/INPUT (ingest) and ~/Desktop/BILDER/SENT (JPEG export)
|
||||
if !UserDefaults.standard.bool(forKey: "seededImmichAlbum") {
|
||||
UserDefaults.standard.set(true, forKey: "seededImmichAlbum")
|
||||
if settings.immich.albumName.isEmpty { settings.immich.albumName = "{event}" }
|
||||
}
|
||||
if !UserDefaults.standard.bool(forKey: "seededBILDER") {
|
||||
UserDefaults.standard.set(true, forKey: "seededBILDER")
|
||||
let bilder = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Desktop/BILDER")
|
||||
@@ -889,8 +893,16 @@ final class AppState: ObservableObject {
|
||||
do { try await w.write(values: src.iptc, fields: IPTCField.all, to: jpegItem) } catch { report(error) }
|
||||
}
|
||||
}
|
||||
// Exported JPEGs carry the IPTC of their RAW (needed for {event} album names, rename patterns …)
|
||||
let exportedItems: [PhotoItem] = files.compactMap { file in
|
||||
let base = file.deletingPathExtension().lastPathComponent
|
||||
guard let src = sources.first(where: { base == $0.baseName || base.hasPrefix($0.baseName + "-") }) else { return nil }
|
||||
var it = PhotoItem(primary: file)
|
||||
it.iptc = src.iptc; it.exif = src.exif; it.captureDate = src.captureDate
|
||||
return it
|
||||
}
|
||||
for target in job.uploadTargets {
|
||||
uploads.enqueue(files: files, target: target, sourceItems: sources)
|
||||
uploads.enqueue(files: files, target: target, sourceItems: exportedItems)
|
||||
}
|
||||
if !job.uploadTargets.isEmpty { openWindow("tasks") }
|
||||
// SENT workflow: show the exported JPEGs for captioning.
|
||||
@@ -901,6 +913,22 @@ final class AppState: ObservableObject {
|
||||
|
||||
// MARK: Upload
|
||||
|
||||
/// Immich album name for an image: the album pattern with variables from its IPTC/EXIF,
|
||||
/// e.g. "{event}" → "DFB-Pokal Frauen: VfL Wolfsburg - TSG 1899 Hoffenheim".
|
||||
/// Unresolved variables are dropped; if nothing is left the fallback pattern is used.
|
||||
func immichAlbum(for item: PhotoItem) -> String {
|
||||
func resolve(_ pattern: String) -> String {
|
||||
guard !pattern.isEmpty else { return "" }
|
||||
let ctx = VariableContext.make(fileURL: item.primary, exif: item.exif, iptc: item.iptc, dateFormat: settings.dateFormat)
|
||||
var s = VariableExpander.expand(pattern, context: ctx, codes: nil)
|
||||
// drop variables that had no value, tidy separators
|
||||
while let open = s.firstIndex(of: "{"), let close = s[open...].firstIndex(of: "}") { s.removeSubrange(open...close) }
|
||||
return s.trimmingCharacters(in: CharacterSet(charactersIn: " -–|·,").union(.whitespaces))
|
||||
}
|
||||
let main = resolve(settings.immich.albumName)
|
||||
return main.isEmpty ? resolve(settings.immich.albumFallback) : main
|
||||
}
|
||||
|
||||
/// Files to upload for an item, depending on the destination's variant.
|
||||
func uploadFiles(for item: PhotoItem, variant: UploadVariant) -> [URL] {
|
||||
switch variant {
|
||||
|
||||
Reference in new issue
Block a user