tracker
All repositories: gitoria
13.5 KB
// lib/franchiseseed.hl — THE CURATED FRANCHISES (tracker.worldapi.org#40, mission 034). Creator: "you never build timlines and// franchises". The big franchises (Star Trek, Star Wars, Stargate, MCU, DC …) with their timelines, MOVIES AND SERIES, come from// a hand-written DATA file in the repo — `data/franchises.json` (TRACKER_FRANCHISE_FILE): per franchise its name, summary,// the TMDB collections that join it, and its timelines, each with its order ("in-universe" | "release") and its titles as// [kind ('tv' | 'movie'), TMDB id, "title (year)" — for people only].//// franchiseSeedTable pk @id { kind, key, ref, order, franchise, created, why, at } — what the seed made, one row per thing:// kind 'franchise' key = its name ref = the franchise @id created (true: the seed made it; false: the// creator's own of that name, adopted)// kind 'timeline' key = franchise|timeline ref = the timeline @id order + franchise = what the seed LAST WROTE// (order null: the creator's own of that name)// kind 'collection' key = collection:<id> ref = the timeline @id franchise (null: it had one already, left alone)// kind 'missing' key = tv:<id> / movie:<id> why TMDB has no such title (404) — not asked again// storage/mpackdb/franchiseseed.db//// THE JOB (jobs.hl `franchiseSeedTick`, after every other start job — the collection seed last — one step per tick):// 1. the titles of the file we don't have (search.hl titleIdByTmdb) are IMPORTED, one per step, through the search's own// import (details.hl importWithCredits: details, seasons + episodes, poster, ids, TVmaze, cast + crew — complete), then// the pause the daily sync makes after the same requests (tmdb.hl pauseMsAfter). Without TMDB_READ_TOKEN: no imports.// 2. then ONE build step (no TMDB): each franchise found or made, its collections' timelines attached, each timeline made// or brought up to date with the titles we have, in the file's order; then every TMDB collection timeline whose titles// are ALL in one curated timeline is hidden (`supersededBy`, franchises.hl seededCoverOf), a partly covered one joins// that franchise.// EDITOR CHANGES WIN: a seeded timeline whose order or franchise is no longer what the seed last wrote was edited by the// creator — it is never written again (`kept`); a franchise or timeline of the same name the creator made is used / left// alone, never doubled; a collection timeline that has a franchise keeps it. RESUMES after a restart (imports are stored at// once; the queue = what is still missing); IDEMPOTENT (a second start imports nothing and writes nothing).import { MPackDB } from 'hl:mpackdb'import { readFile, exists } from 'hl:fs'import { now } from 'hl:time'import { storageDir, envOr, newId } from './util.hl'import { showById, liveShowOf } from './shows.hl'import { titleIdByTmdb } from './search.hl'import { importWithCredits } from './details.hl'import { ensureFranchises, franchiseById, timelineById, timelinesTable, createFranchise, putTimeline, setTimelineFranchise, franchiseByName, timelineByName, timelineOfCollection, storeSeeded, persistFranchises, seededCoverOf, setSuperseded } from './franchises.hl'static franchiseSeedTable = new MPackDB(file = storageDir + '/franchiseseed.db', primaryKey = '@id', indexes = [])static franchiseFile = envOr('TRACKER_FRANCHISE_FILE', './data/franchises.json')// the queue is a plain static list filled in place (a static cannot be reassigned — collections.hl)static importQueue = []static seedRows = {}static fseed = { built = false pos = 0 file = false franchises = 0 timelines = 0 titles = 0 have = 0 imported = 0 failed = 0 missing = 0requests = 0 tvmazeRequests = 0 franchisesCreated = 0 franchisesAdopted = 0 timelinesCreated = 0 updated = 0 unchanged = 0 kept = 0 empty = 0placed = 0 collections = 0 superseded = 0 unsuperseded = 0 joined = 0 writes = 0 error = '' }static typeOfKind = (&kind) => { return kind == 'tv' ? 'series' : 'movie' }static titleKeyOf = (&kind, &tmdbId) => { return kind + ':' + tmdbId }// our show @id for an entry of the file (a merged tombstone answers its keeper), or nullstatic ourIdOf = (&entry) => {id = titleIdByTmdb(typeOfKind(entry[0]), entry[1])s = id != null ? liveShowOf(showById(id)) : nullreturn s != null ? s.id : null}static sameList = (&a, &b) => {if (a == null || b == null || a.length != b.length) { return false }let i = 0while (i < a.length) {if (a[i] != b[i]) { return false }i = i + 1}return true}static noteRow = (kind, key, &ref, &order, &franchise, created, why) => {old = seedRows[kind + '|' + key]rec = { id = old != null ? old.id : newId() kind = kind key = key ref = ref order = order franchise = franchise created = created why = why at = now() }if (old != null) { franchiseSeedTable.update(rec.id, rec) } else { franchiseSeedTable.put(rec) }seedRows[kind + '|' + key] = recreturn rec}static rowOf = (&kind, &key) => { return seedRows[kind + '|' + key] }// the file → { franchises: [...] }, or null (logged) when it is not therestatic readFranchiseFile = () => {if (!exists(franchiseFile)) {fseed.error = franchiseFile + ' not found'return null}d = JSON.parse(readFile(franchiseFile))if (d == null || d.franchises == null) {fseed.error = franchiseFile + ': no "franchises" list'return null}return d}static fileData = { franchises = [] }// at the job's start: the file read, the seed's rows loaded, the queue = the file's titles we don't have (`imports` false: none)static franchiseSeedPrepare = (&imports) => {if (fseed.built) { return importQueue.length }fseed.built = trueensureFranchises()for (r of franchiseSeedTable.find(null, null)) { seedRows[r.kind + '|' + r.key] = r }d = readFranchiseFile()if (d == null) { return 0 }fseed.file = truefileData.franchises = d.franchisesqueued = {}for (f of d.franchises) {fseed.franchises = fseed.franchises + 1for (t of f.timelines) {fseed.timelines = fseed.timelines + 1for (e of t.titles) {let key = titleKeyOf(e[0], e[1])if (queued[key] != true) {queued[key] = truefseed.titles = fseed.titles + 1if (ourIdOf(e) != null) { fseed.have = fseed.have + 1 }else if (rowOf('missing', key) != null) { fseed.missing = fseed.missing + 1 }else if (imports) { importQueue.push(e) }}}}}return importQueue.length}static franchiseSeedStats = () => { return fseed }// ---- step 1: ONE import → { requests, tvmazeRequests (what the pause counts), error } --------------------------------------static importOne = (&entry) => {out = { requests = 1 tvmazeRequests = 0 error = '' done = false }key = titleKeyOf(entry[0], entry[1])fseed.requests = fseed.requests + 1r = importWithCredits(entry[0], entry[1])if (r.error != null) {fseed.failed = fseed.failed + 1out.error = key + ' (' + entry[2] + '): ' + r.error// TMDB has no such title: remembered, never asked again (a passing failure is tried again on the next start)if (r.error.includes('HTTP 404')) { noteRow('missing', key, null, null, null, false, r.error) franchiseSeedTable.persist() }return out}if (r.sync != null) {out.requests = 1 + r.sync.requestsout.tvmazeRequests = r.sync.tvmazeRequestsfseed.requests = fseed.requests + r.sync.requestsfseed.tvmazeRequests = fseed.tvmazeRequests + r.sync.tvmazeRequests}if (r.created == true) { fseed.imported = fseed.imported + 1 } else { fseed.have = fseed.have + 1 }return out}// ---- step 2: the build (no TMDB) ---------------------------------------------------------------------------------------------// the franchise of the file's entry `f`: the one the seed made / adopted before, else the creator's of that name, else a new onestatic franchiseOf = (&f) => {row = rowOf('franchise', f.name)if (row != null) { return franchiseById(row.ref) }mine = franchiseByName(f.name)if (mine != null) {fseed.franchisesAdopted = fseed.franchisesAdopted + 1noteRow('franchise', f.name, mine.id, null, null, false, 'the creator\'s own')return mine}c = createFranchise(f.name, f.summary)if (c.error != null) {fseed.error = f.name + ': ' + c.errorreturn null}fseed.franchisesCreated = fseed.franchisesCreated + 1noteRow('franchise', f.name, c.id, null, null, true, '')return franchiseById(c.id)}// a TMDB collection's timeline (collection seed) joins the franchise — once, and only when it has none yetstatic attachCollection = (&collection, &fid) => {key = 'collection:' + collectionif (rowOf('collection', key) != null) { return false }t = timelineOfCollection(collection)if (t == null) { return false }if (t.franchise != null && t.franchise != '') {noteRow('collection', key, t.id, null, null, false, 'has a franchise already')return false}r = setTimelineFranchise(t.id, fid)if (r.error != null) {fseed.error = key + ': ' + r.errorreturn false}fseed.collections = fseed.collections + 1noteRow('collection', key, t.id, null, fid, true, '')return true}// one timeline of the file: made, brought up to date, or left alone (the creator's)static buildTimeline = (&f, &fid, &tl) => {key = f.name + '|' + tl.nameorder = []for (e of tl.titles) {let sid = ourIdOf(e)if (sid != null && !order.includes(sid)) { order.push(sid) }}fseed.placed = fseed.placed + order.lengthrow = rowOf('timeline', key)if (row == null) {mine = timelineByName(tl.name)if (mine != null) {// the creator made one of that name: theirs, never written by the seedfseed.kept = fseed.kept + 1noteRow('timeline', key, mine.id, null, null, false, 'the creator\'s own')return true}// none of its titles here yet (no TMDB token, or every import failed): made on a later startif (order.length == 0) {fseed.empty = fseed.empty + 1return true}rec = putTimeline(tl.name, fid, order, 'seed', null, tl.order == 'release' ? 'release' : 'in-universe')if (rec == null) {fseed.error = key + ': not stored'return false}fseed.timelinesCreated = fseed.timelinesCreated + 1fseed.writes = fseed.writes + 1noteRow('timeline', key, rec.id, order, fid, true, '')return true}t = timelineById(row.ref)// gone, or the creator's own, or edited since the seed wrote it (its order or franchise changed): editor changes winif (t == null || row.order == null || !sameList(t.order, row.order) || t.franchise != row.franchise) {fseed.kept = fseed.kept + 1return true}if (sameList(t.order, order) && t.franchise == fid) {fseed.unchanged = fseed.unchanged + 1return true}r = storeSeeded(t, order, fid)if (r.error != null) {fseed.error = key + ': ' + r.errorreturn false}fseed.updated = fseed.updated + 1fseed.writes = fseed.writes + 1noteRow('timeline', key, t.id, order, fid, true, '')return true}// tracker#40: every TMDB collection timeline against the curated ones — all its titles in one → hidden (superseded: no second// widget on First Contact); the cover gone → shown again; partly covered and without a franchise → joins that franchisestatic supersedeCollections = () => {for (t of timelinesTable.find(null, null)) {if (t.tmdbCollection != null && t.order != null) {let cov = seededCoverOf(t.order)if (cov.cover != null && t.supersededBy != cov.cover) {if (setSuperseded(t, cov.cover).error == null) { fseed.superseded = fseed.superseded + 1 }} else if (cov.cover == null && t.supersededBy != null) {if (setSuperseded(t, null).error == null) { fseed.unsuperseded = fseed.unsuperseded + 1 }} else if (cov.cover == null && cov.franchise != null && (t.franchise == null || t.franchise == '')) {if (setTimelineFranchise(t.id, cov.franchise).error == null) { fseed.joined = fseed.joined + 1 }}}}return true}static buildAll = () => {for (f of fileData.franchises) {let fr = franchiseOf(f)if (fr != null) {if (f.collections != null) { for (c of f.collections) { attachCollection(c, fr.id) } }for (tl of f.timelines) { buildTimeline(f, fr.id, tl) }}}supersedeCollections()persistFranchises()franchiseSeedTable.persist()return true}// ONE step: the next import, or — the queue done — the build → { requests, tvmazeRequests, error, done }static franchiseSeedStep = () => {if (!fseed.file) { return { requests = 0 tvmazeRequests = 0 error = fseed.error done = true } }if (fseed.pos < importQueue.length) {e = importQueue[fseed.pos]fseed.pos = fseed.pos + 1// imported meanwhile (the search, a person page): nothing to askif (ourIdOf(e) != null) {fseed.have = fseed.have + 1return { requests = 0 tvmazeRequests = 0 error = '' done = false }}return importOne(e)}buildAll()return { requests = 0 tvmazeRequests = 0 error = fseed.error done = true }}static franchiseSeedLine = () => {s = fseedreturn 'franchises=' + s.franchises + ' (created=' + s.franchisesCreated + ' adopted=' + s.franchisesAdopted + ') timelines=' + s.timelines + ' (created=' + s.timelinesCreated+ ' updated=' + s.updated + ' unchanged=' + s.unchanged + ' kept=' + s.kept + ' empty=' + s.empty + ') collections=' + s.collections + ' superseded=' + s.superseded + ' unsuperseded=' + s.unsuperseded + ' joined=' + s.joined + ' titles=' + s.titles + ' had=' + s.have+ ' imported=' + s.imported + ' failed=' + s.failed + ' missing=' + s.missing + ' placed=' + s.placed + ' requests=' + s.requests + ' tvmazeRequests=' + s.tvmazeRequests}
Branches
- mainmain branch
Latest commits
- fbb903cctracker#33/#37 (mission 032): a title without a TMDB poster gets its backdrop (w780, posterFromBackdrop, shown 2:3 centre-cropped); movies store runtime, the page shows release date + runtime; art backfill (public titles without poster file / movies without runtime) and person photo backfill (tmdbProfile / photoCheck) as the last start jobs (TRACKER_ART, TRACKER_PHOTOS; off in every gate start); gates 379/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy: art 4977 titles in 42 min (115 posters, 15 backdrops, 4609 runtimes), The Remaining shows its backdrop + 7 minmre
- 4ecc67b2tracker: STATUS/LOG for the t38 + t40 merge (gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy checks)mre
- e5945d2fMerge t40 (tracker#40 curated franchises, Franchises menu, superseded collections) into main: deploy.sh lists all six gates (browser, kinds, franchises, pager, franchiseseed, check-theme); search.hl keeps #37's personPhotoOf + #40's importWithCredits; pager gate runs with TRACKER_FRANCHISE_SEED=0; gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0mre
- b638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mre
- f8ffa4dbtracker: report 032 + The Remaining + #39mre
- 7565a863tracker: LOG timemre
- b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
- 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre
- 9448d643tracker#35 follow-up (mission 033): TVmaze 'Running' is labelled 'Returning', or 'Airing' while a non-special episode of the two newest seasons is released within today +-7 days (data unchanged); gate fixtures Running/Airing/Aired + a special; browser 366/0, kinds 32/0, franchises 52/0, pager 229/0, check-theme 0mre
- 7d4b293dtracker#40: "Franchises" in the main menu (desktop header after People, phone sidebar) → /franchises, marked on franchise and timeline pages; gates 365/0, 32/0, 53/0, 24/0, check-theme 0mre
- 8751adb8tracker: report 032mre
- 9bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre
- 718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre
- 93dfb0batracker#40 (mission 034): the curated franchises — data/franchises.json (17 franchises, 31 timelines, 285 TMDB titles, movies + series, in-universe/release order, 12 TMDB collections attached); lib/franchiseseed.hl + jobs.hl franchiseSeedTick (last start job, imports missing titles via details.hl importWithCredits = the search's Add, one per step paced, then one build; franchiseseed.db: editor changes win, the creator's same-name franchise adopted / timeline left alone, 404 remembered, resumable, idempotent); timeline heads 'N titles · in-universe order' (orderKind) and wrap on a phone; series pages show the widget; new gate tests/franchiseseed.mjs (5th in deploy.sh), the others run with TRACKER_FRANCHISE_SEED=0; gates 365/0, 32/0, 52/0, 24/0, check-theme 0; real copy 196 imported, 0 failed, 7 min, restart unchanged=31mre
- 03ec792ftracker#38 (mission 033): pagination goes exactly to the clicked page — tilelist read the clicked button's text after pagination.hl's own handler had rebuilt the buttons (real clicks only); now li.current, else the button's own text; new gate tests/pager.mjs (5 lists x 11 pages, 390/1280, real + script clicks, Back/Forward) 229/0; browser 365/0, kinds 32/0, franchises 52/0, check-theme 0mre
- 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
- eb3b9205tracker: report 031mre
- 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
- 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
- a386dc92tracker: reports 029 + 030mre