gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf83571c3f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmref83571c3/details.hl

24.1 KB

  1. // details.hl — A TITLE'S FULL DETAILS (tracker.worldapi.org#26). Creator: "when i go to an artist and it loads the bibliography
  2. // those loaded movies and series miss most information and it stays that way when i click on them".
  3. //
  4. // The person page's fill (people.hl, #16) adds every title we don't have as a MINIMAL record — title, year, overview, genres,
  5. // type, tmdbId, adult, this one person as cast; no poster, no seasons, no external ids, no homepage/tagline/status
  6. // (`minimal = true`). A search import (search.hl importTitle) is full except for the cast. Here a minimal title gets what a
  7. // full import has, plus its cast:
  8. //
  9. // GET <TMDB>/movie/<tmdbId>?append_to_response=external_ids,credits a movie
  10. // GET <TMDB>/tv/<tmdbId>?append_to_response=external_ids,aggregate_credits a series (cast of ALL seasons, roles merged)
  11. // then tmdbsync.hl `syncShowPart(id, <that answer>, …)` — the daily sync's work, without asking for the details again, IN
  12. // STEPS (see `jobs` below): a series' seasons + episodes (`season/1,…`), then the poster (w342), missing imdb/tvdb ids,
  13. // TVmaze lookup + its episode merge (#15); a movie its imdb id + poster
  14. //
  15. // Stored (`withDetailsFields`, shared with the daily sync since tracker#18): title, overview → `tmdbSummary` (`summary` is the
  16. // creator's own text, never written), homepage, tagline, status, genres (by TMDB id, when
  17. // TMDB gives any), release/year/language when we have none, `adult`, the CAST (TMDB's first `castLimit`, in TMDB's order;
  18. // 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
  19. // list are kept after them). Then `detailsAt` (ms) = COMPLETE, never asked again (the daily sync keeps a FOLLOWED title fresh).
  20. // TMDB 404 → `detailsCheck = 'TMDB 404'` (never asked again; the page shows what it has). TMDB says ADULT → the flag is
  21. // stored, `detailsCheck = 'adult'`, no poster/seasons (mission 056: an adult title is never public, its poster not kept).
  22. //
  23. // WHO CALLS IT (`completeStep`, again and again until `done`): the show page when an incomplete title is opened
  24. // (components/show.hl face `showComplete`, skeleton meanwhile) and the repair job in project.hl (`repairTick`, one step per tick
  25. // on the app's clock, like the adult backfill) for every incomplete title that exists when the app starts. Adult titles are
  26. // left alone by both.
  27. //
  28. // CAST AND CREW (tracker.worldapi.org#28; creator: "you show quite few people, usually there are more especially at picard, and
  29. // directors and so"). From the SAME details answer (`credits` of a movie, `aggregate_credits` of a series = every season):
  30. // cast [{ person, character, actor, episodes, guest }] — a movie: TMDB's order (billing); a series: TMDB's aggregate order
  31. // (by episode count, most first; `character` = all roles " / "), `episodes` = the person's episodes, `guest` = fewer than
  32. // `mainMinOf` (half the series' episodes, at most 10, at least 1) → the page puts them after "Guest stars". At most
  33. // `castMax` (300: a talk show/soap lists 3,000+ one-episode guests — Grey's Anatomy 3,243, SNL 2,771 — each would be a
  34. // new person); adult people left out; entries we had and TMDB does not list are kept after them.
  35. // crew [{ person, name, job, episodes }] job = creator (a series' `created_by`) | director (Director) | writer (Writer) |
  36. // screenplay (Screenplay) | story (Story) | composer (Original Music Composer, Composer, Music) — one entry per person and
  37. // job, a series' by that job's episode count (most first), a movie's in TMDB's order; at most `crewMax` per job.
  38. // `creditsAt` (ms) = the credits are stored (by any path); `creditsCheck` = why the credits job gave up (TMDB 404, adult).
  39. // Every person is linked (people.hl castPersonId: the one we have by TMDB id, else a NEW minimal person — slug, search entry,
  40. // this one credit; their page fills on the first visit). WHO STORES THEM: the details step below (incomplete titles), the daily
  41. // sync and the search import (tmdbsync.hl asks for the credits in the details request it makes anyway → `applyCredits`), and
  42. // the CREDITS JOB (project.hl `creditsTick`, `creditsStep` here) for every other public title once — one request per title.
  43. import { now } from 'hl:time'
  44. import { env } from 'hl:proc'
  45. import { showsTable, personsTable } from './shows.hl'
  46. import { tmdbGet, textOr, adultOf, syncShowWith, syncShowPart, persistSync } from './tmdbsync.hl'
  47. import { searchTitleChanged } from './search.hl'
  48. import { refreshCatalogShow } from './catalog.hl'
  49. import { castPersonId, castPeopleCount, genreIdsOfTmdb } from './people.hl'
  50. // how many of TMDB's cast a title keeps (see the top; TRACKER_CAST_MAX) and how many people per crew job
  51. static castMax = env('TRACKER_CAST_MAX') != null ? toNumber(env('TRACKER_CAST_MAX')) : 300
  52. static crewMax = 30
  53. static listOr = (v) => { return v == null ? [] : v }
  54. // INCOMPLETE = a filmography title (`minimal`) or an import whose sync never finished (`imported`, no `tmdbSync`), not
  55. // completed (`detailsAt`) and not given up on (`detailsCheck`)
  56. static isIncomplete = (s) => {
  57. return s != null && s.tmdbId != null && s.detailsAt == null && s.detailsCheck == null && (s.minimal == true || (s.imported != null && s.tmdbSync == null))
  58. }
  59. // what the show page and the repair complete: an incomplete title that is not adult (mission 054/056: never public)
  60. static needsDetails = (s) => { return isIncomplete(s) && s.adult != true }
  61. // 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)
  62. static detailsRepairQueue = () => {
  63. let out = []
  64. for (s of showsTable.find(null, null)) { if (needsDetails(s)) { out.push(s.id) } }
  65. return out
  66. }
  67. // a series' roles ([{ character, episode_count }]) as one text: "Mother / Lamia". tracker#28 (real data): TMDB's characters are
  68. // themselves " / "-joined and repeat across seasons ("Data / Lore", "Data", "Yvette Picard (uncredited)") — split, " (uncredited)"
  69. // dropped, each name once, at most `rolesMax` (a voice actor of The Simpsons has 30+), then " / …"
  70. static rolesMax = 4
  71. static rolesText = (roles) => {
  72. let names = []
  73. let more = false
  74. for (r of listOr(roles)) {
  75. let c = r != null ? textOr(r.character) : null
  76. if (c != null) {
  77. for (part of c.split(' / ')) {
  78. let n = part.replaceAll(' (uncredited)', '').trim()
  79. if (n != '' && !names.includes(n)) { if (names.length < rolesMax) { names.push(n) } else { more = true } }
  80. }
  81. }
  82. }
  83. return names.join(' / ') + (more ? ' / …' : '')
  84. }
  85. // a series' episodes of one person: TMDB's total_episode_count, else the sum of the roles' / jobs' counts
  86. static episodesOf = (total, parts) => {
  87. if (total != null && hlTypeName(total) == 'Number') { return total }
  88. let n = 0
  89. for (r of listOr(parts)) { if (r != null && r.episode_count != null && hlTypeName(r.episode_count) == 'Number') { n = n + r.episode_count } }
  90. return n
  91. }
  92. static personOk = (c) => { return c != null && c.id != null && hlTypeName(c.id) == 'Number' && textOr(c.name) != null && c.adult != true }
  93. // TMDB's cast → [{ tmdbId, name, character, gender, episodes }], TMDB's order, at most castMax, adult people left out
  94. static castOf = (d, movie) => {
  95. let src = movie ? (d.credits != null ? d.credits.cast : null) : (d.aggregate_credits != null ? d.aggregate_credits.cast : null)
  96. let out = []
  97. for (c of listOr(src)) {
  98. if (out.length < castMax && personOk(c)) {
  99. let role = movie ? textOr(c.character) : rolesText(c.roles)
  100. out.push({ tmdbId = c.id name = c.name character = role != null ? role : '' gender = c.gender episodes = movie ? null : episodesOf(c.total_episode_count, c.roles) })
  101. }
  102. }
  103. return out
  104. }
  105. // a series' main cast is in at least this many episodes: half of the series' (rounded up), at most 10 (a season), at least 1
  106. static mainMinOf = (d) => {
  107. let n = d.number_of_episodes != null && hlTypeName(d.number_of_episodes) == 'Number' ? d.number_of_episodes : 0
  108. let half = (n - n % 2) / 2 + n % 2
  109. if (half > 10) { return 10 }
  110. return half < 1 ? 1 : half
  111. }
  112. // the crew jobs we show: TMDB job → ours (the page's labels: components/show.hl crewLabels)
  113. static crewJobOf = (job) => {
  114. if (job == 'Director') { return 'director' }
  115. if (job == 'Writer') { return 'writer' }
  116. if (job == 'Screenplay') { return 'screenplay' }
  117. if (job == 'Story') { return 'story' }
  118. if (job == 'Original Music Composer' || job == 'Composer' || job == 'Music') { return 'composer' }
  119. return null
  120. }
  121. static crewJobs = ['creator', 'director', 'writer', 'screenplay', 'story', 'composer']
  122. // keeps a job's list ordered by episodes (most first, equal ones in TMDB's order), at most crewMax (hand-written: no sort())
  123. static insertByEpisodes = (list, item) => {
  124. let out = []
  125. let inserted = false
  126. for (x of list) {
  127. if (!inserted && item.episodes > x.episodes) { out.push(item) inserted = true }
  128. if (out.length < crewMax) { out.push(x) }
  129. }
  130. if (!inserted && out.length < crewMax) { out.push(item) }
  131. return out
  132. }
  133. // TMDB's crew (+ a series' created_by) → [{ tmdbId, name, job, gender, episodes }], grouped by job in `crewJobs` order, one
  134. // entry per person and job
  135. static crewOf = (d, movie) => {
  136. let byJob = {}
  137. let seen = {}
  138. for (j of crewJobs) { byJob[j] = [] }
  139. if (!movie) {
  140. for (c of listOr(d.created_by)) {
  141. if (personOk(c) && seen['creator:' + c.id] != true && byJob['creator'].length < crewMax) {
  142. seen['creator:' + c.id] = true
  143. let l = byJob['creator']
  144. l.push({ tmdbId = c.id name = c.name job = 'creator' gender = c.gender episodes = 0 })
  145. byJob['creator'] = l
  146. }
  147. }
  148. }
  149. let src = movie ? (d.credits != null ? d.credits.crew : null) : (d.aggregate_credits != null ? d.aggregate_credits.crew : null)
  150. for (c of listOr(src)) {
  151. if (personOk(c)) {
  152. // a movie's crew entry has one `job`; a series' has `jobs` [{ job, episode_count }]
  153. let jobs = movie ? [{ job = c.job episode_count = 0 }] : listOr(c.jobs)
  154. for (jb of jobs) {
  155. let ours = jb != null ? crewJobOf(jb.job) : null
  156. if (ours != null && seen[ours + ':' + c.id] != true) {
  157. seen[ours + ':' + c.id] = true
  158. let n = movie ? 0 : episodesOf(jb.episode_count, null)
  159. byJob[ours] = insertByEpisodes(byJob[ours], { tmdbId = c.id name = c.name job = ours gender = c.gender episodes = n })
  160. }
  161. }
  162. }
  163. }
  164. let out = []
  165. for (j of crewJobs) { for (c of byJob[j]) { out.push(c) } }
  166. return out
  167. }
  168. // the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not list.
  169. // `mainMin` = a series' main-cast episode count (mainMinOf), 0 for a movie (no guests)
  170. static mergedCast = (show, tmdbCast, mainMin) => {
  171. let out = []
  172. let have = {}
  173. let showKey = show.id
  174. for (c of tmdbCast) {
  175. let pid = castPersonId(c, showKey)
  176. if (pid != null && have[pid] != true) {
  177. have[pid] = true
  178. out.push({ person = pid character = c.character actor = c.name episodes = c.episodes guest = c.episodes != null && c.episodes < mainMin })
  179. }
  180. }
  181. for (c of listOr(show.cast)) {
  182. if (c != null && c.person != null && have[c.person] != true) {
  183. have[c.person] = true
  184. out.push(c)
  185. }
  186. }
  187. return out
  188. }
  189. static crewRoleOf = (job) => {
  190. if (job == 'creator') { return 'Creator' }
  191. if (job == 'director') { return 'Director' }
  192. if (job == 'writer') { return 'Writer' }
  193. if (job == 'screenplay') { return 'Screenplay' }
  194. if (job == 'story') { return 'Story' }
  195. return 'Music'
  196. }
  197. // 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
  198. static linkedCrew = (show, tmdbCrew) => {
  199. let out = []
  200. let showKey = show.id
  201. for (c of tmdbCrew) {
  202. let pid = castPersonId({ tmdbId = c.tmdbId name = c.name character = crewRoleOf(c.job) gender = c.gender }, showKey)
  203. if (pid != null) { out.push({ person = pid name = c.name job = c.job episodes = c.episodes }) }
  204. }
  205. return out
  206. }
  207. // the answer carries credits (a details request with `credits` / `aggregate_credits` appended)
  208. static hasCredits = (d, movie) => { return d != null && (movie ? d.credits != null : d.aggregate_credits != null) }
  209. // cast + crew of this record from a details answer → { show (the record with cast, crew, creditsAt), cast, crew, people (new) }
  210. static withCredits = (show, d, movie) => {
  211. let before = castPeopleCount()
  212. let tmdbCast = castOf(d, movie)
  213. let x = show
  214. x.cast = mergedCast(show, tmdbCast, movie ? 0 : mainMinOf(d))
  215. x.crew = linkedCrew(show, crewOf(d, movie))
  216. x.creditsAt = now()
  217. return { show = x cast = tmdbCast.length crew = x.crew.length people = castPeopleCount() - before }
  218. }
  219. // THE RECORD'S OWN FIELDS from a details answer (tracker#26 completion; tracker#18 the daily sync too — creator: "some shows changed
  220. // descriptions and titles and that did not update"): title (a series' `name`, a movie's `title`), TMDB's overview → `tmdbSummary`,
  221. // homepage, tagline, status, genres (by TMDB id), adult; type / release / year / language only when we have none. A TMDB value
  222. // that is empty never overwrites ours. `summary` is the creator's OWN text — never written here (the page shows summary >
  223. // tmdbSummary > tvmazeSummary, shows.hl summaryOf). The slug (`urlSegment`) never changes with the title.
  224. static withDetailsFields = (show, d, movie) => {
  225. let x = show
  226. let adult = adultOf(d)
  227. if (adult != null) { x.adult = adult }
  228. let title = textOr(movie ? d.title : d.name)
  229. if (title != null) { x.title = title }
  230. if (textOr(d.overview) != null) { x.tmdbSummary = d.overview }
  231. if (textOr(d.homepage) != null) { x.homepage = d.homepage }
  232. if (textOr(d.tagline) != null) { x.tagline = d.tagline }
  233. if (textOr(d.status) != null) { x.status = d.status }
  234. let tmdbGenreIds = []
  235. for (g of listOr(d.genres)) { if (g != null && g.id != null) { tmdbGenreIds.push(g.id) } }
  236. let genres = genreIdsOfTmdb(tmdbGenreIds)
  237. if (genres.length > 0) { x.genres = genres }
  238. if (textOr(x.type) == null) { x.type = movie ? 'movie' : 'series' }
  239. let release = textOr(movie ? d.release_date : d.first_air_date)
  240. if (textOr(x.release) == null && release != null) {
  241. x.release = release
  242. if (release.length >= 4) { x.year = toNumber(release.slice(0, 4)) }
  243. }
  244. if (textOr(x.language) == null && textOr(d.original_language) != null) { x.language = d.original_language }
  245. return x
  246. }
  247. // THE DAILY SYNC (project.hl syncTick, tools/sync-tmdb.hl; tracker#18): after tmdbsync.hl `syncShow` (seasons, episodes, poster,
  248. // ids, TVmaze) the record's own fields (withDetailsFields) and its cast + crew (#28) from the SAME details answer (`res.details`)
  249. // — no extra request. Answers { renamed (the title changed: the search re-indexes it), cast, crew, people, ms, error }
  250. static applySynced = (showId, d) => {
  251. let out = { renamed = false cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  252. let t0 = now()
  253. let show = showsTable.fetch(showId)
  254. if (show == null || d == null) { return out }
  255. let movie = show.type == 'movie'
  256. let before = show.title
  257. let x = withDetailsFields(show, d, movie)
  258. out.renamed = x.title != before
  259. if (x.adult != true && hasCredits(d, movie)) {
  260. let w = withCredits(x, d, movie)
  261. x = w.show
  262. out.cast = w.cast
  263. out.crew = w.crew
  264. out.people = w.people
  265. }
  266. if (showsTable.update(x.id, x) == null) { out.error = x.title + ': record not stored: ' + showsTable.lastError() }
  267. out.ms = now() - t0
  268. return out
  269. }
  270. // the search import: its details answer (tmdbsync.hl `res.details`) → the title's cast + crew. Nothing
  271. // for an adult title or an answer without credits. Answers { cast, crew, people, ms, error }
  272. static applyCredits = (showId, d) => {
  273. let out = { cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  274. let t0 = now()
  275. let show = showsTable.fetch(showId)
  276. if (show == null || show.adult == true || adultOf(d) == true || !hasCredits(d, show.type == 'movie')) { return out }
  277. let w = withCredits(show, d, show.type == 'movie')
  278. if (showsTable.update(show.id, w.show) == null) { out.error = show.title + ': credits not stored: ' + showsTable.lastError() return out }
  279. out.cast = w.cast
  280. out.crew = w.crew
  281. out.people = w.people
  282. out.ms = now() - t0
  283. return out
  284. }
  285. // 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
  286. // request at a time, every page waited): step 1 = the details request (fields + cast); then one step per PART of its seasons
  287. // (≤ `partEpisodes` episodes, ≤ 20 seasons = one TMDB request — tmdbsync.hl syncShowPart); the last step = ids, TVmaze, poster,
  288. // `detailsAt`. A movie is one step. Between two steps every other request is served.
  289. // show id → { d (TMDB's answer of step 1), parts ([[season numbers]]), pos, sum } while a series is under way — in memory: a
  290. // restart begins again with the details request; what is stored by then is matched by tmdbId, nothing is duplicated
  291. static jobs = {}
  292. // (TRACKER_DETAILS_PART_EPISODES: the gate sets 1 → one season per step)
  293. static partEpisodes = env('TRACKER_DETAILS_PART_EPISODES') != null ? toNumber(env('TRACKER_DETAILS_PART_EPISODES')) : 300
  294. static 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 = '' } }
  295. static addSum = (sum, r, ms) => {
  296. let o = sum
  297. o.steps = o.steps + 1
  298. o.requests = o.requests + r.requests
  299. o.tvmazeRequests = o.tvmazeRequests + r.tvmazeRequests
  300. o.newSeasons = o.newSeasons + r.newSeasons + r.tvmazeSeasons
  301. o.newEpisodes = o.newEpisodes + r.newEpisodes + r.tvmazeEpisodes
  302. o.posters = o.posters + r.posters
  303. o.ids = o.ids + r.ids
  304. o.ms = o.ms + ms
  305. if (r.error != '') { o.error = r.error }
  306. return o
  307. }
  308. // TMDB's season list → parts of ≤ partEpisodes episodes (a bigger season is a part of its own), ≤ 20 seasons each; which of
  309. // them are really synced (season 0, empty ones) syncShowPart decides
  310. static seasonParts = (d) => {
  311. let parts = []
  312. let cur = []
  313. let n = 0
  314. for (x of listOr(d.seasons)) {
  315. if (x != null && x.season_number != null) {
  316. let c = x.episode_count != null ? x.episode_count : 0
  317. if (cur.length > 0 && (n + c > partEpisodes || cur.length == 20)) {
  318. parts.push(cur)
  319. cur = []
  320. n = 0
  321. }
  322. cur.push(x.season_number)
  323. n = n + c
  324. }
  325. }
  326. if (cur.length > 0) { parts.push(cur) }
  327. return parts
  328. }
  329. // a step's answer: { skipped (nothing to do), done, requests / tvmazeRequests (THIS step's — what the pause counts), adult,
  330. // error ('' = none), retry (a passing failure: no answer, 429, 5xx), sum (the whole title's counts so far: steps, requests,
  331. // cast, newSeasons, newEpisodes, posters, ids, ms) }
  332. static stepOut = () => { return { skipped = false done = false requests = 0 tvmazeRequests = 0 adult = null error = '' retry = false sum = emptySum() } }
  333. // the last step: the title is complete
  334. static markComplete = (showId, sum) => {
  335. let done = showsTable.fetch(showId)
  336. done.detailsAt = now()
  337. if (sum.error != '') { done.detailsError = sum.error }
  338. let ok = showsTable.update(done.id, done) != null
  339. refreshCatalogShow(done.id)
  340. searchTitleChanged(done.id)
  341. return ok
  342. }
  343. // step 1: the details request — the record's fields, the cast; a movie also its ids + poster (done); a series' parts are planned
  344. static firstStep = (show) => {
  345. let out = stepOut()
  346. let t0 = now()
  347. let movie = show.type == 'movie'
  348. out.requests = 1
  349. let d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids,' + (movie ? 'credits' : 'aggregate_credits'))
  350. if (d.failed != null) {
  351. out.error = show.title + ': ' + d.failed
  352. if (d.status == 404) {
  353. show.detailsCheck = 'TMDB 404'
  354. showsTable.update(show.id, show)
  355. out.done = true
  356. } else { out.retry = true }
  357. return out
  358. }
  359. out.adult = adultOf(d)
  360. let x = withDetailsFields(show, d, movie)
  361. if (out.adult == true) {
  362. // never public: the flag, no poster, no seasons, no cast (mission 056)
  363. x.detailsCheck = 'adult'
  364. showsTable.update(x.id, x)
  365. refreshCatalogShow(x.id)
  366. searchTitleChanged(x.id)
  367. out.done = true
  368. return out
  369. }
  370. // tracker#28: the whole cast + the crew, from this same answer
  371. let w = withCredits(x, d, movie)
  372. x = w.show
  373. if (showsTable.update(x.id, x) == null) {
  374. out.error = show.title + ': not updated: ' + showsTable.lastError()
  375. out.retry = true
  376. return out
  377. }
  378. let sum = emptySum()
  379. sum.cast = w.cast
  380. sum.crew = w.crew
  381. sum.people = w.people
  382. if (movie) {
  383. // one request was enough: ids + poster now (syncMovie with this answer)
  384. let r = syncShowWith(x.id, d)
  385. out.requests = r.requests
  386. out.sum = addSum(sum, r, now() - t0)
  387. if (r.error != '') { out.error = r.error }
  388. markComplete(x.id, out.sum)
  389. out.done = true
  390. return out
  391. }
  392. sum.steps = 1
  393. sum.requests = 1
  394. sum.ms = now() - t0
  395. // the next steps need the details, not the credits (a long series' aggregate_credits are ~1 MB, copied on every step)
  396. let dd = d
  397. dd.aggregate_credits = null
  398. jobs[x.id] = { d = dd parts = seasonParts(d) pos = 0 sum = sum }
  399. out.sum = sum
  400. return out
  401. }
  402. // ONE step of completing this title (by our id) — called until `done` (the page's face, the repair job)
  403. static completeStep = (showId) => {
  404. let show = showsTable.fetch(showId)
  405. if (!needsDetails(show)) {
  406. jobs[showId] = null
  407. let out = stepOut()
  408. out.skipped = true
  409. out.done = true
  410. return out
  411. }
  412. let job = jobs[showId]
  413. if (job == null) { return firstStep(show) }
  414. let t0 = now()
  415. let out = stepOut()
  416. let last = job.pos >= job.parts.length
  417. let r = syncShowPart(showId, job.d, { seasons = last ? [] : job.parts[job.pos] finish = last })
  418. out.requests = r.requests
  419. out.tvmazeRequests = r.tvmazeRequests
  420. if (r.error != '') { out.error = r.error }
  421. let j = job
  422. j.sum = addSum(j.sum, r, now() - t0)
  423. j.pos = j.pos + 1
  424. out.sum = j.sum
  425. if (!last) {
  426. jobs[showId] = j
  427. return out
  428. }
  429. jobs[showId] = null
  430. markComplete(showId, j.sum)
  431. out.done = true
  432. return out
  433. }
  434. // the line every completed title logs
  435. static completeLine = (title, sum) => {
  436. return '"' + title + '" steps=' + sum.steps + ' requests=' + sum.requests + ' tvmazeRequests=' + sum.tvmazeRequests + ' cast=' + sum.cast + ' newSeasons=' + sum.newSeasons
  437. + ' newEpisodes=' + sum.newEpisodes + ' posters=' + sum.posters + ' ids=' + sum.ids + ' ms=' + sum.ms + ' crew=' + sum.crew + ' people=' + sum.people + (sum.error != '' ? ' error: ' + sum.error : '')
  438. }
  439. // flush shows/seasons/episodes + people (new cast members)
  440. static persistDetails = () => {
  441. persistSync()
  442. personsTable.persist()
  443. return true
  444. }
  445. // the credits job touches only shows + people: the episodes' index files (~16 MB on the live data) are not rewritten
  446. static persistCredits = () => {
  447. showsTable.persist()
  448. personsTable.persist()
  449. return true
  450. }
  451. // ---- THE CREDITS JOB (tracker#28, project.hl `creditsTick`): every public title that has no credits yet, once --------------
  452. // (the incomplete ones get theirs from completeStep; adult and unknown-flag titles are never asked — not public)
  453. static needsCredits = (s) => { return s != null && s.tmdbId != null && s.adult == false && s.creditsAt == null && s.creditsCheck == null && !isIncomplete(s) }
  454. // in table order, read once when the job starts (a restart goes on with what is left)
  455. static creditsQueue = () => {
  456. let out = []
  457. for (s of showsTable.find(null, null)) { if (needsCredits(s)) { out.push(s.id) } }
  458. return out
  459. }
  460. // ONE title: one request (details + credits / aggregate_credits) → its cast + crew. Answers { skipped, requests, cast, crew,
  461. // people, ms, error, retry (no answer, 429, 5xx: ask again later) }. TMDB 404 / adult → `creditsCheck`, never asked again.
  462. static creditsStep = (showId) => {
  463. let out = { skipped = false requests = 0 cast = 0 crew = 0 people = 0 ms = 0 error = '' retry = false }
  464. let t0 = now()
  465. let show = showsTable.fetch(showId)
  466. if (!needsCredits(show)) { out.skipped = true return out }
  467. let movie = show.type == 'movie'
  468. out.requests = 1
  469. let d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=' + (movie ? 'credits' : 'aggregate_credits'))
  470. if (d.failed != null) {
  471. out.error = show.title + ': ' + d.failed
  472. if (d.status == 404) {
  473. show.creditsCheck = 'TMDB 404'
  474. showsTable.update(show.id, show)
  475. } else { out.retry = true }
  476. return out
  477. }
  478. if (adultOf(d) == true) {
  479. show.creditsCheck = 'adult'
  480. showsTable.update(show.id, show)
  481. return out
  482. }
  483. let w = withCredits(show, d, movie)
  484. if (showsTable.update(show.id, w.show) == null) {
  485. out.error = show.title + ': credits not stored: ' + showsTable.lastError()
  486. out.retry = true
  487. return out
  488. }
  489. out.cast = w.cast
  490. out.crew = w.crew
  491. out.people = w.people
  492. out.ms = now() - t0
  493. return out
  494. }

Branches

Latest commits

  • f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • 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