diff --git a/README.md b/README.md index 6261e73..c9c857e 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,15 @@ How posters are made (sources and their licences, kept layers, options, credits) | `GET /licences` | every source a picture may be made from: its licence, its credit and its terms, and how a picture's licence follows from them | The three picture routes take the same options as query parameters ([docs/posters.md](docs/posters.md) lists -them): `style` (`classic`, `minimal`), `bg` (`satellite`, its alias `aerial`, `osm`, `dark`, `light`, `none`), +them): `style` (`classic`, `minimal`), `bg` (`satellite`, its alias `aerial`, `photo`, `osm`, `dark`, `light`, `none`), `photo` (`natural`, `bw`), `show` (a comma list of `wordmark`, `round`, `name`, `subtitle`, `date`, `circuit`, `locality`, `session`), `locator` and `checker` (`on`, `off`), `track` (`off`, or a colour with an optional width, -`#ffffff,6`), `dim` (0 to 1), `accent` (a colour), `width` (200 up to the picture's own) and `format` (`png`, `jpg`, -`webp`). An unknown option or value is answered 422, naming it. `bg=satellite` takes the layout's picked Wikimedia -Commons photo, else the national aerial photo (USGS in the United States, PDOK in the Netherlands, IGN in France), -else EOxCloudless; [circuits/photos.json](circuits/photos.json) holds the picks, and `{"use": "map"}` there makes a -layout draw the dark map instead of EOxCloudless. Every picture carries the credit line of its sources at its +`#ffffff,6`), `dim` (0 to 1), `accent` (a colour), `width` (400 up to the picture's own) and `format` (`png`, `jpg`, +`webp`). An unknown option or value is answered 422, naming it. `bg=satellite` takes the national aerial photo +(USGS in the United States, PDOK in the Netherlands, IGN in France), else EOxCloudless; `{"use": "map"}` for a +layout in [circuits/photos.json](circuits/photos.json) makes it draw the dark map instead of EOxCloudless. `bg=photo` +takes the layout's picked Wikimedia Commons photo from that file, with the track as an inset, and without a pick +falls back to `bg=satellite`; no style takes it by default. Every picture carries the credit line of its sources at its bottom and in `X-Credits`, its licence in `X-License` (it follows its sources), and `Link: ; rel="license"`. An unknown country, locality, circuit or layout, or a year no layout of the circuit covers, is answered 404, naming it. diff --git a/cdn-api.py b/cdn-api.py index e1026e3..906c7e3 100644 --- a/cdn-api.py +++ b/cdn-api.py @@ -129,10 +129,10 @@ app.mount( # seconds, so it runs in the threadpool instead of holding up every other request on the event loop. POSTER_OPTIONS_DOC = """Options are query parameters, the same on every poster route (docs/posters.md); an unknown option - or value is answered 422, naming it: `style` (classic, minimal), `bg` (satellite, its alias aerial, osm, dark, - light, none), `photo` (natural, bw), `show` (a comma list of wordmark, round, name, subtitle, date, circuit, + or value is answered 422, naming it: `style` (classic, minimal), `bg` (satellite, its alias aerial, photo, osm, + dark, light, none), `photo` (natural, bw), `show` (a comma list of wordmark, round, name, subtitle, date, circuit, locality, session), `locator` and `checker` (on, off), `track` (off, or #rrggbb with an optional width: - #ffffff,6), `dim` (0 to 1), `accent` (#rrggbb), `width` (200 up to the frame's), `format` (png, jpg, webp), and + #ffffff,6), `dim` (0 to 1), `accent` (#rrggbb), `width` (400 up to the frame's), `format` (png, jpg, webp), and `v`, the render version, which the Kometa file adds so clients keep the picture for good.""" diff --git a/circuits/photos.json b/circuits/photos.json index 238ffd5..b8959d3 100644 --- a/circuits/photos.json +++ b/circuits/photos.json @@ -1,3 +1,3 @@ { - "$comment": "The picked Wikimedia Commons aerial photo per layout (docs/posters.md, Picking photos). Key: the layout's path under circuits/ without extension, country/city/circuit/layout, such as \"belgium/spa/circuit-de-spa-francorchamps/1983-\". Value: {\"file\": the Commons title without \"File:\", \"licence\": its LicenseShortName (CC0, public domain, CC BY or CC BY-SA only), \"author\", \"credit\": \"Photo: , , via Wikimedia Commons\", \"date\": YYYY[-MM[-DD]]}; or, instead of a photo, {\"use\": \"map\"}: that layout's bg=satellite then draws the dark OpenStreetMap map instead of EOxCloudless (a photo or a national aerial photo still comes first). Written by the picking tool, read by the poster service; a key starting with \"$\" is a note, not a pick." + "$comment": "The picked Wikimedia Commons aerial photo per layout (docs/posters.md, Picking photos). Key: the layout's path under circuits/ without extension, country/city/circuit/layout, such as \"belgium/spa/circuit-de-spa-francorchamps/1983-\". Value: the photo fields {\"file\": the Commons title without \"File:\", \"licence\": its LicenseShortName (CC0, public domain, CC BY or CC BY-SA only), \"author\", \"credit\": \"Photo: , , via Wikimedia Commons\", \"date\": YYYY[-MM[-DD]]}, which bg=photo draws; \"use\": \"map\", which makes bg=satellite draw the dark OpenStreetMap map instead of EOxCloudless (a national aerial photo still comes first); or both. Written by the picking tool, read by the poster service; a key starting with \"$\" is a note, not a pick." } diff --git a/poster_options.py b/poster_options.py index ef927dd..b4edfb7 100644 --- a/poster_options.py +++ b/poster_options.py @@ -17,14 +17,14 @@ FRAMES = {"poster": (1000, 1500), "thumb": (1920, 1080)} FRAME_OF = {"race": "poster", "season": "poster", "session": "thumb"} SHOW_ITEMS = ("wordmark", "round", "name", "subtitle", "date", "circuit", "locality", "session") -BACKGROUNDS = ("satellite", "osm", "dark", "light", "none") +BACKGROUNDS = ("satellite", "photo", "osm", "dark", "light", "none") # photo is never a style's default BG_ALIASES = {"aerial": "satellite"} # kept for addresses already in use PHOTO_TREATMENTS = ("bw", "natural") FORMATS = {"png": "image/png", "jpg": "image/jpeg", "webp": "image/webp"} STYLES = ("classic", "minimal") ON_OFF = {"on": True, "off": False} TRACK_WIDTHS = (1, 30) -MIN_WIDTH = 200 +MIN_WIDTH = 400 # the full credit line stays readable # The accent the classic and minimal styles give the wordmark: F1 red. One place, mirrored by the picker page. DEFAULT_ACCENT = "#dc1220" diff --git a/poster_sources.py b/poster_sources.py index 02c30cb..06c70bb 100644 --- a/poster_sources.py +++ b/poster_sources.py @@ -1,8 +1,9 @@ """Where every poster picture comes from, under which licence, and the credit each source asks for (docs/posters.md, Sources). Standard library only, so the merge check tests it as it is. -The satellite chain takes, per layout, the first source that has it: the layout's picked Wikimedia Commons photo, -then the national aerial photo of the circuit's country, then EOxCloudless. The national credit lines and tile +bg=satellite takes, per layout, the national aerial photo of the circuit's country, else EOxCloudless (or the dark +map where the operator set {"use": "map"}). bg=photo takes the layout's picked Wikimedia Commons photo, and without a +pick falls back to bg=satellite. The national credit lines and tile addresses were read from each provider's own pages and confirmed against real tiles on 2026-11-27: - USGS: the service description of USGSImageryOnly (its copyright text is the credit; cached to level 16, 17 is a @@ -55,7 +56,7 @@ class MapSource: return NC_SA if self.id == "eox" and self.year != EOX_FREE_YEAR else None -COMMONS = "commons" # the satellite chain's first link: the layout's picked Commons photo +COMMONS = "commons" # bg=photo: the layout's picked Commons photo MAP_OVERRIDE = "map" # a layout's entry {"use": "map"}: its satellite background is the dark map, not EOX # What a source asks of a picture made from it, beyond its credit: share-alike (a CC BY-SA photo) or @@ -135,13 +136,11 @@ def dark_map() -> MapSource: def satellite_source(country_slug: str, circuit_slug: str, layout_slug: str, - entry: Optional[dict] = None) -> Union[str, MapSource]: - """The satellite chain: the layout's picked Commons photo (COMMONS), else the national aerial photo of the - circuit's country, else the chain's last link (satellite_fallback). The layout's entry in circuits/photos.json - is a photo, or the override {"use": "map"}, which a photo or a national source still wins over (they are - sharper).""" - if is_photo(entry): - return COMMONS + entry: Optional[dict] = None) -> MapSource: + """The satellite chain (bg=satellite, aerial): the national aerial photo of the circuit's country, else the + chain's last link (satellite_fallback). "use": "map" in the layout's entry in circuits/photos.json makes that last + link the dark map, whether or not the entry also holds a photo; a national source still wins over it (it is + sharper). A picked photo is not in this chain.""" if country_slug == "united-states": return usgs() if country_slug == "netherlands": @@ -153,6 +152,14 @@ def satellite_source(country_slug: str, circuit_slug: str, layout_slug: str, return satellite_fallback(layout_slug) +def photo_source(country_slug: str, circuit_slug: str, layout_slug: str, + entry: Optional[dict] = None) -> Union[str, MapSource]: + """bg=photo: the layout's picked Commons photo (COMMONS), drawn with the track as an inset; without the photo + fields, whatever bg=satellite draws for the layout (the dark map where "use": "map" is set). Never the default of + any style.""" + return COMMONS if is_photo(entry) else satellite_source(country_slug, circuit_slug, layout_slug, entry) + + def satellite_fallback(layout_slug: str) -> MapSource: """The satellite chain's last link, for a layout no picked photo and no national aerial photo has: EOxCloudless. The one place that decides it.""" @@ -170,19 +177,23 @@ def is_free_licence(licence: str) -> bool: return bool(_FREE_LICENCE.match((licence or "").strip())) +PHOTO_FIELDS = ("file", "licence", "author", "credit", "date") + + def entry_problem(entry) -> Optional[str]: - """Why a picks file's entry is refused, or None: an entry is a photo (file, licence, author, credit, date) under - a free licence, or the override {"use": "map"}, never both.""" + """Why a picks file's entry is refused, or None. An entry carries the photo fields (all of PHOTO_FIELDS, under a + free licence), which decide bg=photo; the override {"use": "map"}, which decides bg=satellite; or both.""" if not isinstance(entry, dict): return "not an object" - if "use" in entry: - if entry["use"] != MAP_OVERRIDE: - return f"unknown use {entry['use']!r}; it takes {MAP_OVERRIDE!r}" - return "a file and a use at once" if "file" in entry else None - if not entry.get("file"): - return "neither a file nor a use" - if not is_free_licence(entry.get("licence", "")): - return f"licence {entry.get('licence')!r} is not CC0, public domain, CC BY or CC BY-SA" + if "use" in entry and entry["use"] != MAP_OVERRIDE: + return f"unknown use {entry['use']!r}; it takes {MAP_OVERRIDE!r}" + given = [field for field in PHOTO_FIELDS if entry.get(field)] + if given and len(given) < len(PHOTO_FIELDS): + return f"incomplete photo fields: no {', '.join(f for f in PHOTO_FIELDS if f not in given)}" + if not given and "use" not in entry: + return "neither the photo fields nor a use" + if given and not is_free_licence(entry["licence"]): + return f"licence {entry['licence']!r} is not CC0, public domain, CC BY or CC BY-SA" return None @@ -240,11 +251,17 @@ def credit_line(credits: list[str]) -> str: return " · ".join(dict.fromkeys(c for c in credits if c)) +_SPELLED = {"ß": "ss", "æ": "ae", "Æ": "AE", "ø": "o", "Ø": "O", "œ": "oe", "Œ": "OE", "đ": "d", "Đ": "D"} + + def ascii_header(text: str) -> str: """The credit line as an ASCII header value (many clients read headers as Latin-1): "©" as "(c)", the " · " - between sources as " | ", accents folded, en and em dashes as "-", any other character outside ASCII as "?". + between sources as " | ", ß, æ, ø, œ and đ spelled out, accents folded, en and em dashes as "-", any other + character outside ASCII as "?". The drawn line and /licences keep the exact text.""" text = text.replace("©", "(c)").replace(" · ", " | ") + for letter, spelled in _SPELLED.items(): # letters NFKD does not take apart, spelled out so names stay readable + text = text.replace(letter, spelled) folded = "".join(c for c in unicodedata.normalize("NFKD", text) if not unicodedata.combining(c)) folded = folded.replace("–", "-").replace("—", "-") return "".join(c if ord(c) < 128 else "?" for c in folded) @@ -272,7 +289,7 @@ def licences() -> dict: "tracks": {"licence": "MIT", "licence_url": "https://opensource.org/license/mit"}, "sources": [ source("commons", "Wikimedia Commons aerial and car photos, picked per layout and per season", - "bg=satellite where a photo is picked for the layout; season posters", + "bg=photo where a photo is picked for the layout; season posters", "per file: CC0, public domain, CC BY or CC BY-SA only", "https://commons.wikimedia.org/wiki/Commons:Licensing", COMMONS_CREDIT.format(author="", licence=""), diff --git a/posters_service.py b/posters_service.py index ae93907..1af4dc6 100644 --- a/posters_service.py +++ b/posters_service.py @@ -731,10 +731,11 @@ class PostersService: background, is_photo, tint, zoom = None, False, options.bg, geo.zoom if geo else DEFAULT_ZOOM if options.bg != "none" and geo: chosen = ps.osm() - if options.bg == "satellite": + if options.bg in ("satellite", "photo"): layout_key = f"{circuit.locality.country.slug}/{circuit.locality.slug}/{circuit.slug}/{layout.slug}" - entry = self.picks(CIRCUIT_PICKS).get(layout_key) # a photo, or the override {"use": "map"} - chosen = ps.satellite_source(circuit.locality.country.slug, circuit.slug, layout.slug, entry) + entry = self.picks(CIRCUIT_PICKS).get(layout_key) # the photo fields, "use": "map", or both + chain = ps.photo_source if options.bg == "photo" else ps.satellite_source + chosen = chain(circuit.locality.country.slug, circuit.slug, layout.slug, entry) if chosen == ps.COMMONS: background, is_photo = self._photo_layer(entry, frame), True else: diff --git a/tests/test_posters.py b/tests/test_posters.py index 2fe4d6a..97d7ad5 100644 --- a/tests/test_posters.py +++ b/tests/test_posters.py @@ -17,22 +17,37 @@ class SatelliteChainTest(unittest.TestCase): def test_the_first_source_that_has_the_layout(self): early = 2016 if ps.EOX_2016_FOR_EARLY_LAYOUTS else 2025 # the one switch for EOX's year photo, use_map = {"file": "A.jpg", "licence": "CC BY 4.0"}, {"use": "map"} + both = {**photo, **use_map} cases = [ # (country, circuit, layout, the layout's entry in circuits/photos.json) → (source, year, tint) - (("bahrain", "bahrain-international-circuit", "2004-", photo), ("commons", None, None)), - (("united-states", "miami-international-autodrome", "2022-", None), ("usgs", None, None)), + (("bahrain", "bahrain-international-circuit", "2004-", photo), ("eox", early, None)), # a pick is bg=photo's + (("united-states", "miami-international-autodrome", "2022-", photo), ("usgs", None, None)), (("netherlands", "circuit-park-zandvoort", "2020-", use_map), ("pdok", None, None)), # national wins (("france", "circuit-paul-ricard", "2018-", None), ("ign", "2021-2023", None)), (("bahrain", "bahrain-international-circuit", "2004-", None), ("eox", early, None)), # first raced by 2016 (("bahrain", "bahrain-international-circuit", "2004-", use_map), ("osm", None, "dark")), # the override + (("bahrain", "bahrain-international-circuit", "2004-", both), ("osm", None, "dark")), # a photo beside it + (("united-states", "miami-international-autodrome", "2022-", both), ("usgs", None, None)), (("spain", "madring", "2026-", None), ("eox", 2025, None)), ] for given, expected in cases: chosen = ps.satellite_source(*given) - got = (chosen, None, None) if chosen == ps.COMMONS else (chosen.id, chosen.year, chosen.tint) - self.assertEqual(got, expected, given) + self.assertEqual((chosen.id, chosen.year, chosen.tint), expected, given) self.assertEqual(ps.satellite_source("bahrain", "x", "2004-", use_map).credit, ps.OSM_CREDIT) + def test_bg_photo_takes_the_pick_else_the_satellite_chain(self): + photo = {"file": "A.jpg", "licence": "CC BY-SA 4.0"} + self.assertEqual(ps.photo_source("united-states", "miami-international-autodrome", "2022-", photo), ps.COMMONS) + self.assertEqual(ps.photo_source("bahrain", "bahrain-international-circuit", "2004-", {**photo, "use": "map"}), + ps.COMMONS) # with use: map beside the photo, bg=photo still draws the photo + for entry, source in ((None, "usgs"), ({"use": "map"}, "usgs")): + self.assertEqual(ps.photo_source("united-states", "miami-international-autodrome", "2022-", entry).id, source) + self.assertEqual(ps.photo_source("bahrain", "bahrain-international-circuit", "2004-", {"use": "map"}).tint, "dark") + options = po.parse_options([("bg", "photo")], "race") + self.assertEqual(options.bg, "photo") + self.assertTrue(all(po.parse_options([("style", style)], kind).bg == "satellite" + for style in po.STYLES for kind in po.FRAME_OF)) # never a style's default + def test_every_french_layout_takes_ign(self): france = json.loads((ROOT / "circuits" / "circuits.json").read_text(encoding="utf-8"))["france"] layouts = [(slug, layout) for locality in france["localities"].values() @@ -48,6 +63,8 @@ class CreditAndLicenceTest(unittest.TestCase): self.assertEqual(line, "© IGN – BD ORTHO, 2021–2023 · © OpenStreetMap contributors") self.assertEqual(ps.ascii_header(line), "(c) IGN - BD ORTHO, 2021-2023 | (c) OpenStreetMap contributors") self.assertEqual(ps.ascii_header("Photo: José Müller — 王 CC BY-SA 4.0"), "Photo: Jose Muller - ? CC BY-SA 4.0") + self.assertEqual(ps.ascii_header("Steffen Prößdorf, Søren Bækgaard, Œuvre, Đorđe"), + "Steffen Prossdorf, Soren Baekgaard, OEuvre, Dorde") def test_a_pictures_licence_follows_its_sources(self): by_sa = ps.pick_share({"licence": "CC BY-SA 3.0 de"}) @@ -66,18 +83,22 @@ class CreditAndLicenceTest(unittest.TestCase): def test_picks_skip_notes_and_refuse_what_they_cannot_use(self): with tempfile.TemporaryDirectory() as kept: path = Path(kept) / "photos.json" + def photo(file, licence): + return {"file": file, "licence": licence, "author": "A", "credit": "Photo: A", "date": "2020"} path.write_text(json.dumps({ "$comment": "a note", - "a/b/c/2004-": {"file": "A.jpg", "licence": "CC BY-SA 4.0", "author": "A"}, - "a/b/c/1950-": {"file": "B.jpg", "licence": "CC BY-NC-SA 2.0", "author": "B"}, - "a/b/c/2010": {"file": "C.jpg", "licence": "Public domain", "author": "C"}, + "a/b/c/2004-": photo("A.jpg", "CC BY-SA 4.0"), + "a/b/c/2010": photo("C.jpg", "Public domain"), "a/b/c/2020-": {"use": "map"}, - "a/b/c/1990": {"use": "satellite"}, - "a/b/c/1991": {"use": "map", "file": "D.jpg", "licence": "CC0"}, + "a/b/c/2021-": {**photo("D.jpg", "CC0"), "use": "map"}, + "a/b/c/1950-": photo("B.jpg", "CC BY-NC-SA 2.0"), # refused: not a free licence + "a/b/c/1990": {"use": "satellite"}, # refused: an unknown use + "a/b/c/1991": {"use": "map", "file": "E.jpg", "licence": "CC0"}, # refused: incomplete photo fields + "a/b/c/1992": {}, # refused: neither })) with self.assertLogs(ps.logger, "ERROR") as logged: - self.assertEqual(sorted(ps.read_picks(path)), ["a/b/c/2004-", "a/b/c/2010", "a/b/c/2020-"]) - self.assertEqual(len(logged.output), 3) + self.assertEqual(sorted(ps.read_picks(path)), ["a/b/c/2004-", "a/b/c/2010", "a/b/c/2020-", "a/b/c/2021-"]) + self.assertEqual(len(logged.output), 4) for name in ("circuits/photos.json", "seasons/photos.json"): self.assertEqual(ps.read_picks(ROOT / name).get("$comment"), None, name) @@ -115,7 +136,7 @@ class OptionsTest(unittest.TestCase): cases = { "colour=red": "'colour'", "bg=esri": "'esri'", "photo=duotone": "'duotone'", "show=name,logo": "'logo'", "track=#fff": "'#fff'", "track=#ffffff,31": "'#ffffff,31'", "dim=1.5": "'1.5'", "dim=nan": "'nan'", - "width=199": "'199'", "width=1001": "'1001'", "format=gif": "'gif'", "bg=osm&bg=dark": "'bg'", + "width=399": "takes 400", "width=1001": "'1001'", "format=gif": "'gif'", "bg=osm&bg=dark": "'bg'", "locator=yes": "'yes'", "accent=red": "'red'", } for query, named in cases.items():