tracker
All repositories: gitoria
15.6 KB
// lib/details.hl — A TITLE'S FULL DETAILS (tracker.worldapi.org#26). Creator: "when i go to an artist and it loads the bibliography// those loaded movies and series miss most information and it stays that way when i click on them".//// The person page's fill (people.hl, #16) adds every title we don't have as a MINIMAL record — title, year, overview, genres,// type, tmdbId, adult, this one person as cast; no poster, no seasons, no external ids, no homepage/tagline/status// (`minimal = true`). A search import (search.hl importTitle) is full except for the cast. Here a minimal title gets what a// full import has, plus its cast://// GET <TMDB>/movie/<tmdbId>?append_to_response=external_ids,credits a movie// GET <TMDB>/tv/<tmdbId>?append_to_response=external_ids,aggregate_credits a series (cast of ALL seasons, roles merged)// then sync.hl `syncShowPart(id, <that answer>, …)` — the daily sync's work, without asking for the details again, IN// STEPS (see `jobs` below): a series' seasons + episodes (`season/1,…`), then the poster (w342), missing imdb/tvdb ids,// TVmaze lookup + its episode merge (#15); a movie its imdb id + poster//// Stored (`withDetailsFields`, shared with the daily sync since tracker#18): title, overview → `tmdbSummary` (`summary` is the// creator's own text, never written), homepage, tagline, status, genres (by TMDB id, when// TMDB gives any), release/year/language when we have none, `adult`, the CAST (TMDB's first `castLimit`, in TMDB's order;// a person we have by TMDB id is linked, a new one is added — people.hl castPersonId; cast entries we had and TMDB does not// list are kept after them). Then `detailsAt` (ms) = COMPLETE, never asked again (the daily sync keeps a FOLLOWED title fresh).// TMDB 404 → `detailsCheck = 'TMDB 404'` (never asked again; the page shows what it has). TMDB says ADULT → the flag is// stored, `detailsCheck = 'adult'`, no poster/seasons (mission 056: an adult title is never public, its poster not kept).//// tracker#33 (mission 029): INCOMPLETE is every title TMDB's details never went through (shows.hl isIncomplete) — also the old// tracker's migrated rows (5,697 on the live copy: never synced, 691 series without seasons); they are completed the same way.//// WHO CALLS IT (`completeStep`, again and again until `done`): the show page when an incomplete title is opened// (components/show.hl face `showComplete`, skeleton meanwhile) and the repair job in jobs.hl (`repairTick`, one step per tick// on the app's clock, like the adult backfill) for every incomplete title that exists when the app starts. Adult titles are// left alone by both.//// The cast and crew of the same answer: credits.hl (withCredits). Mission 028: the cast + crew parts moved there, `isIncomplete`// to shows.hl.import { now } from 'hl:time'import { env } from 'hl:proc'import { textOr, listOr } from './util.hl'import { showsTable, personsTable, kindOfTitle, isIncomplete, missingParts } from './shows.hl'import { tmdbGet, adultOf } from './tmdb.hl'import { syncShowWith, syncShowPart, persistSync } from './sync.hl'import { searchTitleChanged, importTitle } from './search.hl'import { refreshCatalogShow } from './catalog.hl'import { genreIdsOfTmdb } from './people.hl'import { withCredits, applyCredits } from './credits.hl'import { hasCredits } from './credits-helpers.hl'// what the show page and the repair complete: an incomplete title that is not adult (mission 054/056: never public)static needsDetails = (&s) => { return isIncomplete(s) && s.adult != true && s.mergedInto == null }// every title the repair job has to do (read once when it starts — so a restart goes on with what is left). tracker#33: the ones// a page shows as reduced first (shows.hl missingParts: no seasons, poster, genres …), then the rest, each in table orderstatic detailsRepairQueue = () => {first = []rest = []for (s of showsTable.find(null, null)) {if (needsDetails(s)) {if (missingParts(s).length > 0) { first.push(s.id) } else { rest.push(s.id) }}}for (id of rest) { first.push(id) }return first}// THE RECORD'S OWN FIELDS from a details answer (tracker#26 completion; tracker#18 the daily sync too — creator: "some shows changed// descriptions and titles and that did not update"): title (a series' `name`, a movie's `title`), TMDB's overview → `tmdbSummary`,// homepage, tagline, status, genres (by TMDB id), adult; type / release / year / language only when we have none. A TMDB value// that is empty never overwrites ours. `summary` is the creator's OWN text — never written here (the page shows summary >// tmdbSummary > tvmazeSummary, shows.hl summaryOf). The slug (`urlSegment`) never changes with the title.// mission 070 (conductor): the sync never DESTROYS what the old tracker's migration brought — before TMDB's value replaces a// migrated record's title / genres / homepage / tagline for the FIRST time, the old one is kept in `migratedTitle` /// `migratedGenres` / `migratedHomepage` / `migratedTagline` (kept, shown nowhere; set once, a later rename leaves it). A record is// migrated when its `oldId` is the old tracker's (not `tmdb-…`: search import, filmography fill). `status`, counts, ids and the// poster are TMDB's state, written by the sync since #9 — not kept.static isMigratedRecord = (&show) => { return show.oldId != null && ('' + show.oldId).slice(0, 5) != 'tmdb-' }static sameIdList = (&a, &b) => {x = listOr(a)y = listOr(b)if (x.length != y.length) { return false }let i = 0while (i < x.length) { if ('' + x[i] != '' + y[i]) { return false } i = i + 1 }return true}static withDetailsFields = (show, &d, &movie) => {x = showmigrated = isMigratedRecord(show)adult = adultOf(d)if (adult != null) { x.adult = adult }let title = textOr(movie ? d.title : d.name)if (title != null) {if (migrated && x.migratedTitle == null && textOr(x.title) != null && x.title != title) { x.migratedTitle = x.title }x.title = title}if (textOr(d.overview) != null) { x.tmdbSummary = d.overview }if (textOr(d.homepage) != null) {if (migrated && x.migratedHomepage == null && textOr(x.homepage) != null && x.homepage != d.homepage) { x.migratedHomepage = x.homepage }x.homepage = d.homepage}if (textOr(d.tagline) != null) {if (migrated && x.migratedTagline == null && textOr(x.tagline) != null && x.tagline != d.tagline) { x.migratedTagline = x.tagline }x.tagline = d.tagline}if (textOr(d.status) != null) { x.status = d.status }tmdbGenreIds = []for (g of listOr(d.genres)) { if (g != null && g.id != null) { tmdbGenreIds.push(g.id) } }genres = genreIdsOfTmdb(tmdbGenreIds)if (genres.length > 0) {if (migrated && x.migratedGenres == null && listOr(x.genres).length > 0 && !sameIdList(x.genres, genres)) { x.migratedGenres = x.genres }x.genres = genres}if (textOr(x.type) == null) { x.type = movie ? 'movie' : 'series' }release = textOr(movie ? d.release_date : d.first_air_date)if (textOr(x.release) == null && release != null) {x.release = releaseif (release.length >= 4) { x.year = toNumber(release.slice(0, 4)) }}if (textOr(x.language) == null && textOr(d.original_language) != null) { x.language = d.original_language }// tracker#33 (mission 032): a movie's runtime in minutes (TMDB's 0 = unknown, not stored)if (movie && d.runtime != null && hlTypeName(d.runtime) == 'Number' && d.runtime > 0) { x.runtime = d.runtime }// tracker#21 (merge, mission 070): TMDB's TV type + the kind from the genres just stored (the delta's light step and the// completion of #26 store it too, not only syncShow / the kind backfill)if (!movie && textOr(d.type) != null) {x.tmdbType = d.typex.kind = kindOfTitle(d.type, x.genres)}return x}// THE DAILY SYNC (jobs.hl syncTick, tools/sync-tmdb.hl; tracker#18): after sync.hl `syncShow` (seasons, episodes, poster,// ids, TVmaze) the record's own fields (withDetailsFields) and its cast + crew (#28) from the SAME details answer (`res.details`)// — no extra request. Answers { renamed (the title changed: the search re-indexes it), cast, crew, people, ms, error }static applySynced = (&showId, &d) => {out = { renamed = false cast = 0 crew = 0 people = 0 ms = 0 error = '' }t0 = now()show = showsTable.fetch(showId)if (show == null || d == null) { return out }movie = show.type == 'movie'before = show.titlelet x = withDetailsFields(show, d, movie)out.renamed = x.title != beforeif (x.adult != true && hasCredits(d, movie)) {w = withCredits(x, d, movie)x = w.showout.cast = w.castout.crew = w.crewout.people = w.people}if (showsTable.update(x.id, x) == null) { out.error = x.title + ': record not stored: ' + showsTable.lastError() }out.ms = now() - t0return out}// A SERIES IS DONE IN STEPS (real data: The Late Show, 22 seasons / 4,252 episodes, took 10.7 s as one step — hl:web serves one// request at a time, every page waited): step 1 = the details request (fields + cast); then one step per PART of its seasons// (≤ `partEpisodes` episodes, ≤ 20 seasons = one TMDB request — sync.hl syncShowPart); the last step = ids, TVmaze, poster,// `detailsAt`. A movie is one step. Between two steps every other request is served.// show id → { d (TMDB's answer of step 1), parts ([[season numbers]]), pos, sum } while a series is under way — in memory: a// restart begins again with the details request; what is stored by then is matched by tmdbId, nothing is duplicatedstatic jobs = {}// (TRACKER_DETAILS_PART_EPISODES: the gate sets 1 → one season per step)static partEpisodes = env('TRACKER_DETAILS_PART_EPISODES') != null ? toNumber(env('TRACKER_DETAILS_PART_EPISODES')) : 300static emptySum = () => { return { steps = 0 requests = 0 tvmazeRequests = 0 cast = 0 crew = 0 people = 0 newSeasons = 0 newEpisodes = 0 posters = 0 ids = 0 ms = 0 error = '' } }static addSum = (sum, &r, &ms) => {o = sumo.steps = o.steps + 1o.requests = o.requests + r.requestso.tvmazeRequests = o.tvmazeRequests + r.tvmazeRequestso.newSeasons = o.newSeasons + r.newSeasons + r.tvmazeSeasonso.newEpisodes = o.newEpisodes + r.newEpisodes + r.tvmazeEpisodeso.posters = o.posters + r.posterso.ids = o.ids + r.idso.ms = o.ms + msif (r.error != '') { o.error = r.error }return o}// TMDB's season list → parts of ≤ partEpisodes episodes (a bigger season is a part of its own), ≤ 20 seasons each; which of// them are really synced (season 0, empty ones) syncShowPart decidesstatic seasonParts = (&d) => {parts = []let cur = []let n = 0for (x of listOr(d.seasons)) {if (x != null && x.season_number != null) {let c = x.episode_count != null ? x.episode_count : 0if (cur.length > 0 && (n + c > partEpisodes || cur.length == 20)) {parts.push(cur)cur = []n = 0}cur.push(x.season_number)n = n + c}}if (cur.length > 0) { parts.push(cur) }return parts}// a step's answer: { skipped (nothing to do), done, requests / tvmazeRequests (THIS step's — what the pause counts), adult,// error ('' = none), retry (a passing failure: no answer, 429, 5xx), sum (the whole title's counts so far: steps, requests,// cast, newSeasons, newEpisodes, posters, ids, ms) }static stepOut = () => { return { skipped = false done = false requests = 0 tvmazeRequests = 0 adult = null error = '' retry = false sum = emptySum() } }// the last step: the title is completestatic markComplete = (&showId, &sum) => {done = showsTable.fetch(showId)done.detailsAt = now()if (sum.error != '') { done.detailsError = sum.error }ok = showsTable.update(done.id, done) != nullrefreshCatalogShow(done.id)searchTitleChanged(done.id)return ok}// step 1: the details request — the record's fields, the cast; a movie also its ids + poster (done); a series' parts are plannedstatic firstStep = (show) => {out = stepOut()t0 = now()movie = show.type == 'movie'out.requests = 1d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids,' + (movie ? 'credits' : 'aggregate_credits'))if (d.failed != null) {out.error = show.title + ': ' + d.failedif (d.status == 404) {show.detailsCheck = 'TMDB 404'showsTable.update(show.id, show)out.done = true} else { out.retry = true }return out}out.adult = adultOf(d)let x = withDetailsFields(show, d, movie)// mission 025: a movie has no season/episode counts (hasTvLeftovers)if (movie) { x.seasonsCount = null x.episodesCount = null }if (out.adult == true) {// never public: the flag, no poster, no seasons, no cast (mission 056)x.detailsCheck = 'adult'showsTable.update(x.id, x)refreshCatalogShow(x.id)searchTitleChanged(x.id)out.done = truereturn out}// tracker#28: the whole cast + the crew, from this same answerw = withCredits(x, d, movie)x = w.showif (showsTable.update(x.id, x) == null) {out.error = show.title + ': not updated: ' + showsTable.lastError()out.retry = truereturn out}sum = emptySum()sum.cast = w.castsum.crew = w.crewsum.people = w.peopleif (movie) {// one request was enough: ids + poster now (syncMovie with this answer)r = syncShowWith(x.id, d)out.requests = r.requestsout.sum = addSum(sum, r, now() - t0)if (r.error != '') { out.error = r.error }markComplete(x.id, out.sum)out.done = truereturn out}sum.steps = 1sum.requests = 1sum.ms = now() - t0// the next steps need the details, not the credits (a long series' aggregate_credits are ~1 MB, copied on every step)dd = ddd.aggregate_credits = nulljobs[x.id] = { d = dd parts = seasonParts(d) pos = 0 sum = sum }out.sum = sumreturn out}// ONE step of completing this title (by our id) — called until `done` (the page's face, the repair job)static completeStep = (&showId) => {show = showsTable.fetch(showId)if (!needsDetails(show)) {jobs[showId] = nulllet out = stepOut()out.skipped = trueout.done = truereturn out}job = jobs[showId]if (job == null) { return firstStep(show) }t0 = now()let out = stepOut()last = job.pos >= job.parts.lengthr = syncShowPart(showId, job.d, { seasons = last ? [] : job.parts[job.pos] finish = last })out.requests = r.requestsout.tvmazeRequests = r.tvmazeRequestsif (r.error != '') { out.error = r.error }j = jobj.sum = addSum(j.sum, r, now() - t0)j.pos = j.pos + 1out.sum = j.sumif (!last) {jobs[showId] = jreturn out}jobs[showId] = nullmarkComplete(showId, j.sum)out.done = truereturn out}// the line every completed title logsstatic completeLine = (&title, &sum) => {return '"' + title + '" steps=' + sum.steps + ' requests=' + sum.requests + ' tvmazeRequests=' + sum.tvmazeRequests + ' cast=' + sum.cast + ' newSeasons=' + sum.newSeasons+ ' newEpisodes=' + sum.newEpisodes + ' posters=' + sum.posters + ' ids=' + sum.ids + ' ms=' + sum.ms + ' crew=' + sum.crew + ' people=' + sum.people + (sum.error != '' ? ' error: ' + sum.error : '')}// flush shows/seasons/episodes + people (new cast members)static persistDetails = () => {persistSync()personsTable.persist()return true}// THE SEARCH IMPORT, COMPLETE (tracker#14 + #28): search.hl importTitle and, for a title it created, the cast + crew from the// same details answer (credits.hl applyCredits — search.hl cannot call it, this file imports search.hl). Used by the search's// "Add" (components/search.hl) and the curated franchise seed (franchiseseed.hl, tracker#40). → importTitle's answerstatic importWithCredits = (&kind, tmdbId) => {r = importTitle(kind, tmdbId)if (r.error != null || r.created != true || r.details == null) { return r }c = applyCredits(r.show, r.details)persistDetails()console.log('search import credits: ' + r.path + ' cast=' + c.cast + ' crew=' + c.crew + ' people=' + c.people + ' ms=' + c.ms + (c.error != '' ? ' error: ' + c.error : ''))return r}
Branches
- mainmain branch
Latest commits
- 5cb85d75deploy.sh: a backup taken while a background job writes (tar exit 1) is a warning; archive checked with gzip -tmre
- 9abda75dtracker: report 035mre
- 12595e47mission 035: theme re-vendored from layouts.worldapi.org 0222f67 (two corner radii: radiusSmall 5px, radiusLarge 10px); the tracker's 18 own radii -> radiusSmall/radiusLarge (--layout-radius is gone); check-theme 0; gates 379/0, 32/0, 53/0, 229/0, 26/0; real copy: every computed radius in {0, 5px, 10px, 50%}mre
- e7305014tracker: report 032 (art + photos)mre
- 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