diff --git a/Sources/Lichtkasten/Services/AppState.swift b/Sources/Lichtkasten/Services/AppState.swift index dbc6a1a..5d8577e 100644 --- a/Sources/Lichtkasten/Services/AppState.swift +++ b/Sources/Lichtkasten/Services/AppState.swift @@ -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 { diff --git a/Sources/Lichtkasten/Services/UploadQueue.swift b/Sources/Lichtkasten/Services/UploadQueue.swift index e25930e..175d663 100644 --- a/Sources/Lichtkasten/Services/UploadQueue.swift +++ b/Sources/Lichtkasten/Services/UploadQueue.swift @@ -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() } diff --git a/Sources/Lichtkasten/Views/SettingsView.swift b/Sources/Lichtkasten/Views/SettingsView.swift index ed6825a..de972f0 100644 --- a/Sources/Lichtkasten/Views/SettingsView.swift +++ b/Sources/Lichtkasten/Views/SettingsView.swift @@ -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)) diff --git a/Sources/LichtkastenCore/Matchday/Spieltag.swift b/Sources/LichtkastenCore/Matchday/Spieltag.swift index 735088e..76c4324 100644 --- a/Sources/LichtkastenCore/Matchday/Spieltag.swift +++ b/Sources/LichtkastenCore/Matchday/Spieltag.swift @@ -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[.. [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: "-") diff --git a/Tests/LichtkastenCoreTests/CoreTests.swift b/Tests/LichtkastenCoreTests/CoreTests.swift index 4be5563..03102bf 100644 --- a/Tests/LichtkastenCoreTests/CoreTests.swift +++ b/Tests/LichtkastenCoreTests/CoreTests.swift @@ -459,3 +459,20 @@ final class LeagueTests: XCTestCase { XCTAssertEqual(set.league, "1. Bundesliga") } } + +final class MatchVariableTests: XCTestCase { + func testTeamsFromEventText() { + let v = SpieltagGenerator.matchVariables(event: "Bundesliga: Hamburger SV - Borussia Mönchengladbach", + library: SpieltagLibrary()) + XCTAssertEqual(v["vereina"], "Hamburger SV") + XCTAssertEqual(v["vereinb"], "Borussia Mönchengladbach") + let ctx = VariableContext(values: v.merging(["date": "06.11.2026"]) { a, _ in a }) + XCTAssertEqual(VariableExpander.expand("{vereina} - {vereinb} | {date}", context: ctx), + "Hamburger SV - Borussia Mönchengladbach | 06.11.2026") + } + + func testHeadlineStyleAndNoMatch() { + XCTAssertEqual(SpieltagGenerator.teams(fromEvent: "DFB-Pokal: VfL Wolfsburg vs. TSG Hoffenheim, 02.11.2026")?.away, "TSG Hoffenheim") + XCTAssertNil(SpieltagGenerator.teams(fromEvent: "Training")) + } +}