tracker
All repositories: gitoria
14.9 KB
// people.hl — THE PERSON PAGE's data (tracker.worldapi.org#16, components/person.hl `/person/<slug>`): a person by slug,// their facts and filmography, and the ONE-TIME fetch of their whole filmography from TMDB on the first visit. Creator:// "the movies come from artist scrolls. when one clicks on an artist that has no dataset yet the old version fetched that// artist and its entire bibilogrqphy so its profile was complete".//// personBySlug(slug) the person (slug = `urlSegment`) — a slug → id map built once (15k people, one scan)// personInfoOf(p) name, photo URL, born/died lines, bio// filmographyOf(p) their credits (`p.shows`): poster, title, year, role, kind — newest first, adult titles hidden// personFillStep(id) ONE step of the fetch, called again and again by the page until it answers `done`:// 1st call: GET <TMDB>/person/<tmdbId>?append_to_response=combined_credits (ONE request: details +// every cast/crew credit) + the photo (w185, like the posters); the person's facts are updated;// every next call stores the next `fillBatch` titles; the last one links the credits and marks// the person complete (`filmographyAt`, ms). hl:web serves one request at a time — between two// steps every other request is served, so a person with 300 credits never holds the server.//// COMPLETE = `filmographyAt` set: never fetched again (the daily sync may refresh followed people later — not built).// Migrated people are NOT complete (153 of them carry the old tracker's credits — kept, the fetch adds the rest).// A title we don't have → a MINIMAL show record (title, year, type, tmdbId, `adult`, overview, genres by TMDB id, language;// no seasons, no poster file — the daily sync / a backfill brings those), shaped like search.hl importTitle's// (`oldId tmdb-<tv|movie>-<id>`, a free slug), indexed for the search and put into the public lists (catalog.hl).// The person's credits (`shows`, the migrated field): [{ show, character, posterPath, adult }] — `character` is the role// text (the characters, then crew jobs like "Director", " / " between them); `posterPath` = TMDB's, so the page can show// TMDB's small poster (w92, like search's web rows) until we have the file. ADULT (TMDB's flag, mission 054): a row is// shown only for a PUBLIC title (shows.hl `isPublicTitle`: `adult == false`, unknown hidden like the public lists) whose// credit is not adult either (mission 056 merge).// ONE PROCESS PER STORAGE (hybriel#21); new rows get self-assigned 16-hex ids (hybriel#113), like tmdbsync.hl.import { now } from 'hl:time'import { fetch } from 'hl:fetch'import { randomBytes } from 'hl:crypto'import { writeFile, mkDir, exists } from 'hl:fs'import { personsTable, showsTable, genresTable, storageDir, showById, showYear, posterUrlOf, isPublicTitle } from './shows.hl'import { tmdbGet, tmdbImageBase, textOr } from './tmdbsync.hl'import { titleIdByTmdb, indexShow, slugOf } from './search.hl'import { refreshCatalogShow, sortDesc } from './catalog.hl'static profilesDir = storageDir + '/profiles'// titles stored per step (real data: see STATUS.md ticket #16 for the per-step time)static fillBatch = 40static listOr = (v) => { return v == null ? [] : v }// ---- the person -------------------------------------------------------------------------------------------------static slugIndex = { built = false ids = {} }static personBySlug = (slug) => {if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }if (!slugIndex.built) {let m = {}for (p of personsTable.find(null, null)) { if (p.urlSegment != null) { m[p.urlSegment] = p.id } }slugIndex.ids = mslugIndex.built = true}let id = slugIndex.ids[slug]return id == null ? null : personsTable.fetch(id)}static isComplete = (p) => { return p.filmographyAt != null }// the page asks TMDB for this person: not complete yet, and TMDB knows themstatic needsFill = (p) => { return !isComplete(p) && p.tmdbId != null }// the photo: /profiles/<oldId>.<ext> (project.hl profileRoute) — only when the file is there (the migrated `image` = 'jpg'// of 129 people never came with a file)static profileName = (p) => {if (p.oldId == null || p.image == null || p.image == '') { return null }return p.oldId + '.' + p.image}static photoUrlOf = (p) => {let name = profileName(p)return name != null && exists(profilesDir + '/' + name) ? '/profiles/' + name : ''}static monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']// '1986-03-04' → '4 March 1986'; a bare year or anything else as it isstatic dateText = (d) => {let t = textOr(d)if (t == null) { return null }if (t.length < 10) { return t }let m = toNumber(t.slice(5, 7))let day = toNumber(t.slice(8, 10))if (m == null || day == null || m < 1 || m > 12) { return t }return day + ' ' + monthNames[m - 1] + ' ' + t.slice(0, 4)}// { name, photoUrl, born, died, bio } — every field a plain string ('' = none)static personInfoOf = (p) => {let born = dateText(p.birthDate)let place = textOr(p.birthPlace)let bornText = ''if (born != null && place != null) { bornText = 'Born ' + born + ' in ' + place } else if (born != null) { bornText = 'Born ' + born } else if (place != null) { bornText = 'Born in ' + place }let died = dateText(p.deathDate)return { name = p.name != null ? p.name : '' photoUrl = photoUrlOf(p) born = bornText died = died != null ? 'Died ' + died : ''bio = textOr(p.biography) != null ? p.biography : '' }}// ---- the filmography --------------------------------------------------------------------------------------------// the credits, one row per title (a title twice — the migrated credit and TMDB's — is ONE row, roles merged), newest// first by the title's release ('YYYY-MM-DD', else its year), undated last; only public titles (no adult/unknown)static filmographyOf = (p) => {let byShow = {}let order = []for (c of listOr(p.shows)) {if (c != null && c.show != null) {let role = textOr(c.character)let prev = byShow[c.show]if (prev == null) {byShow[c.show] = { role = role != null ? role : '' posterPath = textOr(c.posterPath) adult = c.adult == true }order.push(c.show)} else {let x = previf (role != null && !(' / ' + x.role + ' / ').includes(' / ' + role + ' / ')) { x.role = x.role == '' ? role : x.role + ' / ' + role }if (x.posterPath == null) { x.posterPath = textOr(c.posterPath) }if (c.adult == true) { x.adult = true }byShow[c.show] = x}}}let list = []for (sid of order) {let c = byShow[sid]let s = showById(sid)if (isPublicTitle(s) && !c.adult) {let y = showYear(s)let release = textOr(s.release)let key = release != null && release.length >= 4 ? release : (y != null ? y : '')let poster = posterUrlOf(s)if (poster == '/posters/none' && c.posterPath != null) { poster = tmdbImageBase + '/w92' + c.posterPath }list.push({ key = key id = s.id title = s.title year = y != null ? y : '' href = '/shows/' + s.urlSegment posterUrl = posterrole = c.role typeLabel = s.type == 'movie' ? 'Movie' : 'Series' })}}let out = []let undated = []for (r of sortDesc(list)) { if (r.key == '') { undated.push(r) } else { out.push(r) } }for (r of undated) { out.push(r) }return out}// ---- the fetch ------------------------------------------------------------------------------------------------// person id → { items, pos, credits, added, requests, started, steps } while a fetch is under way (in memory: a restart// loses it — the titles stored so far are found again by TMDB id, nothing is duplicated)static jobs = {}// TMDB genre id → ours (our genres carry TMDB's id)static genreMap = { built = false ids = {} }static genreIdsOfTmdb = (tmdbIds) => {if (!genreMap.built) {let m = {}for (g of genresTable.find(null, null)) { if (g.tmdbId != null) { m['' + g.tmdbId] = g.id } }genreMap.ids = mgenreMap.built = true}let out = []for (t of listOr(tmdbIds)) {let id = genreMap.ids['' + t]if (id != null && !out.includes(id)) { out.push(id) }}return out}// TMDB's combined_credits → one item per title (cast AND crew of the same title merged), TV + movies onlystatic creditItems = (cc) => {let byKey = {}let order = []let all = []if (cc != null) {for (c of listOr(cc.cast)) { all.push({ credit = c role = textOr(c.character) }) }for (c of listOr(cc.crew)) { all.push({ credit = c role = textOr(c.job) }) }}for (a of all) {let c = a.creditlet kind = c.media_typeif ((kind == 'tv' || kind == 'movie') && c.id != null && hlTypeName(c.id) == 'Number') {let k = kind + ':' + c.idlet known = byKey[k]if (known == null) {let name = kind == 'tv' ? textOr(c.name) : textOr(c.title)if (name != null) {byKey[k] = { kind = kind tmdbId = c.id title = name release = textOr(kind == 'tv' ? c.first_air_date : c.release_date)overview = textOr(c.overview) language = textOr(c.original_language) genreIds = listOr(c.genre_ids)posterPath = textOr(c.poster_path) adult = c.adult == true role = a.role != null ? a.role : '' }order.push(k)}} else if (a.role != null && !(' / ' + known.role + ' / ').includes(' / ' + a.role + ' / ')) {let x = knownx.role = x.role == '' ? a.role : x.role + ' / ' + a.rolebyKey[k] = x}}}let out = []for (k of order) { out.push(byKey[k]) }return out}// the photo: w185 → storage/mpackdb/profiles/<oldId>.<ext> — { requests, image, tmdbProfile, failed }static syncProfile = (p, profilePath) => {let out = { requests = 0 image = p.image tmdbProfile = p.tmdbProfile failed = null }if (textOr(profilePath) == null || p.oldId == null) { return out }let parts = profilePath.split('.')let ext = parts[parts.length - 1].toLowerCase()if (ext != 'jpg' && ext != 'jpeg' && ext != 'png' && ext != 'webp') { return out }let file = profilesDir + '/' + p.oldId + '.' + extif (exists(file) && p.tmdbProfile == profilePath && p.image == ext) { return out }out.requests = 1let r = fetch(tmdbImageBase + '/w185' + profilePath, { headers = { 'user-agent' = 'tracker.worldapi.org (person page)' } timeoutMs = 20000 })if (r == null || r.status != 200 || r.body == null || r.body.length == 0) {out.failed = 'photo ' + profilePath + ': ' + (r == null ? 'no answer' : 'HTTP ' + r.status)return out}mkDir(profilesDir)writeFile(file, toBytes(r.body), 420)out.image = extout.tmdbProfile = profilePathreturn out}// step 1: TMDB's person + credits; the facts (a TMDB value that is empty never overwrites ours) and the photostatic startFill = (p) => {let t0 = now()let d = tmdbGet('/person/' + p.tmdbId + '?append_to_response=combined_credits')if (d.failed != null) { return { error = 'TMDB: ' + d.failed } }let items = creditItems(d.combined_credits)let photo = syncProfile(p, d.profile_path)let x = pif (textOr(d.biography) != null) { x.biography = d.biography }if (textOr(d.birthday) != null) { x.birthDate = d.birthday }if (textOr(d.deathday) != null) { x.deathDate = d.deathday }if (textOr(d.place_of_birth) != null) { x.birthPlace = d.place_of_birth }if (textOr(x.imdbId) == null && textOr(d.imdb_id) != null) { x.imdbId = d.imdb_id }if (d.adult != null) { x.adult = d.adult == true }x.image = photo.imagex.tmdbProfile = photo.tmdbProfileif (personsTable.update(x.id, x) == null) { return { error = 'could not store the person: ' + personsTable.lastError() } }if (photo.failed != null) { console.log('person fill: ' + p.name + ': ' + photo.failed) }jobs[p.id] = { items = items pos = 0 credits = [] added = 0 requests = 1 + photo.requests started = t0 steps = 1 tmdbMs = now() - t0 }return { done = false pos = 0 total = items.length }}// a title we don't have: the minimal record (shape: search.hl importTitle) → its id, or nullstatic addMinimalTitle = (cr, pid, pname) => {let kindType = cr.kind == 'tv' ? 'series' : 'movie'let rel = cr.releaselet yr = rel != null && rel.length >= 4 ? toNumber(rel.slice(0, 4)) : nulllet slug = slugOf(cr.title, cr.tmdbId)let record = {id = randomBytes(8, 'hex') title = cr.title summary = cr.overview != null ? cr.overview : '' tmdbSummary = cr.overview tmdbId = cr.tmdbIdlanguage = cr.language type = kindType release = rel year = yr image = nullurlSegment = slug episodesCount = null homepage = null imdbId = null seasonsCount = nullstatus = null tagline = null tvdbId = null tvmzId = null genres = genreIdsOfTmdb(cr.genreIds)cast = [{ person = pid character = cr.role actor = pname }] seasons = [] oldId = 'tmdb-' + cr.kind + '-' + cr.tmdbIdadult = cr.adult imported = now()}if (showsTable.put(record) == null) {console.log('person fill: "' + cr.title + '" not stored: ' + showsTable.lastError())return null}indexShow(record)refreshCatalogShow(record.id)return record.id}// every next step: the next `fillBatch` titles; the last one links the credits and marks the person completestatic fillStep = (p, jobIn) => {let job = jobInlet total = job.items.lengthlet end = job.pos + fillBatchif (end > total) { end = total }let credits = job.creditslet added = job.addedlet pid = p.idlet pname = p.namelet i = job.poswhile (i < end) {let item = job.items[i]let sid = titleIdByTmdb(item.kind == 'tv' ? 'series' : 'movie', item.tmdbId)if (sid == null) {sid = addMinimalTitle(item, pid, pname)if (sid != null) { added = added + 1 }}if (sid != null) { credits.push({ show = sid character = item.role posterPath = item.posterPath adult = item.adult }) }i = i + 1}job.pos = endjob.credits = creditsjob.added = addedjob.steps = job.steps + 1jobs[pid] = jobif (end < total) { return { done = false pos = end total = total } }// done: the credits (+ the migrated ones TMDB no longer lists), completelet have = {}let all = []for (c of credits) { have[c.show] = true all.push(c) }for (c of listOr(p.shows)) { if (c != null && c.show != null && have[c.show] != true) { all.push(c) } }let x = px.shows = allx.filmographyAt = now()if (personsTable.update(x.id, x) == null) { return { error = 'could not store the filmography: ' + personsTable.lastError() } }personsTable.persist()showsTable.persist()jobs[pid] = nullconsole.log('person fill: ' + pname + ' (tmdb ' + p.tmdbId + ') credits=' + total + ' added=' + added + ' requests=' + job.requests + ' steps=' + job.steps + ' tmdbMs=' + job.tmdbMs + ' ms=' + (now() - job.started))return { done = true pos = total total = total added = added }}// one step for the person with this id: { done, pos, total } or { error }static personFillStep = (personId) => {let p = personsTable.fetch(personId)if (p == null) { return { error = 'no such person' } }if (isComplete(p)) { return { done = true } }if (p.tmdbId == null) { return { error = 'TMDB does not know this person' } }let job = jobs[personId]if (job == null) { return startFill(p) }return fillStep(p, job)}
Branches
- mainmain branch
Latest commits
- 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
- 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
- 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre