gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitdc40d859dc40d859tracker#31 (mission 026): duplicate titles merged — the 68 type+tmdbId pairs held by 157 records were the old tracker's (all migrated); merge.hl repair job (own clock, before the TMDB jobs) keeps one keeper per title (follows/watches > old short id > oldest), moves follows, watches, seasons, cast, credits, timelines, tombstones the rest (mergedInto, never deleted), slugs + short ids 301 to the keeper; stray seasons merged into their listed twin (Reacher S3 watches) or linked when watched; search import re-checks before its put; deploy.sh waits up to 90 s for 200; real copy 68 -> 0 dup ids, az5b2 follows/watches equal; gates 342/0, 32/0, 52/0mredc40d859/details.hl

28.0 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. // GUESTS ARE NOT PERSON RECORDS (mission 062, memory: 160k people = +3.3 GB RSS at boot): a guest entry is
  36. // { person (only when we have them already, else null), tmdbId, actor, character, profile (TMDB's profile_path), episodes,
  37. // guest = true } — the page links it to `/person/tmdb/<tmdbId>?show=<show id>`, which creates the person on the first open
  38. // (people.hl guestPersonId). The main cast and the crew are linked/created at once as before.
  39. // crew [{ person, name, job, episodes }] job = creator (a series' `created_by`) | director (Director) | writer (Writer) |
  40. // screenplay (Screenplay) | story (Story) | composer (Original Music Composer, Composer, Music) — one entry per person and
  41. // job, a series' by that job's episode count (most first), a movie's in TMDB's order; at most `crewMax` per job.
  42. // `creditsAt` (ms) = the credits are stored (by any path); `creditsCheck` = why the credits job gave up (TMDB 404, adult).
  43. // Every person is linked (people.hl castPersonId: the one we have by TMDB id, else a NEW minimal person — slug, search entry,
  44. // this one credit; their page fills on the first visit). WHO STORES THEM: the details step below (incomplete titles), the daily
  45. // sync and the search import (tmdbsync.hl asks for the credits in the details request it makes anyway → `applyCredits`), and
  46. // the CREDITS JOB (project.hl `creditsTick`, `creditsStep` here) for every other public title once — one request per title.
  47. import { now } from 'hl:time'
  48. import { env } from 'hl:proc'
  49. import { showsTable, personsTable, kindOfTitle } from './shows.hl'
  50. import { tmdbGet, textOr, adultOf, syncShowWith, syncShowPart, persistSync } from './tmdbsync.hl'
  51. import { searchTitleChanged } from './search.hl'
  52. import { refreshCatalogShow } from './catalog.hl'
  53. import { castPersonId, castPeopleCount, genreIdsOfTmdb, personIdByTmdb } from './people.hl'
  54. // how many of TMDB's cast a title keeps (see the top; TRACKER_CAST_MAX) and how many people per crew job
  55. static castMax = env('TRACKER_CAST_MAX') != null ? toNumber(env('TRACKER_CAST_MAX')) : 300
  56. static crewMax = 30
  57. static listOr = (&v) => { return v == null ? [] : v }
  58. // INCOMPLETE = a filmography title (`minimal`) or an import whose sync never finished (`imported`, no `tmdbSync`), not
  59. // completed (`detailsAt`) and not given up on (`detailsCheck`) — or a movie with a TV answer's leftovers (below)
  60. static isIncomplete = (&s) => {
  61. return s != null && s.tmdbId != null && s.detailsCheck == null
  62. && ((s.detailsAt == null && (s.minimal == true || (s.imported != null && s.tmdbSync == null))) || hasTvLeftovers(s))
  63. }
  64. // mission 025 (report 021's "wrong TMDB id"): the #9 sync once asked TMDB for every followed title as `/tv/<tmdbId>` — a movie's
  65. // id is ANOTHER title there (fixed in mission 006: movies go to /movie/) and the TV title's overview, status and season/episode
  66. // counts were stored on the movie. On the real data only Star Trek: First Contact: its tmdbId 199 IS the movie (/movie/199),
  67. // tmdbSummary was TV 199's ("Kabuhayang Swak na Swak …"), status 'Ended', seasonsCount/episodesCount 0. The movie path never
  68. // writes the counts, so a movie that has them is such a record: the repair asks /movie/<id> again (withDetailsFields: overview →
  69. // tmdbSummary, status, …) and firstStep drops the counts — repaired once, then it no longer matches.
  70. static hasTvLeftovers = (&s) => { return s.type == 'movie' && (s.seasonsCount != null || s.episodesCount != null) }
  71. // what the show page and the repair complete: an incomplete title that is not adult (mission 054/056: never public)
  72. static needsDetails = (&s) => { return isIncomplete(s) && s.adult != true && s.mergedInto == null }
  73. // 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)
  74. static detailsRepairQueue = () => {
  75. let out = []
  76. for (s of showsTable.find(null, null)) { if (needsDetails(s)) { out.push(s.id) } }
  77. return out
  78. }
  79. // a series' roles ([{ character, episode_count }]) as one text: "Mother / Lamia". tracker#28 (real data): TMDB's characters are
  80. // themselves " / "-joined and repeat across seasons ("Data / Lore", "Data", "Yvette Picard (uncredited)") — split, " (uncredited)"
  81. // dropped, each name once, at most `rolesMax` (a voice actor of The Simpsons has 30+), then " / …"
  82. static rolesMax = 4
  83. static rolesText = (&roles) => {
  84. let names = []
  85. let more = false
  86. for (r of listOr(roles)) {
  87. let c = r != null ? textOr(r.character) : null
  88. if (c != null) {
  89. for (part of c.split(' / ')) {
  90. let n = part.replaceAll(' (uncredited)', '').trim()
  91. if (n != '' && !names.includes(n)) { if (names.length < rolesMax) { names.push(n) } else { more = true } }
  92. }
  93. }
  94. }
  95. return names.join(' / ') + (more ? ' / …' : '')
  96. }
  97. // a series' episodes of one person: TMDB's total_episode_count, else the sum of the roles' / jobs' counts
  98. static episodesOf = (&total, &parts) => {
  99. if (total != null && hlTypeName(total) == 'Number') { return total }
  100. let n = 0
  101. for (r of listOr(parts)) { if (r != null && r.episode_count != null && hlTypeName(r.episode_count) == 'Number') { n = n + r.episode_count } }
  102. return n
  103. }
  104. static personOk = (&c) => { return c != null && c.id != null && hlTypeName(c.id) == 'Number' && textOr(c.name) != null && c.adult != true }
  105. // TMDB's cast → [{ tmdbId, name, character, gender, episodes }], TMDB's order, at most castMax, adult people left out
  106. static castOf = (&d, &movie) => {
  107. let src = movie ? (d.credits != null ? d.credits.cast : null) : (d.aggregate_credits != null ? d.aggregate_credits.cast : null)
  108. let out = []
  109. for (c of listOr(src)) {
  110. if (out.length < castMax && personOk(c)) {
  111. let role = movie ? textOr(c.character) : rolesText(c.roles)
  112. out.push({ tmdbId = c.id name = c.name character = role != null ? role : '' gender = c.gender profile = textOr(c.profile_path) episodes = movie ? null : episodesOf(c.total_episode_count, c.roles) })
  113. }
  114. }
  115. return out
  116. }
  117. // 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
  118. static mainMinOf = (&d) => {
  119. let n = d.number_of_episodes != null && hlTypeName(d.number_of_episodes) == 'Number' ? d.number_of_episodes : 0
  120. let half = (n - n % 2) / 2 + n % 2
  121. if (half > 10) { return 10 }
  122. return half < 1 ? 1 : half
  123. }
  124. // the crew jobs we show: TMDB job → ours (the page's labels: components/show.hl crewLabels)
  125. static crewJobOf = (&job) => {
  126. if (job == 'Director') { return 'director' }
  127. if (job == 'Writer') { return 'writer' }
  128. if (job == 'Screenplay') { return 'screenplay' }
  129. if (job == 'Story') { return 'story' }
  130. if (job == 'Original Music Composer' || job == 'Composer' || job == 'Music') { return 'composer' }
  131. return null
  132. }
  133. static crewJobs = ['creator', 'director', 'writer', 'screenplay', 'story', 'composer']
  134. // keeps a job's list ordered by episodes (most first, equal ones in TMDB's order), at most crewMax (hand-written: no sort())
  135. static insertByEpisodes = (&list, &item) => {
  136. let out = []
  137. let inserted = false
  138. for (x of list) {
  139. if (!inserted && item.episodes > x.episodes) { out.push(item) inserted = true }
  140. if (out.length < crewMax) { out.push(x) }
  141. }
  142. if (!inserted && out.length < crewMax) { out.push(item) }
  143. return out
  144. }
  145. // TMDB's crew (+ a series' created_by) → [{ tmdbId, name, job, gender, episodes }], grouped by job in `crewJobs` order, one
  146. // entry per person and job
  147. static crewOf = (&d, &movie) => {
  148. let byJob = {}
  149. let seen = {}
  150. for (j of crewJobs) { byJob[j] = [] }
  151. if (!movie) {
  152. for (c of listOr(d.created_by)) {
  153. if (personOk(c) && seen['creator:' + c.id] != true && byJob['creator'].length < crewMax) {
  154. seen['creator:' + c.id] = true
  155. let l = byJob['creator']
  156. l.push({ tmdbId = c.id name = c.name job = 'creator' gender = c.gender episodes = 0 })
  157. byJob['creator'] = l
  158. }
  159. }
  160. }
  161. let src = movie ? (d.credits != null ? d.credits.crew : null) : (d.aggregate_credits != null ? d.aggregate_credits.crew : null)
  162. for (c of listOr(src)) {
  163. if (personOk(c)) {
  164. // a movie's crew entry has one `job`; a series' has `jobs` [{ job, episode_count }]
  165. let jobs = movie ? [{ job = c.job episode_count = 0 }] : listOr(c.jobs)
  166. for (jb of jobs) {
  167. let ours = jb != null ? crewJobOf(jb.job) : null
  168. if (ours != null && seen[ours + ':' + c.id] != true) {
  169. seen[ours + ':' + c.id] = true
  170. let n = movie ? 0 : episodesOf(jb.episode_count, null)
  171. byJob[ours] = insertByEpisodes(byJob[ours], { tmdbId = c.id name = c.name job = ours gender = c.gender episodes = n })
  172. }
  173. }
  174. }
  175. }
  176. let out = []
  177. for (j of crewJobs) { for (c of byJob[j]) { out.push(c) } }
  178. return out
  179. }
  180. // the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not list.
  181. // `mainMin` = a series' main-cast episode count (mainMinOf), 0 for a movie (no guests)
  182. static mergedCast = (&show, &tmdbCast, &mainMin) => {
  183. let out = []
  184. let have = {}
  185. let showKey = show.id
  186. let seenTmdb = {}
  187. for (c of tmdbCast) {
  188. let guest = c.episodes != null && c.episodes < mainMin
  189. // a guest: linked only when we have them, never created here (mission 062)
  190. let pid = guest ? personIdByTmdb(c.tmdbId) : castPersonId(c, showKey)
  191. if (pid != null && have[pid] != true) {
  192. have[pid] = true
  193. seenTmdb['' + c.tmdbId] = true
  194. out.push({ person = pid tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = guest })
  195. } else if (pid == null && guest && seenTmdb['' + c.tmdbId] != true) {
  196. seenTmdb['' + c.tmdbId] = true
  197. out.push({ person = null tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = true })
  198. }
  199. }
  200. for (c of listOr(show.cast)) {
  201. if (c != null && c.person != null && have[c.person] != true && (c.tmdbId == null || seenTmdb['' + c.tmdbId] != true)) {
  202. have[c.person] = true
  203. out.push(c)
  204. }
  205. }
  206. return out
  207. }
  208. static crewRoleOf = (&job) => {
  209. if (job == 'creator') { return 'Creator' }
  210. if (job == 'director') { return 'Director' }
  211. if (job == 'writer') { return 'Writer' }
  212. if (job == 'screenplay') { return 'Screenplay' }
  213. if (job == 'story') { return 'Story' }
  214. return 'Music'
  215. }
  216. // 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
  217. static linkedCrew = (&show, &tmdbCrew) => {
  218. let out = []
  219. let showKey = show.id
  220. for (c of tmdbCrew) {
  221. let pid = castPersonId({ tmdbId = c.tmdbId name = c.name character = crewRoleOf(c.job) gender = c.gender }, showKey)
  222. if (pid != null) { out.push({ person = pid name = c.name job = c.job episodes = c.episodes }) }
  223. }
  224. return out
  225. }
  226. // the answer carries credits (a details request with `credits` / `aggregate_credits` appended)
  227. static hasCredits = (&d, &movie) => { return d != null && (movie ? d.credits != null : d.aggregate_credits != null) }
  228. // cast + crew of this record from a details answer → { show (the record with cast, crew, creditsAt), cast, crew, people (new) }
  229. static withCredits = (show, &d, &movie) => {
  230. let before = castPeopleCount()
  231. let tmdbCast = castOf(d, movie)
  232. let x = show
  233. x.cast = mergedCast(show, tmdbCast, movie ? 0 : mainMinOf(d))
  234. x.crew = linkedCrew(show, crewOf(d, movie))
  235. x.creditsAt = now()
  236. return { show = x cast = tmdbCast.length crew = x.crew.length people = castPeopleCount() - before }
  237. }
  238. // THE RECORD'S OWN FIELDS from a details answer (tracker#26 completion; tracker#18 the daily sync too — creator: "some shows changed
  239. // descriptions and titles and that did not update"): title (a series' `name`, a movie's `title`), TMDB's overview → `tmdbSummary`,
  240. // homepage, tagline, status, genres (by TMDB id), adult; type / release / year / language only when we have none. A TMDB value
  241. // that is empty never overwrites ours. `summary` is the creator's OWN text — never written here (the page shows summary >
  242. // tmdbSummary > tvmazeSummary, shows.hl summaryOf). The slug (`urlSegment`) never changes with the title.
  243. // mission 070 (conductor): the sync never DESTROYS what the old tracker's migration brought — before TMDB's value replaces a
  244. // migrated record's title / genres / homepage / tagline for the FIRST time, the old one is kept in `migratedTitle` /
  245. // `migratedGenres` / `migratedHomepage` / `migratedTagline` (kept, shown nowhere; set once, a later rename leaves it). A record is
  246. // migrated when its `oldId` is the old tracker's (not `tmdb-…`: search import, filmography fill). `status`, counts, ids and the
  247. // poster are TMDB's state, written by the sync since #9 — not kept.
  248. static isMigratedRecord = (&show) => { return show.oldId != null && ('' + show.oldId).slice(0, 5) != 'tmdb-' }
  249. static sameIdList = (&a, &b) => {
  250. let x = listOr(a)
  251. let y = listOr(b)
  252. if (x.length != y.length) { return false }
  253. let i = 0
  254. while (i < x.length) { if ('' + x[i] != '' + y[i]) { return false } i = i + 1 }
  255. return true
  256. }
  257. static withDetailsFields = (show, &d, &movie) => {
  258. let x = show
  259. let migrated = isMigratedRecord(show)
  260. let adult = adultOf(d)
  261. if (adult != null) { x.adult = adult }
  262. let title = textOr(movie ? d.title : d.name)
  263. if (title != null) {
  264. if (migrated && x.migratedTitle == null && textOr(x.title) != null && x.title != title) { x.migratedTitle = x.title }
  265. x.title = title
  266. }
  267. if (textOr(d.overview) != null) { x.tmdbSummary = d.overview }
  268. if (textOr(d.homepage) != null) {
  269. if (migrated && x.migratedHomepage == null && textOr(x.homepage) != null && x.homepage != d.homepage) { x.migratedHomepage = x.homepage }
  270. x.homepage = d.homepage
  271. }
  272. if (textOr(d.tagline) != null) {
  273. if (migrated && x.migratedTagline == null && textOr(x.tagline) != null && x.tagline != d.tagline) { x.migratedTagline = x.tagline }
  274. x.tagline = d.tagline
  275. }
  276. if (textOr(d.status) != null) { x.status = d.status }
  277. let tmdbGenreIds = []
  278. for (g of listOr(d.genres)) { if (g != null && g.id != null) { tmdbGenreIds.push(g.id) } }
  279. let genres = genreIdsOfTmdb(tmdbGenreIds)
  280. if (genres.length > 0) {
  281. if (migrated && x.migratedGenres == null && listOr(x.genres).length > 0 && !sameIdList(x.genres, genres)) { x.migratedGenres = x.genres }
  282. x.genres = genres
  283. }
  284. if (textOr(x.type) == null) { x.type = movie ? 'movie' : 'series' }
  285. let release = textOr(movie ? d.release_date : d.first_air_date)
  286. if (textOr(x.release) == null && release != null) {
  287. x.release = release
  288. if (release.length >= 4) { x.year = toNumber(release.slice(0, 4)) }
  289. }
  290. if (textOr(x.language) == null && textOr(d.original_language) != null) { x.language = d.original_language }
  291. // tracker#21 (merge, mission 070): TMDB's TV type + the kind from the genres just stored (the delta's light step and the
  292. // completion of #26 store it too, not only syncShow / the kind backfill)
  293. if (!movie && textOr(d.type) != null) {
  294. x.tmdbType = d.type
  295. x.kind = kindOfTitle(d.type, x.genres)
  296. }
  297. return x
  298. }
  299. // THE DAILY SYNC (project.hl syncTick, tools/sync-tmdb.hl; tracker#18): after tmdbsync.hl `syncShow` (seasons, episodes, poster,
  300. // ids, TVmaze) the record's own fields (withDetailsFields) and its cast + crew (#28) from the SAME details answer (`res.details`)
  301. // — no extra request. Answers { renamed (the title changed: the search re-indexes it), cast, crew, people, ms, error }
  302. static applySynced = (&showId, &d) => {
  303. let out = { renamed = false cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  304. let t0 = now()
  305. let show = showsTable.fetch(showId)
  306. if (show == null || d == null) { return out }
  307. let movie = show.type == 'movie'
  308. let before = show.title
  309. let x = withDetailsFields(show, d, movie)
  310. out.renamed = x.title != before
  311. if (x.adult != true && hasCredits(d, movie)) {
  312. let w = withCredits(x, d, movie)
  313. x = w.show
  314. out.cast = w.cast
  315. out.crew = w.crew
  316. out.people = w.people
  317. }
  318. if (showsTable.update(x.id, x) == null) { out.error = x.title + ': record not stored: ' + showsTable.lastError() }
  319. out.ms = now() - t0
  320. return out
  321. }
  322. // the search import: its details answer (tmdbsync.hl `res.details`) → the title's cast + crew. Nothing
  323. // for an adult title or an answer without credits. Answers { cast, crew, people, ms, error }
  324. static applyCredits = (&showId, &d) => {
  325. let out = { cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  326. let t0 = now()
  327. let show = showsTable.fetch(showId)
  328. if (show == null || show.adult == true || adultOf(d) == true || !hasCredits(d, show.type == 'movie')) { return out }
  329. let w = withCredits(show, d, show.type == 'movie')
  330. if (showsTable.update(show.id, w.show) == null) { out.error = show.title + ': credits not stored: ' + showsTable.lastError() return out }
  331. out.cast = w.cast
  332. out.crew = w.crew
  333. out.people = w.people
  334. out.ms = now() - t0
  335. return out
  336. }
  337. // 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
  338. // request at a time, every page waited): step 1 = the details request (fields + cast); then one step per PART of its seasons
  339. // (≤ `partEpisodes` episodes, ≤ 20 seasons = one TMDB request — tmdbsync.hl syncShowPart); the last step = ids, TVmaze, poster,
  340. // `detailsAt`. A movie is one step. Between two steps every other request is served.
  341. // show id → { d (TMDB's answer of step 1), parts ([[season numbers]]), pos, sum } while a series is under way — in memory: a
  342. // restart begins again with the details request; what is stored by then is matched by tmdbId, nothing is duplicated
  343. static jobs = {}
  344. // (TRACKER_DETAILS_PART_EPISODES: the gate sets 1 → one season per step)
  345. static partEpisodes = env('TRACKER_DETAILS_PART_EPISODES') != null ? toNumber(env('TRACKER_DETAILS_PART_EPISODES')) : 300
  346. 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 = '' } }
  347. static addSum = (sum, &r, &ms) => {
  348. let o = sum
  349. o.steps = o.steps + 1
  350. o.requests = o.requests + r.requests
  351. o.tvmazeRequests = o.tvmazeRequests + r.tvmazeRequests
  352. o.newSeasons = o.newSeasons + r.newSeasons + r.tvmazeSeasons
  353. o.newEpisodes = o.newEpisodes + r.newEpisodes + r.tvmazeEpisodes
  354. o.posters = o.posters + r.posters
  355. o.ids = o.ids + r.ids
  356. o.ms = o.ms + ms
  357. if (r.error != '') { o.error = r.error }
  358. return o
  359. }
  360. // TMDB's season list → parts of ≤ partEpisodes episodes (a bigger season is a part of its own), ≤ 20 seasons each; which of
  361. // them are really synced (season 0, empty ones) syncShowPart decides
  362. static seasonParts = (&d) => {
  363. let parts = []
  364. let cur = []
  365. let n = 0
  366. for (x of listOr(d.seasons)) {
  367. if (x != null && x.season_number != null) {
  368. let c = x.episode_count != null ? x.episode_count : 0
  369. if (cur.length > 0 && (n + c > partEpisodes || cur.length == 20)) {
  370. parts.push(cur)
  371. cur = []
  372. n = 0
  373. }
  374. cur.push(x.season_number)
  375. n = n + c
  376. }
  377. }
  378. if (cur.length > 0) { parts.push(cur) }
  379. return parts
  380. }
  381. // a step's answer: { skipped (nothing to do), done, requests / tvmazeRequests (THIS step's — what the pause counts), adult,
  382. // error ('' = none), retry (a passing failure: no answer, 429, 5xx), sum (the whole title's counts so far: steps, requests,
  383. // cast, newSeasons, newEpisodes, posters, ids, ms) }
  384. static stepOut = () => { return { skipped = false done = false requests = 0 tvmazeRequests = 0 adult = null error = '' retry = false sum = emptySum() } }
  385. // the last step: the title is complete
  386. static markComplete = (&showId, &sum) => {
  387. let done = showsTable.fetch(showId)
  388. done.detailsAt = now()
  389. if (sum.error != '') { done.detailsError = sum.error }
  390. let ok = showsTable.update(done.id, done) != null
  391. refreshCatalogShow(done.id)
  392. searchTitleChanged(done.id)
  393. return ok
  394. }
  395. // step 1: the details request — the record's fields, the cast; a movie also its ids + poster (done); a series' parts are planned
  396. static firstStep = (show) => {
  397. let out = stepOut()
  398. let t0 = now()
  399. let movie = show.type == 'movie'
  400. out.requests = 1
  401. let d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids,' + (movie ? 'credits' : 'aggregate_credits'))
  402. if (d.failed != null) {
  403. out.error = show.title + ': ' + d.failed
  404. if (d.status == 404) {
  405. show.detailsCheck = 'TMDB 404'
  406. showsTable.update(show.id, show)
  407. out.done = true
  408. } else { out.retry = true }
  409. return out
  410. }
  411. out.adult = adultOf(d)
  412. let x = withDetailsFields(show, d, movie)
  413. // mission 025: a movie has no season/episode counts (hasTvLeftovers)
  414. if (movie) { x.seasonsCount = null x.episodesCount = null }
  415. if (out.adult == true) {
  416. // never public: the flag, no poster, no seasons, no cast (mission 056)
  417. x.detailsCheck = 'adult'
  418. showsTable.update(x.id, x)
  419. refreshCatalogShow(x.id)
  420. searchTitleChanged(x.id)
  421. out.done = true
  422. return out
  423. }
  424. // tracker#28: the whole cast + the crew, from this same answer
  425. let w = withCredits(x, d, movie)
  426. x = w.show
  427. if (showsTable.update(x.id, x) == null) {
  428. out.error = show.title + ': not updated: ' + showsTable.lastError()
  429. out.retry = true
  430. return out
  431. }
  432. let sum = emptySum()
  433. sum.cast = w.cast
  434. sum.crew = w.crew
  435. sum.people = w.people
  436. if (movie) {
  437. // one request was enough: ids + poster now (syncMovie with this answer)
  438. let r = syncShowWith(x.id, d)
  439. out.requests = r.requests
  440. out.sum = addSum(sum, r, now() - t0)
  441. if (r.error != '') { out.error = r.error }
  442. markComplete(x.id, out.sum)
  443. out.done = true
  444. return out
  445. }
  446. sum.steps = 1
  447. sum.requests = 1
  448. sum.ms = now() - t0
  449. // the next steps need the details, not the credits (a long series' aggregate_credits are ~1 MB, copied on every step)
  450. let dd = d
  451. dd.aggregate_credits = null
  452. jobs[x.id] = { d = dd parts = seasonParts(d) pos = 0 sum = sum }
  453. out.sum = sum
  454. return out
  455. }
  456. // ONE step of completing this title (by our id) — called until `done` (the page's face, the repair job)
  457. static completeStep = (&showId) => {
  458. let show = showsTable.fetch(showId)
  459. if (!needsDetails(show)) {
  460. jobs[showId] = null
  461. let out = stepOut()
  462. out.skipped = true
  463. out.done = true
  464. return out
  465. }
  466. let job = jobs[showId]
  467. if (job == null) { return firstStep(show) }
  468. let t0 = now()
  469. let out = stepOut()
  470. let last = job.pos >= job.parts.length
  471. let r = syncShowPart(showId, job.d, { seasons = last ? [] : job.parts[job.pos] finish = last })
  472. out.requests = r.requests
  473. out.tvmazeRequests = r.tvmazeRequests
  474. if (r.error != '') { out.error = r.error }
  475. let j = job
  476. j.sum = addSum(j.sum, r, now() - t0)
  477. j.pos = j.pos + 1
  478. out.sum = j.sum
  479. if (!last) {
  480. jobs[showId] = j
  481. return out
  482. }
  483. jobs[showId] = null
  484. markComplete(showId, j.sum)
  485. out.done = true
  486. return out
  487. }
  488. // the line every completed title logs
  489. static completeLine = (&title, &sum) => {
  490. return '"' + title + '" steps=' + sum.steps + ' requests=' + sum.requests + ' tvmazeRequests=' + sum.tvmazeRequests + ' cast=' + sum.cast + ' newSeasons=' + sum.newSeasons
  491. + ' newEpisodes=' + sum.newEpisodes + ' posters=' + sum.posters + ' ids=' + sum.ids + ' ms=' + sum.ms + ' crew=' + sum.crew + ' people=' + sum.people + (sum.error != '' ? ' error: ' + sum.error : '')
  492. }
  493. // flush shows/seasons/episodes + people (new cast members)
  494. static persistDetails = () => {
  495. persistSync()
  496. personsTable.persist()
  497. return true
  498. }
  499. // the credits job touches only shows + people: the episodes' index files (~16 MB on the live data) are not rewritten
  500. static persistCredits = () => {
  501. showsTable.persist()
  502. personsTable.persist()
  503. return true
  504. }
  505. // ---- THE CREDITS JOB (tracker#28, project.hl `creditsTick`): every public title that has no credits yet, once --------------
  506. // (the incomplete ones get theirs from completeStep; adult and unknown-flag titles are never asked — not public)
  507. static needsCredits = (&s) => { return s != null && s.tmdbId != null && s.adult == false && s.creditsAt == null && s.creditsCheck == null && !isIncomplete(s) && s.mergedInto == null }
  508. // in table order, read once when the job starts (a restart goes on with what is left)
  509. static creditsQueue = () => {
  510. let out = []
  511. for (s of showsTable.find(null, null)) { if (needsCredits(s)) { out.push(s.id) } }
  512. return out
  513. }
  514. // ONE title: one request (details + credits / aggregate_credits) → its cast + crew. Answers { skipped, requests, cast, crew,
  515. // people, ms, error, retry (no answer, 429, 5xx: ask again later) }. TMDB 404 / adult → `creditsCheck`, never asked again.
  516. static creditsStep = (&showId) => {
  517. let out = { skipped = false requests = 0 cast = 0 crew = 0 people = 0 ms = 0 error = '' retry = false }
  518. let t0 = now()
  519. let show = showsTable.fetch(showId)
  520. if (!needsCredits(show)) { out.skipped = true return out }
  521. let movie = show.type == 'movie'
  522. out.requests = 1
  523. let d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=' + (movie ? 'credits' : 'aggregate_credits'))
  524. if (d.failed != null) {
  525. out.error = show.title + ': ' + d.failed
  526. if (d.status == 404) {
  527. show.creditsCheck = 'TMDB 404'
  528. showsTable.update(show.id, show)
  529. } else { out.retry = true }
  530. return out
  531. }
  532. if (adultOf(d) == true) {
  533. show.creditsCheck = 'adult'
  534. showsTable.update(show.id, show)
  535. return out
  536. }
  537. let w = withCredits(show, d, movie)
  538. if (showsTable.update(show.id, w.show) == null) {
  539. out.error = show.title + ': credits not stored: ' + showsTable.lastError()
  540. out.retry = true
  541. return out
  542. }
  543. out.cast = w.cast
  544. out.crew = w.crew
  545. out.people = w.people
  546. out.ms = now() - t0
  547. return out
  548. }

Branches

Latest commits

  • dc40d859tracker#31 (mission 026): duplicate titles merged — the 68 type+tmdbId pairs held by 157 records were the old tracker's (all migrated); merge.hl repair job (own clock, before the TMDB jobs) keeps one keeper per title (follows/watches > old short id > oldest), moves follows, watches, seasons, cast, credits, timelines, tombstones the rest (mergedInto, never deleted), slugs + short ids 301 to the keeper; stray seasons merged into their listed twin (Reacher S3 watches) or linked when watched; search import re-checks before its put; deploy.sh waits up to 90 s for 200; real copy 68 -> 0 dup ids, az5b2 follows/watches equal; gates 342/0, 32/0, 52/0mre
  • 2667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre
  • 3909810dantcolony#40: mission references in README/STATUS/docs point to the moved missionsmre
  • e63b1d28antcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 1cda451dtracker: Hybriel master 190aa11d (#127 both shapes, GC correctness fc838894) — conductor adopts despite /my/series 2.4x after jobs (memory 8.0 → 1.7 GB boot); see reports/071mre
  • c1fa2f2etracker (mission 071): Hybriel master 190aa11d measured on the real copy vs the live binary 8590df63 — NOT adopted (after the first-start jobs /my/series 2.4x slower, /series 1.6x, RSS swings 7.4-12.2 GB; fresh it is flat at 1.7-2.2 GB and /my/unwatched faster), vendor stays 8efba065, candidate kept in .scratch/w071/vendor-190aa11d; tests/kinds.mjs: collection seed off (its TMDB request broke check 1 in 1 of 4 runs); tests/realdata-071.sh + realdata-071-bench.mjs + tools/realdata-071-table.py; README + STATUS (numbers, how to repeat); gates 325/0, 32/0, 50/0mre
  • 8081350atracker docs (mission 070): README (summary, Config HL_GC_BYTES — kept at Hybriel's default, the 256 MiB setting is taken out of docker-compose.yml again: the jobs grew to 12+ GB with it too, see STATUS), Test (three gates), Deploy (first start ~50 min: kinds then seed, restart once after collections done, memory numbers), Vendored Hybriel 8efba065 + #48 audit, Files; STATUS mission 070 entry (merges, migrated counts, lambda audit, gates, RSS old vs new, how to repeat, open points); docs/kinds.md + docs/franchises.md job order; tests/realdata-070-*.sh, tools/count-migrated.hl, tools/ref-params.py, tools/lambda-audit.pymre
  • 1ad19c8ctracker: re-vendor Hybriel master 8efba065 (#126 GC by bytes, #48 lambda parameters copy) (mission 070): bin/hybriel sha256 50361e95…, plugins core crypto data fetch fs http http1 mpackdb proc smtp time web; lambda audit: 13 lambdas change a passed record/list (11 through a local alias), no caller relies on it — unchanged; 319 read-only lambda parameters get & (no copy per call: /my/schedule 2.35 → 0.46 s, /my/unwatched 13.7 → 5.7 s on the real copy); /my/unwatched one merge sort instead of n² inserts; docker-compose HL_GC_BYTES=268435456; deploy.sh runs kinds.mjs + franchises.mjs too (default ports 8700–8710); tests/realdata-070.mjs; gates browser 325/0, kinds 32/0, franchises 50/0mre
  • 46b21389tracker (mission 070, conductor): the sync never destroys migrated data — the one-time summary step MOVES a copied summary to migratedSummary (marker summaries-moved.txt) instead of clearing it; a migrated record's first title/genres/homepage/tagline TMDB replaces → migratedTitle/migratedGenres/migratedHomepage/migratedTagline, a migrated season's/episode's title/summary → migratedTitle/migratedSummary (set once); tests/peek-shows.hl prints them; gate 325/0mre
  • 749019b0Merge t19 (tracker#19 franchises + timelines) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs/faketmdb.mjs, both sides kept; franchise/timeline pages get #20's typed heading (Franchise | …, Timeline | …), their title links via titlePath (/movies|/series|/shows); the collection seed waits for repair, kinds and credits too; franchises.mjs URLs + 2 new checks; gates browser 323/0, kinds 32/0, franchises 50/0mre
  • daf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mre
  • 20e09d89Merge t18 (tracker#18 delta sync) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs, both sides kept; pageShowOf summary = summaryOfmre
  • 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
  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • 0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.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
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, 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