Season posters: a free photo of each season's car, matched to the operator's curated cars #11
@@ -159,7 +159,7 @@ layers, at most 2 GB, the least recently used going first; a second season of a
|
||||
and fetches nothing. A picture whose map or photo did not arrive is served without it, kept nowhere, and sent with
|
||||
five minutes' `Cache-Control` and no `ETag`.
|
||||
|
||||
Clients keep an address that carries the render version (`?v=r3`, as the Kometa file writes it) for good
|
||||
Clients keep an address that carries the address version (`?v=a1`, as the Kometa file writes it) for good
|
||||
(`immutable`); any other address a day, then ask again with its `ETag` and get a 304 while it is unchanged. Every
|
||||
request the service makes carries the User-Agent `f1-circuits/<version> (+<its public address>)`. OpenStreetMap tiles
|
||||
are fetched only when a picture asks for them, at most two at once; Wikimedia Commons is asked one request at a time.
|
||||
|
||||
+3
-3
@@ -148,14 +148,14 @@ POSTER_OPTIONS_DOC = """Options are query parameters, the same on every poster r
|
||||
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` (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."""
|
||||
`v`, the address version, which the Kometa file adds so clients keep the picture for good."""
|
||||
|
||||
|
||||
def render_poster(request: Request, kind: str, grand_prix_name: Optional[str] = None, season: Optional[int] = None,
|
||||
session_slug: Optional[str] = None) -> Response:
|
||||
"""A picture with its credits, its licence and what clients may keep of it.
|
||||
|
||||
An address with the current render version (?v=) is kept for good; any other a day, then asked again with its
|
||||
An address with the current address version (?v=) is kept for good; any other a day, then asked again with its
|
||||
ETag (a 304 while it is unchanged); a picture served without its map or photo five minutes, with no ETag."""
|
||||
try:
|
||||
options = poster_options.parse_options(request.query_params.multi_items(), kind)
|
||||
@@ -213,7 +213,7 @@ def get_kometa_metadata():
|
||||
- uses Kometa's f1_season builder for round/episode names
|
||||
- sets url_poster on the show (the season poster)
|
||||
- sets url_poster on each Plex 'season' (== each F1 round) from the race poster route, and on each episode
|
||||
from the session thumbnail route; every address carries ?v=<render version>
|
||||
from the session thumbnail route; every address carries ?v=<address version>
|
||||
|
||||
Kometa harmlessly skips shows / seasons that don't exist in the Plex
|
||||
library, so we can emit the full schedule and let Kometa do the matching.
|
||||
|
||||
+7
-4
@@ -8,9 +8,12 @@ import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterable, Optional
|
||||
|
||||
# Part of every layer's and every finished picture's key: raised when what a picture looks like changes, so no
|
||||
# Part of every layer's and every finished picture's key: raised only when the drawing itself changes, so no
|
||||
# picture made before is served again. r3: licensed sources, kept layers, options and credits.
|
||||
RENDER_VERSION = "r3"
|
||||
# Carried by the address clients are given (?v=), separate from RENDER_VERSION: raised when a look changes, so clients
|
||||
# load the address again, served from the pictures already kept. a1: every season poster changed (the season photos).
|
||||
ADDRESS_VERSION = "a1"
|
||||
|
||||
# A frame is the picture's own size: a poster (race and season) and a session thumbnail.
|
||||
FRAMES = {"poster": (1000, 1500), "thumb": (1920, 1080)}
|
||||
@@ -69,7 +72,7 @@ class Options:
|
||||
accent: str
|
||||
width: int
|
||||
format: str
|
||||
versioned: bool # the address carries the current render version (?v=)
|
||||
versioned: bool # the address carries the current address version (?v=)
|
||||
|
||||
def canonical(self) -> str:
|
||||
"""The options as they are drawn, the style resolved: two addresses that draw the same picture match."""
|
||||
@@ -157,7 +160,7 @@ def parse_options(items: Iterable[tuple[str, str]], kind: str) -> Options:
|
||||
|
||||
fmt = _choice("format", given.get("format", "png"), tuple(FORMATS))
|
||||
return Options(style=style, bg=bg, photo=photo, show=show, locator=locator, checker=checker, track=track,
|
||||
dim=dim, accent=accent, width=width, format=fmt, versioned=given.get("v") == RENDER_VERSION)
|
||||
dim=dim, accent=accent, width=width, format=fmt, versioned=given.get("v") == ADDRESS_VERSION)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ keys
|
||||
@@ -194,7 +197,7 @@ def finished_key(route: str, options: Options, layer_keys: Iterable[str]) -> str
|
||||
# ------------------------------------------------------------------ what clients keep
|
||||
|
||||
def cache_headers(kept: bool, versioned: bool, etag: str) -> dict[str, str]:
|
||||
"""An address with the current render version is kept for good; any other a day, asked again with its ETag;
|
||||
"""An address with the current address version is kept for good; any other a day, asked again with its ETag;
|
||||
a picture served without its layer five minutes, with no ETag."""
|
||||
if not kept:
|
||||
return {"Cache-Control": "public, max-age=300"}
|
||||
|
||||
+3
-3
@@ -919,12 +919,12 @@ class PostersService:
|
||||
def render_kometa_metadata(self, first_season: int = 1950, last_offset: int = 1) -> str:
|
||||
"""The Kometa metadata YAML for the Formula 1 library, every season from `first_season` through
|
||||
current_year + last_offset. Per show: the f1_season builder and the season poster; per Plex season (a
|
||||
round): its race poster; per episode: its session thumbnail. Every poster address carries the render
|
||||
version, so clients keep it for good and a changed look reaches them under a new address."""
|
||||
round): its race poster; per episode: its session thumbnail. Every poster address carries the address
|
||||
version (?v=), so clients keep it for good and a changed look reaches them under a new address."""
|
||||
from datetime import datetime
|
||||
from urllib.parse import quote
|
||||
|
||||
version = f"?v={po.RENDER_VERSION}"
|
||||
version = f"?v={po.ADDRESS_VERSION}"
|
||||
last_season = datetime.utcnow().year + last_offset
|
||||
lines: list[str] = [
|
||||
"# This file's data (race names, rounds, dates) comes from the Jolpica F1 API "
|
||||
|
||||
@@ -183,7 +183,10 @@ class OptionsTest(unittest.TestCase):
|
||||
# Any option given overrides the style; equal pictures share one canonical form, whatever their address
|
||||
self.assertEqual(self.parse("style=minimal&checker=on").checker, True)
|
||||
self.assertEqual(self.parse("bg=aerial&v=r1").canonical(), self.parse("").canonical())
|
||||
self.assertTrue(self.parse(f"v={po.RENDER_VERSION}").versioned)
|
||||
# Kept for good: an address with the address version, never one with the render version it carried before
|
||||
self.assertTrue(self.parse(f"v={po.ADDRESS_VERSION}").versioned)
|
||||
self.assertNotEqual(po.ADDRESS_VERSION, po.RENDER_VERSION)
|
||||
self.assertFalse(self.parse("v=r3").versioned)
|
||||
self.assertFalse(self.parse("v=r2").versioned)
|
||||
|
||||
def test_an_unknown_option_or_value_is_named(self):
|
||||
|
||||
Reference in New Issue
Block a user