Vereins-Variablen für Immich-Album und Umbenennen
{vereina}/{vereinb} (= {home}/{away}, {heim}/{gast}), {homeshort}/{awayshort}, {competition}, {round},
{season} … aus dem Spieltag des Bildes oder aus dem IPTC-Ereignis („Liga: A - B“). Gilt für das
Immich-Album und das FTP-Umbenennungsmuster, z. B. „{vereina} - {vereinb} | {date}“.
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
3a2c8253ac
commit
fff701674a
5 files changed
+62
-3
No files matched your search
@@ -1156,7 +1156,8 @@ final class AppState: ObservableObject {
|
||||
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 ctx = VariableContext.make(fileURL: item.primary, exif: item.exif, iptc: item.iptc, dateFormat: settings.dateFormat)
|
||||
ctx.values.merge(matchVariables(for: item)) { iptc, _ in iptc } // IPTC values win (city, …)
|
||||
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) }
|
||||
@@ -1166,6 +1167,11 @@ final class AppState: ObservableObject {
|
||||
return main.isEmpty ? resolve(settings.immich.albumFallback) : main
|
||||
}
|
||||
|
||||
/// {home}/{away} (= {vereina}/{vereinb}) … of a photo: from its Spieltag, else read from the IPTC event.
|
||||
func matchVariables(for item: PhotoItem) -> [String: String] {
|
||||
SpieltagGenerator.matchVariables(event: (self.item(item.id) ?? item).iptc.text["event"] ?? "", library: spieltag)
|
||||
}
|
||||
|
||||
/// Files to upload for an item, depending on the destination's variant.
|
||||
func uploadFiles(for item: PhotoItem, variant: UploadVariant) -> [URL] {
|
||||
switch variant {
|
||||
|
||||
@@ -134,8 +134,9 @@ final class UploadQueue: ObservableObject {
|
||||
let src = sourceItems.first { $0.primary == f || $0.companions.contains(f) }
|
||||
var remote = f.lastPathComponent
|
||||
if !pattern.isEmpty {
|
||||
let ctx = VariableContext.make(fileURL: f, exif: src?.exif ?? [:], iptc: src?.iptc ?? IPTCValues(),
|
||||
var ctx = VariableContext.make(fileURL: f, exif: src?.exif ?? [:], iptc: src?.iptc ?? IPTCValues(),
|
||||
dateFormat: state.settings.dateFormat)
|
||||
if let src { ctx.values.merge(state.matchVariables(for: src)) { iptc, _ in iptc } }
|
||||
remote = VariableExpander.expand(pattern, context: ctx)
|
||||
.replacingOccurrences(of: "/", with: "-") + "." + f.pathExtension.lowercased()
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ struct ImmichSettingsView: View {
|
||||
.onChange(of: apiKey) { _, k in Keychain.set(k, account: ImmichSettings.keychainAccount); state.uploads.resetImmich() }
|
||||
TextField("Album", text: $state.settings.immich.albumName, prompt: Text("{event}"))
|
||||
TextField("Album, wenn kein Ereignis im IPTC", text: $state.settings.immich.albumFallback, prompt: Text("{isodate} {city}"))
|
||||
Text("Variablen aus IPTC/EXIF pro Bild, z. B. {event}, {headline}, {city}, {sublocation}, {isodate}, {date}, {year4}, {creator}. Fehlende Alben werden angelegt, leer = kein Album.")
|
||||
Text("Variablen aus IPTC/EXIF pro Bild, z. B. {event}, {headline}, {city}, {sublocation}, {isodate}, {date}, {year4}, {creator}. Vereine: {vereina} - {vereinb} (= {home}/{away}, kurz {homeshort}/{awayshort}), dazu {competition}, {round}, {season} – aus dem Spieltag oder dem Ereignis. Beispiel: {vereina} - {vereinb} | {date}. Fehlende Alben werden angelegt, leer = kein Album.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
if let first = state.selectedItems.first {
|
||||
LabeledContent("Beispiel (\(first.filename))", value: state.immichAlbum(for: first).isEmpty ? "– kein Album –" : state.immichAlbum(for: first))
|
||||
|
||||
@@ -295,6 +295,41 @@ public enum SpieltagGenerator {
|
||||
return all.filter { seen.insert($0.lowercased()).inserted }
|
||||
}
|
||||
|
||||
/// Teams from an IPTC event text without a Spieltag: "Bundesliga: Hamburger SV - Borussia Mönchengladbach"
|
||||
/// → ("Hamburger SV", "Borussia Mönchengladbach"). Also "vs.", "–" and "gegen".
|
||||
public static func teams(fromEvent event: String) -> (home: String, away: String)? {
|
||||
var s = event.trimmingCharacters(in: .whitespaces)
|
||||
if let colon = s.range(of: ": ") { s = String(s[colon.upperBound...]) }
|
||||
for sep in [" vs. ", " vs ", " - ", " – ", " gegen "] {
|
||||
let parts = s.components(separatedBy: sep)
|
||||
if parts.count == 2 {
|
||||
let h = parts[0].trimmingCharacters(in: .whitespaces)
|
||||
var a = parts[1].trimmingCharacters(in: .whitespaces)
|
||||
// "… vs. Gladbach, 06.11.2026" (headline style) → cut the date
|
||||
if let comma = a.range(of: ", ") { a = String(a[..<comma.lowerBound]) }
|
||||
if !h.isEmpty, !a.isEmpty { return (h, a) }
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Variables of the match a photo belongs to – for album names and rename patterns:
|
||||
/// {home} {away} {homeshort} {awayshort} {homeabbr} {awayabbr} {competition} {round} {matchdate} {season} …
|
||||
/// plus German aliases {heim} {gast} {vereina} {vereinb}.
|
||||
public static func matchVariables(event: String, library: SpieltagLibrary) -> [String: String] {
|
||||
var v: [String: String] = [:]
|
||||
if let m = library.match(forEvent: event), let h = library.team(m.homeID), let a = library.team(m.awayID) {
|
||||
v = context(match: m, home: h, away: a, competition: library.competition(m.competitionID), patterns: library.patterns)
|
||||
} else if let t = teams(fromEvent: event) {
|
||||
v = ["home": t.home, "away": t.away, "homeshort": t.home, "awayshort": t.away]
|
||||
}
|
||||
if let h = v["home"], let a = v["away"] {
|
||||
v["heim"] = h; v["gast"] = a; v["vereina"] = h; v["vereinb"] = a
|
||||
v["teama"] = h; v["teamb"] = a
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
/// Folder name for the ingest (no path separators).
|
||||
public static func folderName(patterns: SpieltagPatterns, ctx: [String: String]) -> String {
|
||||
fill(patterns.folder, ctx).replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")
|
||||
|
||||
Reference in new issue
Block a user