gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit59095c5959095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre59095c59/lib/credits.hl

8.0 KB

  1. // lib/credits.hl — A TITLE'S CAST AND CREW (tracker.worldapi.org#28): linked to our people, stored on the title, and the
  2. // CREDITS JOB that gives every public title its credits once. Mission 028: out of details.hl (the reading of TMDB's answer is in
  3. // credits-helpers.hl).
  4. //
  5. // CAST AND CREW (tracker.worldapi.org#28; creator: "you show quite few people, usually there are more especially at picard, and
  6. // directors and so"). From the SAME details answer (`credits` of a movie, `aggregate_credits` of a series = every season):
  7. // cast [{ person, character, actor, episodes, guest }] — a movie: TMDB's order (billing); a series: TMDB's aggregate order
  8. // (by episode count, most first; `character` = all roles " / "), `episodes` = the person's episodes, `guest` = fewer than
  9. // `mainMinOf` (half the series' episodes, at most 10, at least 1) → the page puts them after "Guest stars". At most
  10. // `castMax` (300: a talk show/soap lists 3,000+ one-episode guests — Grey's Anatomy 3,243, SNL 2,771 — each would be a
  11. // new person); adult people left out; entries we had and TMDB does not list are kept after them.
  12. // GUESTS ARE NOT PERSON RECORDS (mission 062, memory: 160k people = +3.3 GB RSS at boot): a guest entry is
  13. // { person (only when we have them already, else null), tmdbId, actor, character, profile (TMDB's profile_path), episodes,
  14. // guest = true } — the page links it to `/person/tmdb/<tmdbId>?show=<show id>`, which creates the person on the first open
  15. // (people.hl guestPersonId). The main cast and the crew are linked/created at once as before.
  16. // crew [{ person, name, job, episodes, profile }] job = creator (a series' `created_by`) | director (Director) | writer (Writer) |
  17. // screenplay (Screenplay) | story (Story) | composer (Original Music Composer, Composer, Music) — one entry per person and
  18. // job, a series' by that job's episode count (most first), a movie's in TMDB's order; at most `crewMax` per job.
  19. // `creditsAt` (ms) = the credits are stored (by any path); `creditsCheck` = why the credits job gave up (TMDB 404, adult).
  20. // Every person is linked (people.hl castPersonId: the one we have by TMDB id, else a NEW minimal person — slug, search entry,
  21. // this one credit; their page fills on the first visit). WHO STORES THEM: the details step below (incomplete titles), the daily
  22. // sync and the search import (the sync (sync.hl) asks for the credits in the details request it makes anyway → `applyCredits`), and
  23. // the CREDITS JOB (jobs.hl `creditsTick`, `creditsStep` here) for every other public title once — one request per title.
  24. import { now } from 'hl:time'
  25. import { listOr } from './util.hl'
  26. import { collectStart } from './slices.hl'
  27. import { showsTable, personsTable, isIncomplete } from './shows.hl'
  28. import { tmdbGet, adultOf } from './tmdb.hl'
  29. import { castPersonId, castPeopleCount, personIdByTmdb } from './people.hl'
  30. import { castOf, mainMinOf, crewOf, crewRoleOf, hasCredits } from './credits-helpers.hl'
  31. // the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not list.
  32. // `mainMin` = a series' main-cast episode count (mainMinOf), 0 for a movie (no guests)
  33. static mergedCast = (&show, &tmdbCast, &mainMin) => {
  34. out = []
  35. have = {}
  36. showKey = show.id
  37. seenTmdb = {}
  38. for (c of tmdbCast) {
  39. let guest = c.episodes != null && c.episodes < mainMin
  40. // a guest: linked only when we have them, never created here (mission 062)
  41. let pid = guest ? personIdByTmdb(c.tmdbId) : castPersonId(c, showKey)
  42. if (pid != null && have[pid] != true) {
  43. have[pid] = true
  44. seenTmdb['' + c.tmdbId] = true
  45. out.push({ person = pid tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = guest })
  46. } else if (pid == null && guest && seenTmdb['' + c.tmdbId] != true) {
  47. seenTmdb['' + c.tmdbId] = true
  48. out.push({ person = null tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = true })
  49. }
  50. }
  51. for (c of listOr(show.cast)) {
  52. if (c != null && c.person != null && have[c.person] != true && (c.tmdbId == null || seenTmdb['' + c.tmdbId] != true)) {
  53. have[c.person] = true
  54. out.push(c)
  55. }
  56. }
  57. return out
  58. }
  59. // the title's crew: TMDB's, linked to our people (a crew person new to us gets the job as their role) — replaces what we had
  60. static linkedCrew = (&show, &tmdbCrew) => {
  61. out = []
  62. showKey = show.id
  63. for (c of tmdbCrew) {
  64. let pid = castPersonId({ tmdbId = c.tmdbId name = c.name character = crewRoleOf(c.job) gender = c.gender profile = c.profile }, showKey)
  65. if (pid != null) { out.push({ person = pid name = c.name job = c.job episodes = c.episodes profile = c.profile }) }
  66. }
  67. return out
  68. }
  69. // cast + crew of this record from a details answer → { show (the record with cast, crew, creditsAt), cast, crew, people (new) }
  70. static withCredits = (show, &d, &movie) => {
  71. before = castPeopleCount()
  72. tmdbCast = castOf(d, movie)
  73. x = show
  74. x.cast = mergedCast(show, tmdbCast, movie ? 0 : mainMinOf(d))
  75. x.crew = linkedCrew(show, crewOf(d, movie))
  76. x.creditsAt = now()
  77. return { show = x cast = tmdbCast.length crew = x.crew.length people = castPeopleCount() - before }
  78. }
  79. // the search import: its details answer (sync.hl `res.details`) → the title's cast + crew. Nothing
  80. // for an adult title or an answer without credits. Answers { cast, crew, people, ms, error }
  81. static applyCredits = (&showId, &d) => {
  82. out = { cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  83. t0 = now()
  84. show = showsTable.fetch(showId)
  85. if (show == null || show.adult == true || adultOf(d) == true || !hasCredits(d, show.type == 'movie')) { return out }
  86. w = withCredits(show, d, show.type == 'movie')
  87. if (showsTable.update(show.id, w.show) == null) { out.error = show.title + ': credits not stored: ' + showsTable.lastError() return out }
  88. out.cast = w.cast
  89. out.crew = w.crew
  90. out.people = w.people
  91. out.ms = now() - t0
  92. return out
  93. }
  94. // the credits job touches only shows + people: the episodes' index files (~16 MB on the live data) are not rewritten
  95. static persistCredits = () => {
  96. showsTable.persist()
  97. personsTable.persist()
  98. return true
  99. }
  100. // ---- THE CREDITS JOB (tracker#28, jobs.hl `creditsTick`): every public title that has no credits yet, once --------------
  101. // (the incomplete ones get theirs from completeStep; adult and unknown-flag titles are never asked — not public)
  102. static needsCredits = (&s) => { return s != null && s.tmdbId != null && s.adult == false && s.creditsAt == null && s.creditsCheck == null && !isIncomplete(s) && s.mergedInto == null }
  103. // in table order, read once when the job starts (a restart goes on with what is left)
  104. static creditsScanStart = () => { return collectStart(showsTable) }
  105. static creditsPred = (&s) => { return needsCredits(s) }
  106. // ONE title: one request (details + credits / aggregate_credits) → its cast + crew. Answers { skipped, requests, cast, crew,
  107. // people, ms, error, retry (no answer, 429, 5xx: ask again later) }. TMDB 404 / adult → `creditsCheck`, never asked again.
  108. static creditsStep = (&showId) => {
  109. out = { skipped = false requests = 0 cast = 0 crew = 0 people = 0 ms = 0 error = '' retry = false }
  110. t0 = now()
  111. show = showsTable.fetch(showId)
  112. if (!needsCredits(show)) { out.skipped = true return out }
  113. movie = show.type == 'movie'
  114. out.requests = 1
  115. d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=' + (movie ? 'credits' : 'aggregate_credits'))
  116. if (d.failed != null) {
  117. out.error = show.title + ': ' + d.failed
  118. if (d.status == 404) {
  119. show.creditsCheck = 'TMDB 404'
  120. showsTable.update(show.id, show)
  121. } else { out.retry = true }
  122. return out
  123. }
  124. if (adultOf(d) == true) {
  125. show.creditsCheck = 'adult'
  126. showsTable.update(show.id, show)
  127. return out
  128. }
  129. w = withCredits(show, d, movie)
  130. if (showsTable.update(show.id, w.show) == null) {
  131. out.error = show.title + ': credits not stored: ' + showsTable.lastError()
  132. out.retry = true
  133. return out
  134. }
  135. out.cast = w.cast
  136. out.crew = w.crew
  137. out.people = w.people
  138. out.ms = now() - t0
  139. return out
  140. }

Branches

Latest commits

  • 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre
  • 105309detap targets: every row link, the TMDB/IMDb badges, the widget links, the franchise names and the login-failed link are 44 px high on a phonemre
  • f0b86c8efranchises: 40 loose timelines per page (/franchises/page/N) and a merge sort for the names (1,546 timelines: 20 s and 54,000 px before)mre
  • b9e841a7Merge branch 'sy-sync'mre
  • d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mre
  • 043624b2theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 05d89fd0deploy: security gate (tests/security.mjs)mre
  • 2ae8a47bMerge branch 'sk-sec'mre
  • 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 944ad51eSK: report reports/SK-sec.md, LOGsk
  • 415487c1SK: import budget per user + id type check, gate checkssk
  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre