Gesendet-Status, Agentur-Check, Rückgängig und Spieltag-Assistent

- Gesendet-Status pro Bild: Upload-Historie (FTP + Immich) mit Ziel und Zeit, grünes Abzeichen im Kontaktabzug,
  Anzeige in Lupe und IPTC-Fenster, Filter Gesendet/Nicht gesendet, bereits gesendete beim Upload überspringen,
  'Als nicht gesendet markieren'
- Agentur-Check vor dem FTP-Upload: Pflichtfelder, offene Variablen und Codes, Datum aus alter Vorlage,
  IIM-Längen, offene Trikot-Vorschläge, Mindestgröße; Prüffenster mit Bearbeiten/Erneut prüfen/
  Nur fehlerfreie senden; Einstellungsseite und Schalter pro Server
- Rückgängig/Wiederholen (⌘Z/⇧⌘Z) für Sterne, Farben, Tags, IPTC und Vorlagen, Schreibvorgänge serialisiert,
  in Textfeldern bleibt ⌘Z beim Text
- Spieltag-Assistent (⌘⇧N, auch im Ingest und in der Matchday-Ansicht): Teams, Wettbewerbe und Muster werden
  gespeichert; erzeugt Vorlage im Aufbau der Basis-Vorlage, Ingest-Ordner, Trikot-Teams und aktive Code-Teams;
  Trikotfarben aus der Erkennung fließen ins Team zurück; Matchday nimmt die Teams aus dem Ereignis des Bildes
- Tests für Spieltag-Generator, Agentur-Check und Gesendet-Log, README ergänzt

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-05 00:23:03 +00:00
1 parent 22b2611228
commit 93ecdf03fc
22 files changed
+2119 -49

No files matched your search

@@ -0,0 +1,325 @@
import Foundation
/// Stadium / place of a match.
public struct Venue: Codable, Hashable, Sendable {
public var name: String = "" // "AOK Stadion"
public var city: String = "" // "Wolfsburg"
public var state: String = "" // "Niedersachsen"
public var country: String = "Deutschland"
public var countryCode: String = "DEU"
public init(name: String = "", city: String = "", state: String = "", country: String = "Deutschland", countryCode: String = "DEU") {
self.name = name; self.city = city; self.state = state; self.country = country; self.countryCode = countryCode
}
public var isEmpty: Bool { name.isEmpty && city.isEmpty }
}
/// Kit colors of a team (home / away).
public struct Kit: Codable, Hashable, Sendable {
public var shirt: KitColor
public var shorts: KitColor?
public init(shirt: KitColor, shorts: KitColor? = nil) { self.shirt = shirt; self.shorts = shorts }
}
/// A club/team as it appears in captions, keywords, folder names, jersey recognition.
public struct TeamProfile: Codable, Hashable, Identifiable, Sendable {
public var id = UUID()
public var name: String // "VfL Wolfsburg"
public var shortName: String // "Wolfsburg (F)" – folder names
public var abbreviation: String // "VFL" – match code VFLTSG
/// comma separated, e.g. "VfL Wolfsburg, VfL, Wölfe, Wölfinnen, Grün Weiß"
public var keywords: String
public var venue: Venue // home stadium
public var codeSetID: UUID? // players in the code library
public var codePrefix: String // "w" → w10
public var homeKit: Kit?
public var awayKit: Kit?
public init(name: String, shortName: String = "", abbreviation: String = "", keywords: String = "",
venue: Venue = Venue(), codeSetID: UUID? = nil, codePrefix: String = "") {
self.name = name; self.shortName = shortName; self.abbreviation = abbreviation; self.keywords = keywords
self.venue = venue; self.codeSetID = codeSetID; self.codePrefix = codePrefix
}
enum CodingKeys: String, CodingKey {
case id, name, shortName, abbreviation, keywords, venue, codeSetID, codePrefix, homeKit, awayKit
}
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
id = (try? c.decode(UUID.self, forKey: .id)) ?? UUID()
name = (try? c.decode(String.self, forKey: .name)) ?? ""
shortName = (try? c.decode(String.self, forKey: .shortName)) ?? ""
abbreviation = (try? c.decode(String.self, forKey: .abbreviation)) ?? ""
keywords = (try? c.decode(String.self, forKey: .keywords)) ?? ""
venue = (try? c.decode(Venue.self, forKey: .venue)) ?? Venue()
codeSetID = try? c.decode(UUID.self, forKey: .codeSetID)
codePrefix = (try? c.decode(String.self, forKey: .codePrefix)) ?? ""
homeKit = try? c.decode(Kit.self, forKey: .homeKit)
awayKit = try? c.decode(Kit.self, forKey: .awayKit)
}
/// "VfL Wolfsburg" → "VFL" when no abbreviation is set
public var effectiveAbbreviation: String {
if !abbreviation.isEmpty { return abbreviation.uppercased() }
let words = name.split(separator: " ").map(String.init)
let main = words.first { $0.count > 3 && $0.first?.isLetter == true } ?? words.first ?? name
return String(main.prefix(3)).uppercased()
}
public var effectiveShortName: String { shortName.isEmpty ? name : shortName }
}
/// Competition: "DFB-Pokal Frauen", "Frauen-Bundesliga", "FIBA Women's World Cup" …
public struct Competition: Codable, Hashable, Identifiable, Sendable {
public var id = UUID()
public var name: String // headline / event: "DFB-Pokal Frauen"
public var longName: String // caption: "DFB-Pokal der Frauen"
public var sport: String // "Fußball"
public var keywords: String // comma separated
/// rights notice appended to the caption ("DFB REGULATIONS PROHIBIT …")
public var notice: String
public init(name: String, longName: String = "", sport: String = "Fußball", keywords: String = "", notice: String = "") {
self.name = name; self.longName = longName; self.sport = sport; self.keywords = keywords; self.notice = notice
}
enum CodingKeys: String, CodingKey { case id, name, longName, sport, keywords, notice }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
id = (try? c.decode(UUID.self, forKey: .id)) ?? UUID()
name = (try? c.decode(String.self, forKey: .name)) ?? ""
longName = (try? c.decode(String.self, forKey: .longName)) ?? ""
sport = (try? c.decode(String.self, forKey: .sport)) ?? "Fußball"
keywords = (try? c.decode(String.self, forKey: .keywords)) ?? ""
notice = (try? c.decode(String.self, forKey: .notice)) ?? ""
}
}
/// How the IPTC of every match is built – defaults follow Leon's Photo Mechanic template.
public struct SpieltagPatterns: Codable, Hashable, Sendable {
public var headline = "{competition}: {home} vs. {away}, {matchdate}"
public var event = "{competition}: {home} - {away}"
public var caption = "\n\n\n; {sport}, {competitionLong}, {round}: {home} vs. {away} am {matchdate} im {venue}, {city}{noticeBlock}"
public var folder = "{matchdate} - {homeShort} - {awayShort}"
public var matchCode = "{homeAbbr}{awayAbbr}"
public var seasonKeyword = "Saison {season}"
/// keywords for every match, comma separated ("Fußball, Fußballspiel, BLD")
public var generalKeywords = ""
public init() {}
enum CodingKeys: String, CodingKey { case headline, event, caption, folder, matchCode, seasonKeyword, generalKeywords }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = SpieltagPatterns()
headline = (try? c.decode(String.self, forKey: .headline)) ?? d.headline
event = (try? c.decode(String.self, forKey: .event)) ?? d.event
caption = (try? c.decode(String.self, forKey: .caption)) ?? d.caption
folder = (try? c.decode(String.self, forKey: .folder)) ?? d.folder
matchCode = (try? c.decode(String.self, forKey: .matchCode)) ?? d.matchCode
seasonKeyword = (try? c.decode(String.self, forKey: .seasonKeyword)) ?? d.seasonKeyword
generalKeywords = (try? c.decode(String.self, forKey: .generalKeywords)) ?? d.generalKeywords
}
/// Variables available in all patterns (shown in the assistant).
public static let variables: [(String, String)] = [
("{home}", "Heimteam"), ("{away}", "Gastteam"), ("{homeShort}", "Heim kurz (Ordner)"), ("{awayShort}", "Gast kurz"),
("{homeAbbr}", "Heim-Kürzel"), ("{awayAbbr}", "Gast-Kürzel"), ("{competition}", "Wettbewerb"),
("{competitionLong}", "Wettbewerb lang"), ("{round}", "Runde / Spieltag"), ("{sport}", "Sportart"),
("{venue}", "Stadion"), ("{city}", "Stadt"), ("{state}", "Bundesland"), ("{country}", "Land"),
("{matchdate}", "Datum 02.11.2026"), ("{isomatchdate}", "Datum 2026-11-02"), ("{season}", "Saison 26/27"),
("{matchcode}", "Matchcode"), ("{notice}", "Rechtehinweis"), ("{noticeBlock}", "Leerzeile + Rechtehinweis"),
]
}
/// One planned/created match.
public struct MatchPlan: Codable, Hashable, Identifiable, Sendable {
public var id = UUID()
public var homeID: UUID
public var awayID: UUID
public var competitionID: UUID?
public var round: String
public var date: Date
public var venue: Venue
/// comma separated, only for this match
public var extraKeywords: String
public var baseTemplateID: UUID?
public var templateID: UUID?
/// event text written into the photos – finds the match of a photo later (e.g. in SENT)
public var event: String
public var folderName: String
public var created: Date
public init(homeID: UUID, awayID: UUID, competitionID: UUID?, round: String, date: Date, venue: Venue,
extraKeywords: String = "", baseTemplateID: UUID? = nil) {
self.homeID = homeID; self.awayID = awayID; self.competitionID = competitionID; self.round = round
self.date = date; self.venue = venue; self.extraKeywords = extraKeywords; self.baseTemplateID = baseTemplateID
self.event = ""; self.folderName = ""; self.created = Date()
}
}
/// Everything the Spieltag assistant remembers.
public struct SpieltagLibrary: Codable, Sendable {
public var teams: [TeamProfile] = []
public var competitions: [Competition] = []
public var patterns = SpieltagPatterns()
public var matches: [MatchPlan] = []
public var lastBaseTemplateID: UUID?
public var lastCompetitionID: UUID?
public init() {}
enum CodingKeys: String, CodingKey { case teams, competitions, patterns, matches, lastBaseTemplateID, lastCompetitionID }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
teams = (try? c.decode([TeamProfile].self, forKey: .teams)) ?? []
competitions = (try? c.decode([Competition].self, forKey: .competitions)) ?? []
patterns = (try? c.decode(SpieltagPatterns.self, forKey: .patterns)) ?? SpieltagPatterns()
matches = (try? c.decode([MatchPlan].self, forKey: .matches)) ?? []
lastBaseTemplateID = try? c.decode(UUID.self, forKey: .lastBaseTemplateID)
lastCompetitionID = try? c.decode(UUID.self, forKey: .lastCompetitionID)
}
public func team(_ id: UUID?) -> TeamProfile? { id.flatMap { i in teams.first { $0.id == i } } }
public func competition(_ id: UUID?) -> Competition? { id.flatMap { i in competitions.first { $0.id == i } } }
/// Newest match whose event text is exactly this (IPTC "Event" of a photo).
public func match(forEvent event: String) -> MatchPlan? {
guard !event.isEmpty else { return nil }
return matches.last { $0.event == event }
}
}
/// Builds headline, event, caption, keywords, folder name and the IPTC template of a match.
public enum SpieltagGenerator {
/// Season of a date: July–June, "26/27" for November 2026.
public static func season(for date: Date) -> String {
let c = Calendar(identifier: .gregorian).dateComponents([.year, .month], from: date)
let y = (c.year ?? 2000) % 100, m = c.month ?? 1
let start = m >= 7 ? y : (y + 99) % 100
return String(format: "%02d/%02d", start, (start + 1) % 100)
}
public static func context(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
patterns: SpieltagPatterns) -> [String: String] {
let f = DateFormatter()
f.locale = Locale(identifier: "de_DE")
f.dateFormat = "dd.MM.yyyy"
let iso = DateFormatter()
iso.locale = Locale(identifier: "en_US_POSIX")
iso.dateFormat = "yyyy-MM-dd"
var ctx: [String: String] = [
"home": home.name, "away": away.name,
"homeshort": home.effectiveShortName, "awayshort": away.effectiveShortName,
"homeabbr": home.effectiveAbbreviation, "awayabbr": away.effectiveAbbreviation,
"competition": competition?.name ?? "",
"competitionlong": (competition?.longName.isEmpty == false ? competition?.longName : competition?.name) ?? "",
"round": match.round, "sport": competition?.sport ?? "",
"venue": match.venue.name, "city": match.venue.city, "state": match.venue.state,
"country": match.venue.country, "countrycode": match.venue.countryCode,
"matchdate": f.string(from: match.date), "isomatchdate": iso.string(from: match.date),
"season": season(for: match.date),
"notice": competition?.notice ?? "",
"noticeblock": (competition?.notice ?? "").isEmpty ? "" : "\n\n" + (competition?.notice ?? ""),
]
ctx["matchcode"] = fill(patterns.matchCode, ctx).replacingOccurrences(of: " ", with: "")
return ctx
}
/// Replaces {variables} (case-insensitive) and tidies separators left by empty values
/// (", :" → ":", ", ," → ","). Line breaks are kept exactly.
public static func fill(_ pattern: String, _ ctx: [String: String]) -> String {
var out = ""
var rest = pattern[...]
while let open = rest.firstIndex(of: "{") {
out += rest[..<open]
guard let close = rest[open...].firstIndex(of: "}") else { break }
let key = rest[rest.index(after: open)..<close].lowercased()
if let v = ctx[key] { out += v } else { out += rest[open...close] }
rest = rest[rest.index(after: close)...]
}
out += rest
return out.components(separatedBy: "\n").map(tidy).joined(separator: "\n")
}
static func tidy(_ line: String) -> String {
var s = line
let rules: [(String, String)] = [(#",\s*:"#, ":"), (#",\s*,"#, ","), (#"\s+,"#, ","), (#"\(\s*\)"#, ""), (#" {2,}"#, " ")]
for (p, r) in rules {
s = s.replacingOccurrences(of: p, with: r, options: .regularExpression)
}
// trailing separators from empty values at the end ("…, 02.11.2026, " → "…, 02.11.2026")
s = s.replacingOccurrences(of: #"[\s,;:–-]+$"#, with: "", options: .regularExpression)
return s
}
public static func splitKeywords(_ s: String) -> [String] { IPTCValues.splitList(s) }
public static func keywords(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
patterns: SpieltagPatterns, ctx: [String: String]) -> [String] {
var all: [String] = []
all += splitKeywords(patterns.generalKeywords)
all += splitKeywords(competition?.keywords ?? "")
if !match.round.isEmpty { all.append(match.round) }
all += splitKeywords(home.keywords)
all += splitKeywords(away.keywords)
if !match.venue.name.isEmpty { all.append(match.venue.name) }
if let code = ctx["matchcode"], !code.isEmpty { all.append(code) }
let season = fill(patterns.seasonKeyword, ctx)
if !season.isEmpty { all.append(season) }
all += splitKeywords(match.extraKeywords)
var seen = Set<String>()
return all.filter { seen.insert($0.lowercased()).inserted }
}
/// 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: "-")
}
public static let generatedFields = ["headline", "event", "caption", "city", "sublocation", "state", "country",
"countryCode", "keywords", "dateCreated"]
/// The IPTC template of the match: base template (creator, copyright, …) + everything generated.
public static func makeTemplate(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
patterns: SpieltagPatterns, base: IPTCTemplate?) -> IPTCTemplate {
let ctx = context(match: match, home: home, away: away, competition: competition, patterns: patterns)
var t = base ?? IPTCTemplate(name: "", listMergeMode: .replace)
t.id = match.templateID ?? UUID()
t.name = "Spieltag \(ctx["matchdate"] ?? "") · \(home.name) – \(away.name)"
var v = t.values
v.text["headline"] = fill(patterns.headline, ctx)
v.text["event"] = fill(patterns.event, ctx)
v.text["caption"] = fill(patterns.caption, ctx)
v.text["city"] = match.venue.city.isEmpty ? nil : match.venue.city
v.text["sublocation"] = match.venue.name.isEmpty ? nil : match.venue.name
v.text["state"] = match.venue.state.isEmpty ? nil : match.venue.state
v.text["country"] = match.venue.country.isEmpty ? nil : match.venue.country
v.text["countryCode"] = match.venue.countryCode.isEmpty ? nil : match.venue.countryCode
v.lists["keywords"] = keywords(match: match, home: home, away: away, competition: competition, patterns: patterns, ctx: ctx)
v.text["dateCreated"] = "{capturetime}"
// "Location created" only if the base template uses it – then it must not keep the old stadium
if t.values.text["lcCity"] != nil || t.values.text["lcSublocation"] != nil {
v.text["lcCity"] = match.venue.city
v.text["lcSublocation"] = match.venue.name
v.text["lcState"] = match.venue.state
v.text["lcCountry"] = match.venue.country
v.text["lcCountryCode"] = match.venue.countryCode
}
t.values = v
t.dateFromCapture = true
if var applied = t.appliedFields {
applied.formUnion(generatedFields)
t.appliedFields = applied
}
if base == nil { t.listMergeMode = .replace }
t.unmappedPMCodes = []
t.modified = Date()
return t
}
}