Files
f1-circuits/examples/kometa.html
T
jschoubben b6e6e9d565 Add an example site that calls every route, served at /examples/
A reader learns the API fastest from working calls: one page per area
(circuit browser, track images, GPS traces on a map, grand prix lookup,
posters, Kometa) shows the exact request URL next to its answer. Pages
call their own origin when the app serves them, and the public service
when opened from disk or given ?api=. Posters render only on a button
press, since each one fetches map tiles on the server. A body that does
not match the asked format is said in red, never shown as success.

The image copies examples/ so the deployed app serves the same pages.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
2026-11-27 09:48:04 +01:00

150 lines
6.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kometa metadata · F1 Circuits API examples</title>
<meta name="description" content="The Kometa metadata file the F1 Circuits API generates for a Formula 1 library in Plex, and what it is for.">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="site.css">
</head>
<body>
<header class="site">
<a class="brand" href="index.html">F1 <span>Circuits</span> API</a>
<nav aria-label="Examples">
<a href="index.html">Overview</a>
<a href="circuits.html">Circuit browser</a>
<a href="tracks.html">Track images</a>
<a href="map.html">GPS traces</a>
<a href="grand-prix.html">Grand prix lookup</a>
<a href="posters.html">Posters</a>
<a href="kometa.html" aria-current="page">Kometa</a>
</nav>
<div id="api-base"></div>
</header>
<main>
<h1>Kometa metadata</h1>
<p class="lead">
<a href="https://kometa.wiki/">Kometa</a> (formerly Plex Meta Manager) sets titles and artwork in a Plex library
from YAML files. This route generates the file for a Formula 1 library: it gives every season, every round and every
session of a weekend its artwork, all of it rendered by this API.
</p>
<h2>What it is for</h2>
<div class="card">
<p>In a Formula 1 library as Kometa’s Formula 1 builder shapes it:</p>
<ul>
<li>each F1 season is one <strong>show</strong>, titled like the file’s keys (<code>Season 2024</code>);</li>
<li>each round of that season is a Plex <strong>season</strong> of the show;</li>
<li>each session of the race weekend is an <strong>episode</strong>.</li>
</ul>
<p>
<code>f1_season</code> lets Kometa name the rounds and episodes from that year’s schedule. The file adds the
artwork: the show gets the <a href="posters.html">season poster</a>, each round its race poster, and each episode
its session thumbnail. It covers every season from 1950 to next year; Kometa skips a show or a round the library
does not hold.
</p>
<table class="kv">
<tr><th><code>f1_season</code></th><td>The year the show holds; Kometa’s Formula 1 builder reads its schedule.</td></tr>
<tr><th><code>round_prefix: true</code></th><td>Puts the round number in front of each round’s name.</td></tr>
<tr><th><code>shorten_gp: true</code></th><td>Shortens “Grand Prix” to “GP” in the names.</td></tr>
<tr><th><code>url_poster</code> (show)</th><td><code>/posters/season/{season}.png</code></td></tr>
<tr><th><code>seasons.{round}.url_poster</code></th><td><code>/posters/race/{race name}/{season}.png</code></td></tr>
<tr><th><code>episodes.{n}.url_poster</code></th><td><code>/posters/session/{race name}/{season}/{session}.png</code>, numbered as on the <a href="posters.html">posters page</a>: 10 episodes for a standard weekend, 15 for a sprint weekend.</td></tr>
</table>
<h3>Using it in Kometa</h3>
<p>Point the library at the file’s URL in Kometa’s <code>config.yml</code>; Kometa fetches it on every run:</p>
<pre class="code" id="config"></pre>
<p>
The poster addresses inside the file use the public name the service is served under, so Plex can fetch them.
The answer is <code>text/yaml</code> and may be cached for an hour (<code>Cache-Control: public, max-age=3600</code>).
</p>
</div>
<h2>The file</h2>
<section class="card" id="yaml">
<p>
<code>/kometa/formula-1-metadata.yml</code>. The server builds it from the Jolpica schedule of every season; the
first call after a restart takes several seconds.
</p>
<div class="request"></div>
<div class="status"></div>
<div id="summary"></div>
<div class="controls">
<label>Show <select id="season-filter"><option value="">All seasons</option></select></label>
</div>
<div class="result"></div>
</section>
</main>
<footer class="pager">
<a rel="prev" href="posters.html">← Posters</a>
<a class="home" href="index.html">All examples</a>
<span></span>
</footer>
<script src="site.js"></script>
<script>
(function () {
const { h, api, call, showText, notice } = F1;
const $ = (id) => document.getElementById(id);
const fileURL = F1.absolute(api('/kometa/formula-1-metadata.yml'));
$('config').textContent = [
'libraries:',
' Formula 1: # the library’s name in Plex',
' metadata_files:',
` - url: ${fileURL}`,
].join('\n');
/** Splits the file into one block per show, counting its rounds and episodes. */
function parse(text) {
const lines = text.split('\n');
const head = [];
const seasons = [];
let cur = null;
for (const line of lines) {
const m = /^ {2}"Season (\d+)":/.exec(line);
if (m) { cur = { season: m[1], lines: [line], rounds: 0, episodes: 0 }; seasons.push(cur); continue; }
if (!cur) { head.push(line); continue; }
cur.lines.push(line);
if (/^ {6}\d+:\s*$/.test(line)) cur.rounds++;
else if (/^ {10}\d+:\s*$/.test(line)) cur.episodes++;
}
return { head, seasons };
}
async function load() {
const card = $('yaml');
const answer = await call(card, api('/kometa/formula-1-metadata.yml'), { waiting: 'The server is building the file from every season’s schedule…' });
if (!answer) return;
const text = await answer.blob.text();
const { head, seasons } = parse(text);
const rounds = seasons.reduce((n, s) => n + s.rounds, 0);
const episodes = seasons.reduce((n, s) => n + s.episodes, 0);
const empty = seasons.filter((s) => s.rounds === 0).map((s) => s.season);
const parts = [h('p', {}, `${seasons.length} shows (seasons ${seasons[0] ? seasons[0].season : '?'} to ${seasons.length ? seasons[seasons.length - 1].season : '?'}), ${rounds} rounds with a race poster, ${episodes} episodes with a session thumbnail.`)];
if (empty.length) {
parts.push(notice(empty.length > 2 ? 'error' : 'info',
`${empty.length} of ${seasons.length} shows list no rounds: `, h('code', {}, empty.join(', ')),
'. A show lists no rounds when the server had no schedule for that season from Jolpica (a season still to be published, or Jolpica not answering the server). Kometa then sets only that show’s poster.'));
}
$('summary').replaceChildren(...parts);
const filter = $('season-filter');
filter.append(...seasons.map((s) => h('option', { value: s.season }, `Season ${s.season} (${s.rounds} rounds)`)));
const show = () => {
const s = seasons.find((x) => x.season === filter.value);
showText(card.querySelector('.result'), s ? [...head, ...s.lines].join('\n') : text, { tall: true });
};
filter.addEventListener('change', show);
show();
}
load();
})();
</script>
</body>
</html>