tracker
All repositories: gitoria
11.9 KB
// 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 tmdbsync.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: overview (`summary` only when ours is empty; `tmdbSummary`), 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).//// 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 project.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.import { now } from 'hl:time'import { env } from 'hl:proc'import { showsTable, personsTable } from './shows.hl'import { tmdbGet, textOr, adultOf, syncShowWith, syncShowPart, persistSync } from './tmdbsync.hl'import { searchTitleChanged } from './search.hl'import { refreshCatalogShow } from './catalog.hl'import { castPersonId, genreIdsOfTmdb } from './people.hl'// how many of TMDB's cast a title keeps (TMDB's own order = billing; a movie can list 100+, each would be a new person)static castLimit = 20static listOr = (v) => { return v == null ? [] : v }// INCOMPLETE = a filmography title (`minimal`) or an import whose sync never finished (`imported`, no `tmdbSync`), not// completed (`detailsAt`) and not given up on (`detailsCheck`)static isIncomplete = (s) => {return s != null && s.tmdbId != null && s.detailsAt == null && s.detailsCheck == null && (s.minimal == true || (s.imported != null && s.tmdbSync == null))}// 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 }// every title the repair job has to do, in table order (read once when it starts — so a restart goes on with what is left)static detailsRepairQueue = () => {let out = []for (s of showsTable.find(null, null)) { if (needsDetails(s)) { out.push(s.id) } }return out}// a series' roles ([{ character, episode_count }]) as one text: "Mother / Lamia"static rolesText = (roles) => {let out = ''for (r of listOr(roles)) {let c = r != null ? textOr(r.character) : nullif (c != null && !(' / ' + out + ' / ').includes(' / ' + c + ' / ')) { out = out == '' ? c : out + ' / ' + c }}return out}// TMDB's cast → [{ tmdbId, name, character, gender }], TMDB's order, at most castLimit, adult people left outstatic castOf = (d, movie) => {let src = movie ? (d.credits != null ? d.credits.cast : null) : (d.aggregate_credits != null ? d.aggregate_credits.cast : null)let out = []for (c of listOr(src)) {if (out.length < castLimit && c != null && c.id != null && hlTypeName(c.id) == 'Number' && textOr(c.name) != null && c.adult != true) {let role = movie ? textOr(c.character) : rolesText(c.roles)out.push({ tmdbId = c.id name = c.name character = role != null ? role : '' gender = c.gender })}}return out}// the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not liststatic mergedCast = (show, tmdbCast) => {let out = []let have = {}let showKey = show.idfor (c of tmdbCast) {let pid = castPersonId(c, showKey)if (pid != null && have[pid] != true) {have[pid] = trueout.push({ person = pid character = c.character actor = c.name })}}for (c of listOr(show.cast)) {if (c != null && c.person != null && have[c.person] != true) {have[c.person] = trueout.push(c)}}return 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 — tmdbsync.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 newSeasons = 0 newEpisodes = 0 posters = 0 ids = 0 ms = 0 error = '' } }static addSum = (sum, r, ms) => {let 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) => {let 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) => {let done = showsTable.fetch(showId)done.detailsAt = now()if (sum.error != '') { done.detailsError = sum.error }let 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) => {let out = stepOut()let t0 = now()let movie = show.type == 'movie'out.requests = 1let d = 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}let x = showout.adult = adultOf(d)if (out.adult != null) { x.adult = out.adult }let overview = textOr(d.overview)if (overview != null) {x.tmdbSummary = overviewif (textOr(x.summary) == null) { x.summary = overview }}if (textOr(d.homepage) != null) { x.homepage = d.homepage }if (textOr(d.tagline) != null) { x.tagline = d.tagline }if (textOr(d.status) != null) { x.status = d.status }let tmdbGenreIds = []for (g of listOr(d.genres)) { if (g != null && g.id != null) { tmdbGenreIds.push(g.id) } }let genres = genreIdsOfTmdb(tmdbGenreIds)if (genres.length > 0) { x.genres = genres }let 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 }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}let tmdbCast = castOf(d, movie)x.cast = mergedCast(x, tmdbCast)if (showsTable.update(x.id, x) == null) {out.error = show.title + ': not updated: ' + showsTable.lastError()out.retry = truereturn out}let sum = emptySum()sum.cast = tmdbCast.lengthif (movie) {// one request was enough: ids + poster now (syncMovie with this answer)let 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() - t0jobs[x.id] = { d = d 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) => {let show = showsTable.fetch(showId)if (!needsDetails(show)) {jobs[showId] = nulllet out = stepOut()out.skipped = trueout.done = truereturn out}let job = jobs[showId]if (job == null) { return firstStep(show) }let t0 = now()let out = stepOut()let last = job.pos >= job.parts.lengthlet r = 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 }let 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 + (sum.error != '' ? ' error: ' + sum.error : '')}// flush shows/seasons/episodes + people (new cast members)static persistDetails = () => {persistSync()personsTable.persist()return true}
Branches
- mainmain branch
Latest commits
- 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
- 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
- f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
- f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
- 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
- 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
- c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
- 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
- 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
- 47a3cae6STATUS: mission 053 merge commit idsmre
- dcc5eecaMerge branch 't14-search'mre
- 03edc783Merge branch 't15-tvmaze'mre
- 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
- 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
- b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
- 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
- 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
- cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
- b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
- 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre