gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc41587d2c41587d2Merge branch 'bs2' into mainTrackerc41587d2/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. guest = c.episodes != null && c.episodes < mainMin
  40. // a guest: linked only when we have them, never created here (mission 062)
  41. 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. 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

  • c41587d2Merge branch 'bs2' into mainTracker
  • 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
  • 019d5cedMerge branch 'records-1110' into mainTracker
  • f88ae8b9|||PR records: day56 toggle live, reviewTracker
  • b6b3bb4dMerge branch 'ap56e' into mainTracker
  • 29a26da9|||PR AP56e: guard hidden show helpers during session syncTracker
  • 7c9ec236|||PR AP56e: re-vendor Hybriel set day56 (source 36ae83a8, bin c1f595a2)Tracker
  • 4b54f6f9Merge branch 'records-audit' into mainTracker
  • cab4a3bc|||PR records: branch audit, PR-onlyTracker
  • 641e1c4cMerge branch 'records-dp71' into mainTracker
  • 85a6e9f5|||PR records: DP71 checked in ChromeTracker
  • f5be5f18records: gitoria PR-only planTracker
  • 46a37036records: DP71 liveTracker
  • 3bcb7039Status/log: DP71 in progressTracker
  • 5b3a5693Log: SR1b merged via PR 2, DP71 startedTracker
  • 783957c2Merge branch 'sr1-search' into mainTracker
  • 792b9652README: search results come from the routeTracker
  • fd8570b1|||PR search: one server exchange per keystrokeTracker
  • e8f5cbcaLog: SR1 result, SR1bTracker
  • 8ad275a4Log/status: tracker 68, SR1Tracker