gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit718bfb89718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre718bfb89/lib/sync.hl

25.7 KB

  1. // lib/sync.hl — THE TMDB SYNC OF ONE TITLE (tracker.worldapi.org#9; tmdbsync.hl before mission 028 — its requests are in tmdb.hl,
  2. // its small helpers in sync-helpers.hl, the backfills in backfill.hl): for every show SOMEONE follows, fetch the show's
  3. // details, seasons and episodes from TMDB and bring storage/mpackdb/ up to date, plus the show's poster.
  4. // Used by BOTH runners: the daily run inside the app (jobs.hl `syncTick`, one show per step) and the
  5. // command-line tool (tools/sync-tmdb.hl). Reference for the API use: the old tracker's
  6. // crates/sync/commands/sync.js (read-only).
  7. //
  8. // GET <TMDB_BASE_URL>/tv/<tmdbId>?append_to_response=external_ids,aggregate_credits the details (status,
  9. // counts, overview, poster_path, seasons[])
  10. // + external_ids (imdb_id, tvdb_id) + the cast/crew
  11. // of every season (tracker#28: the answer goes back
  12. // as `res.details`, the caller stores the credits —
  13. // credits.hl applyCredits; no extra request)
  14. // GET <TMDB_BASE_URL>/tv/<tmdbId>?append_to_response=season/1,season/2… up to 20 seasons with their
  15. // episodes in ONE request
  16. // GET <TMDB_IMAGE_URL>/w342<poster_path> the poster → storage/mpackdb/posters/
  17. // Authorization: Bearer $TMDB_READ_TOKEN
  18. // GET <TVMAZE_BASE_URL>/lookup/shows?imdb=tt… (else ?thetvdb=<id>) the TVmaze id, ONLY when the show
  19. // has none (301 → /shows/<id>, 404 = unknown)
  20. // GET <TVMAZE_BASE_URL>/shows/<tvmzId>?embed=episodes a SERIES on TVmaze with its episodes (#15), see
  21. // below; its summary → `tvmazeSummary` (tracker#18),
  22. // its status → `tvmazeStatus` (tracker#35)
  23. // A MOVIE (`type = 'movie'`, 7814 of the migrated rows, 1 followed): only
  24. // GET <TMDB_BASE_URL>/movie/<tmdbId>?append_to_response=external_ids,credits its imdb id + poster (+ credits); no seasons,
  25. // status, overview (it is no TV show)
  26. //
  27. // EXTERNAL IDS (tracker.worldapi.org#12, the show page's link icons): a MISSING imdbId/tvdbId is filled from TMDB's
  28. // external_ids, a missing tvmzId from TVmaze's lookup — an id the show already has is NEVER overwritten.
  29. // RULES (ticket): new seasons/episodes are ADDED, existing ones UPDATED (title, summary, release) —
  30. // matched by tmdbId, never duplicated; NOTHING is deleted. An episode without a tmdbId (161 migrated ones)
  31. // is matched by its S/E number instead and gets the tmdbId. A season (no tmdbId in the migrated data) is
  32. // matched by (show, seasonNumber). A TMDB value that is empty/null never overwrites a stored one.
  33. // Season 0 ("Specials") is only synced for a show that already has a season 0 (else every followed show
  34. // would suddenly flood /my/unwatched with specials); a TMDB season with no episodes is not created.
  35. //
  36. // TVMAZE MERGE (tracker.worldapi.org#15): AFTER TMDB, a series with a tvmzId gets TVmaze's episode list (one request)
  37. // and TVmaze FILLS GAPS only — matched by season/episode number: a missing episode (and its season) is ADDED, an empty
  38. // title or air date of an existing one is FILLED; a value TMDB gave is never overwritten. A placeholder title
  39. // ("Episode 4", "TBA") counts as empty — and TMDB's own placeholder never overwrites a real title either (else the
  40. // two would flip it every day). When TMDB later lists the episode, the TMDB step adopts it by number (it has no tmdbId)
  41. // and TMDB's values win. TVmaze specials (no episode number) are skipped, season 0 only if the show has one. SAFETY:
  42. // when the two number a show differently (fewer than 80 % of the episodes both know air within a day of each other or
  43. // share the title — `numberingAgrees`), TVmaze is ignored for that show (`tvmazeSkipped`). Summaries are not taken
  44. // (TVmaze's are HTML; the ticket asks for episodes, air dates, titles). The SHOW's TVmaze summary is kept, HTML stripped, as
  45. // `tvmazeSummary` (tracker#18; the page shows summary > tmdbSummary > tvmazeSummary, shows.hl summaryOf).
  46. //
  47. // WHICH TITLES, WHEN (tracker#18): the daily run asks TMDB's and TVmaze's change lists first and syncs only the titles of ours
  48. // that changed — dailysync.hl. THE SHOW RECORD (title, tagline, homepage, status, genres …) is refreshed from the same details
  49. // answer by details.hl `applySynced`.
  50. //
  51. // IDS ARE SELF-ASSIGNED (randomBytes, like watches.hl): hl:mpackdb's own generated @id can repeat within
  52. // one millisecond, which is what made update() lose rows (hybriel#113, fixed upstream, not in the vendored
  53. // build) — a table holding only unique ids is safe to update().
  54. //
  55. // ONE PROCESS PER STORAGE: hl:mpackdb does not coordinate two processes (hybriel#21) — the in-app run uses
  56. // the app's own open tables (imported from shows.hl); the tool only ever runs against a stopped app or a copy.
  57. import { now } from 'hl:time'
  58. import { newId, textOr } from './util.hl'
  59. import { showsTable, seasonsTable, episodesTable, kindOfTitle } from './shows.hl'
  60. import { tmdbGet, numIdOr, externalIdsFor, tvmazeEpisodes, tvmazeShow, syncPoster, adultOf } from './tmdb.hl'
  61. import { isPlaceholderTitle, numberingAgrees, wantedSeasonNumbers, batchesOf, changedText, isMigratedRow } from './sync-helpers.hl'
  62. // Merge TVmaze's episodes of a series into what we have AFTER the TMDB step (gaps only, rules at the top).
  63. // `seasonsByNumber` / `epByNumber` = the show's seasons by number and episodes by '<s>x<e>', as the TMDB step left them.
  64. // Answers { tvmazeRequests, newSeasons, newEpisodes, filledEpisodes, skipped, errors, error, showSeasons }.
  65. static mergeTvmaze = (title, &showKey, tvmzId, seasonsIn, episodesIn, &showSeasonsIn) => {
  66. seasonsByNumber = seasonsIn
  67. epByNumber = episodesIn
  68. out = { tvmazeRequests = 1 newSeasons = 0 newEpisodes = 0 filledEpisodes = 0 skipped = 0 errors = 0 error = '' showSeasons = showSeasonsIn summary = null status = null }
  69. got = tvmazeEpisodes(tvmzId)
  70. if (got.failed != null) { out.errors = 1 out.error = title + ': ' + got.failed return out }
  71. out.summary = got.summary
  72. out.status = got.status
  73. // the numbered episodes TVmaze has in seasons we take (no specials; season 0 only when the show has one)
  74. list = []
  75. for (te of got.list) {
  76. if (numIdOr(te.season) != null && numIdOr(te.number) != null) { list.push(te) }
  77. else if (te.season == 0 && numIdOr(te.number) != null && seasonsByNumber['0'] != null) { list.push(te) }
  78. }
  79. if (!numberingAgrees(epByNumber, list).ok) { out.skipped = 1 return out }
  80. added = {}
  81. addedFirstDate = {}
  82. for (te of list) {
  83. let key = te.season + 'x' + te.number
  84. let e = epByNumber[key]
  85. if (e == null) {
  86. let seasonKey = seasonsByNumber['' + te.season] != null ? seasonsByNumber['' + te.season].id : null
  87. if (seasonKey == null) {
  88. if (added['' + te.season] == null) { added['' + te.season] = [] addedFirstDate['' + te.season] = textOr(te.airdate) seasonsByNumber['' + te.season] = { id = newId() isNew = true } }
  89. seasonKey = seasonsByNumber['' + te.season].id
  90. }
  91. let fresh = { id = newId() episodeNumber = te.number seasonNumber = te.season
  92. title = textOr(te.name) summary = '' release = textOr(te.airdate)
  93. show = showKey season = seasonKey tmdbId = null tvmzId = te.id oldId = 'tvmaze-episode:' + te.id }
  94. if (episodesTable.put(fresh) == null) {
  95. out.errors = out.errors + 1
  96. out.error = title + ': TVmaze episode ' + te.id + ' not stored: ' + episodesTable.lastError()
  97. } else {
  98. if (added['' + te.season] == null) { added['' + te.season] = [] }
  99. let l = added['' + te.season]
  100. l.push(fresh.id)
  101. added['' + te.season] = l
  102. epByNumber[key] = fresh
  103. out.newEpisodes = out.newEpisodes + 1
  104. }
  105. } else {
  106. let changed = false
  107. if (isPlaceholderTitle(e.title) && !isPlaceholderTitle(te.name)) { e.title = te.name changed = true }
  108. if (textOr(e.release) == null && textOr(te.airdate) != null) { e.release = te.airdate changed = true }
  109. if (changed) {
  110. if (episodesTable.update(e.id, e) == null) {
  111. out.errors = out.errors + 1
  112. out.error = title + ': episode ' + e.id + ' not filled from TVmaze: ' + episodesTable.lastError()
  113. } else {
  114. epByNumber[key] = e
  115. out.filledEpisodes = out.filledEpisodes + 1
  116. }
  117. }
  118. }
  119. }
  120. // the seasons that got episodes: an existing one is updated, a new one stored and linked to the show
  121. showSeasons = []
  122. for (sid of showSeasonsIn) { showSeasons.push(sid) }
  123. for (n of added.keys()) {
  124. let ids = added[n]
  125. let s = seasonsByNumber[n]
  126. if (ids.length > 0 && s.isNew == true) {
  127. let season = { id = s.id seasonNumber = toNumber(n) title = 'Season ' + n release = addedFirstDate[n] summary = ''
  128. show = showKey episodes = ids oldId = 'tvmaze-season:' + tvmzId + ':' + n }
  129. if (seasonsTable.put(season) == null) {
  130. out.errors = out.errors + 1
  131. out.error = title + ': TVmaze season ' + n + ' not stored: ' + seasonsTable.lastError()
  132. } else {
  133. showSeasons.push(season.id)
  134. out.newSeasons = out.newSeasons + 1
  135. }
  136. } else if (ids.length > 0) {
  137. let season = seasonsTable.fetch(s.id)
  138. let eps = []
  139. for (eid of season.episodes) { eps.push(eid) }
  140. for (eid of ids) { eps.push(eid) }
  141. season.episodes = eps
  142. if (seasonsTable.update(season.id, season) == null) {
  143. out.errors = out.errors + 1
  144. out.error = title + ': season ' + season.id + ' not updated: ' + seasonsTable.lastError()
  145. }
  146. }
  147. }
  148. out.showSeasons = showSeasons
  149. return out
  150. }
  151. // a MOVIE: one request — its imdb id (if missing) and its poster; nothing else of the record is touched. `pre` = that
  152. // request's answer when the caller already made it (details.hl firstStep, tracker#26), else null
  153. static syncMovie = (show, res, &pre) => {
  154. out = res
  155. out.requests = 1
  156. details = pre != null ? pre : tmdbGet('/movie/' + show.tmdbId + '?append_to_response=external_ids,credits')
  157. if (details.failed != null) { out.errors = 1 out.error = show.title + ': ' + details.failed return out }
  158. if (pre == null) { out.details = details }
  159. ids = externalIdsFor(show, details.external_ids, false, false)
  160. out.ids = ids.filled
  161. poster = syncPoster(show, details.poster_path)
  162. out.requests = out.requests + poster.requests
  163. out.posters = poster.saved
  164. if (poster.failed != null) { out.errors = out.errors + 1 out.error = show.title + ': ' + poster.failed }
  165. m = show
  166. m.imdbId = ids.imdbId
  167. m.image = poster.image
  168. m.tmdbPoster = poster.tmdbPoster
  169. if (adultOf(details) != null) { m.adult = adultOf(details) }
  170. m.tmdbSync = now()
  171. if (showsTable.update(m.id, m) == null) { out.errors = out.errors + 1 out.error = show.title + ': movie not updated: ' + showsTable.lastError() }
  172. return out
  173. }
  174. // Sync ONE show (by our id). Answers counts: { requests, tvmazeRequests, newSeasons, newEpisodes, updatedEpisodes,
  175. // updatedSeasons, posters, ids, tvmazeEpisodes, tvmazeSeasons, tvmazeFilled, tvmazeSkipped, errors, error } + `details` (the
  176. // details answer with its credits when this call asked for it, else null — tracker#28: the caller stores the credits). Never throws for a TMDB failure — it is counted and the show left as is.
  177. static syncShow = (&showId) => { return syncShowPart(showId, null, null) }
  178. // the same with the details request (`/tv|movie/<id>?append_to_response=external_ids…`) already answered — `pre`, counted as
  179. // this show's first request — so details.hl (tracker#26) asks TMDB once for details, ids AND the cast
  180. static syncShowWith = (&showId, &pre) => { return syncShowPart(showId, pre, null) }
  181. // ONE PART of a series' sync (tracker#26: a talk show with 4,000 episodes took 10 s in one step, blocking every request):
  182. // `only` = { seasons (the TMDB season numbers of this part), finish (false: only those seasons — new ones linked to the show,
  183. // nothing else; true: the ids, TVmaze, poster and the show record), tvmaze (false: no TVmaze lookup/merge — tracker#18's light
  184. // step) }; null = everything at once. `pre` is required with `only` (its request is the caller's: a part counts only its own
  185. // requests).
  186. static emptyResult = () => { return { requests = 0 tvmazeRequests = 0 newSeasons = 0 newEpisodes = 0 updatedEpisodes = 0 updatedSeasons = 0 posters = 0 ids = 0 tvmazeEpisodes = 0 tvmazeSeasons = 0 tvmazeFilled = 0 tvmazeSkipped = 0 errors = 0 error = '' details = null } }
  187. static syncShowPart = (&showId, &pre, &only) => {
  188. let res = emptyResult()
  189. show = showsTable.fetch(showId)
  190. if (show == null) { res.errors = 1 res.error = 'no show ' + showId return res }
  191. if (show.tmdbId == null) { res.errors = 1 res.error = show.title + ': no tmdbId' return res }
  192. if (show.type == 'movie') { return syncMovie(show, res, pre) }
  193. res.requests = only != null ? 0 : 1
  194. details = pre != null ? pre : tmdbGet('/tv/' + show.tmdbId + '?append_to_response=external_ids,aggregate_credits')
  195. if (details.failed != null) { res.errors = 1 res.error = show.title + ': ' + details.failed return res }
  196. if (pre == null) { res.details = details }
  197. // what we have: seasons by number, episodes by tmdbId and by S/E number
  198. // (tracker#18: a part reads only ITS seasons' episodes, unless it finishes with the TVmaze merge, which compares them all —
  199. // Today, 15,716 episodes, read them all for a one-season change: 20 s and GBs of memory)
  200. tvmazeToo = only == null || only.tvmaze != false
  201. allEpisodes = only == null || (only.finish && tvmazeToo)
  202. seasonsByNumber = {}
  203. epByTmdb = {}
  204. epByNumber = {}
  205. for (sid of show.seasons) {
  206. let s = seasonsTable.fetch(sid)
  207. if (s != null) {
  208. seasonsByNumber['' + s.seasonNumber] = s
  209. let epIds = allEpisodes || only.seasons.includes(s.seasonNumber) ? s.episodes : []
  210. for (eid of epIds) {
  211. let e = episodesTable.fetch(eid)
  212. if (e != null) {
  213. if (e.tmdbId != null) { epByTmdb['' + e.tmdbId] = e }
  214. epByNumber[e.seasonNumber + 'x' + e.episodeNumber] = e
  215. }
  216. }
  217. }
  218. }
  219. // plain locals for the record literals below: inside a literal, an entry named `show`/`season` would shadow
  220. // the variable for every later entry (SPEC "A literal's entries are evaluated in order")
  221. showKey = show.id
  222. showTmdb = show.tmdbId
  223. let showSeasons = []
  224. for (sid of show.seasons) { showSeasons.push(sid) }
  225. let showChanged = false
  226. let wanted = wantedSeasonNumbers(details, seasonsByNumber)
  227. if (only != null) {
  228. part = []
  229. for (n of wanted) { if (only.seasons.includes(n)) { part.push(n) } }
  230. wanted = part
  231. }
  232. for (batch of batchesOf(wanted, 20)) {
  233. let names = []
  234. for (n of batch) { names.push('season/' + n) }
  235. res.requests = res.requests + 1
  236. let withSeasons = tmdbGet('/tv/' + show.tmdbId + '?append_to_response=' + names.join(','))
  237. if (withSeasons.failed != null) {
  238. res.errors = res.errors + 1
  239. res.error = show.title + ': ' + withSeasons.failed
  240. } else {
  241. for (n of batch) {
  242. let ts = withSeasons['season/' + n]
  243. if (ts != null && ts.episodes != null) {
  244. let season = seasonsByNumber['' + n]
  245. let seasonIsNew = season == null
  246. let seasonChanged = false
  247. if (seasonIsNew) {
  248. season = { id = newId() seasonNumber = n title = textOr(ts.name) != null ? ts.name : 'Season ' + n
  249. release = textOr(ts.air_date) summary = textOr(ts.overview) != null ? ts.overview : ''
  250. show = showKey episodes = [] oldId = 'tmdb-season:' + showTmdb + ':' + n }
  251. } else {
  252. let seasonMigrated = isMigratedRow(season)
  253. if (changedText(season.title, textOr(ts.name))) {
  254. if (seasonMigrated && season.migratedTitle == null && textOr(season.title) != null) { season.migratedTitle = season.title }
  255. season.title = ts.name seasonChanged = true
  256. }
  257. if (changedText(season.summary, textOr(ts.overview))) {
  258. if (seasonMigrated && season.migratedSummary == null && textOr(season.summary) != null) { season.migratedSummary = season.summary }
  259. season.summary = ts.overview seasonChanged = true
  260. }
  261. if (changedText(season.release, textOr(ts.air_date))) { season.release = ts.air_date seasonChanged = true }
  262. }
  263. let seasonKey = season.id
  264. let seasonEpisodes = []
  265. for (eid of season.episodes) { seasonEpisodes.push(eid) }
  266. for (te of ts.episodes) {
  267. if (te.id != null && te.episode_number != null) {
  268. let e = epByTmdb['' + te.id]
  269. if (e == null) {
  270. let byNum = epByNumber[n + 'x' + te.episode_number]
  271. if (byNum != null && byNum.tmdbId == null) { e = byNum }
  272. }
  273. if (e == null) {
  274. let fresh = { id = newId() episodeNumber = te.episode_number seasonNumber = n
  275. title = textOr(te.name) summary = textOr(te.overview) != null ? te.overview : '' release = textOr(te.air_date)
  276. show = showKey season = seasonKey tmdbId = te.id oldId = 'tmdb-episode:' + te.id }
  277. let putId = episodesTable.put(fresh)
  278. if (putId == null) {
  279. res.errors = res.errors + 1
  280. res.error = show.title + ': episode ' + te.id + ' not stored: ' + episodesTable.lastError()
  281. } else {
  282. seasonEpisodes.push(fresh.id)
  283. epByTmdb['' + te.id] = fresh
  284. epByNumber[n + 'x' + te.episode_number] = fresh
  285. res.newEpisodes = res.newEpisodes + 1
  286. seasonChanged = true
  287. }
  288. } else {
  289. let changed = false
  290. if (e.tmdbId == null) { e.tmdbId = te.id changed = true }
  291. // #15: TMDB's "Episode 4" never replaces a real title (one TVmaze filled, or the migrated one)
  292. let epMigrated = isMigratedRow(e)
  293. if (changedText(e.title, textOr(te.name)) && !(isPlaceholderTitle(te.name) && !isPlaceholderTitle(e.title))) {
  294. if (epMigrated && e.migratedTitle == null && textOr(e.title) != null) { e.migratedTitle = e.title }
  295. e.title = te.name changed = true
  296. }
  297. if (changedText(e.summary, textOr(te.overview))) {
  298. if (epMigrated && e.migratedSummary == null && textOr(e.summary) != null) { e.migratedSummary = e.summary }
  299. e.summary = te.overview changed = true
  300. }
  301. if (changedText(e.release, textOr(te.air_date))) { e.release = te.air_date changed = true }
  302. if (changed) {
  303. if (episodesTable.update(e.id, e) == null) {
  304. res.errors = res.errors + 1
  305. res.error = show.title + ': episode ' + e.id + ' not updated: ' + episodesTable.lastError()
  306. } else {
  307. epByTmdb['' + e.tmdbId] = e
  308. epByNumber[e.seasonNumber + 'x' + e.episodeNumber] = e
  309. res.updatedEpisodes = res.updatedEpisodes + 1
  310. }
  311. }
  312. }
  313. }
  314. }
  315. season.episodes = seasonEpisodes
  316. if (seasonIsNew) {
  317. if (seasonsTable.put(season) == null) {
  318. res.errors = res.errors + 1
  319. res.error = show.title + ': season ' + n + ' not stored: ' + seasonsTable.lastError()
  320. } else {
  321. seasonsByNumber['' + n] = season
  322. showSeasons.push(season.id)
  323. showChanged = true
  324. res.newSeasons = res.newSeasons + 1
  325. }
  326. } else if (seasonChanged) {
  327. if (seasonsTable.update(season.id, season) == null) {
  328. res.errors = res.errors + 1
  329. res.error = show.title + ': season ' + season.id + ' not updated: ' + seasonsTable.lastError()
  330. } else {
  331. res.updatedSeasons = res.updatedSeasons + 1
  332. }
  333. }
  334. }
  335. }
  336. }
  337. }
  338. // a part that is not the last: only the new seasons are linked to the show (the next part reads them)
  339. if (only != null && !only.finish) {
  340. if (showChanged) {
  341. show.seasons = showSeasons
  342. if (showsTable.update(show.id, show) == null) { res.errors = res.errors + 1 res.error = show.title + ': show not updated: ' + showsTable.lastError() }
  343. }
  344. return res
  345. }
  346. // the external ids (tracker.worldapi.org#12): missing ones from TMDB's external_ids, a missing TVmaze id from TVmaze
  347. ids = externalIdsFor(show, details.external_ids, true, tvmazeToo)
  348. res.ids = ids.filled
  349. res.tvmazeRequests = ids.tvmazeRequests
  350. if (ids.failed != null) { res.errors = res.errors + 1 res.error = show.title + ': ' + ids.failed }
  351. // tracker.worldapi.org#15: what TVmaze has and TMDB not yet (new episodes/seasons, empty titles and air dates)
  352. let tvmazeSummary = null
  353. let tvmazeStatus = null
  354. if (numIdOr(ids.tvmzId) != null && tvmazeToo) {
  355. tvm = mergeTvmaze(show.title, showKey, ids.tvmzId, seasonsByNumber, epByNumber, showSeasons)
  356. res.tvmazeRequests = res.tvmazeRequests + tvm.tvmazeRequests
  357. res.tvmazeEpisodes = tvm.newEpisodes
  358. res.tvmazeSeasons = tvm.newSeasons
  359. res.tvmazeFilled = tvm.filledEpisodes
  360. res.tvmazeSkipped = tvm.skipped
  361. if (tvm.errors > 0) { res.errors = res.errors + tvm.errors res.error = tvm.error }
  362. showSeasons = tvm.showSeasons
  363. tvmazeSummary = tvm.summary
  364. tvmazeStatus = tvm.status
  365. }
  366. // the show itself: status, counts, TMDB's overview, the poster, when it was synced
  367. poster = syncPoster(show, details.poster_path)
  368. res.requests = res.requests + poster.requests
  369. res.posters = poster.saved
  370. if (poster.failed != null) { res.errors = res.errors + 1 res.error = show.title + ': ' + poster.failed }
  371. show.seasons = showSeasons
  372. if (textOr(details.status) != null) { show.status = details.status }
  373. if (details.number_of_seasons != null) { show.seasonsCount = details.number_of_seasons }
  374. if (details.number_of_episodes != null) { show.episodesCount = details.number_of_episodes }
  375. // tracker#18: TMDB's text → tmdbSummary, TVmaze's → tvmazeSummary; `summary` is the creator's own text, never written here
  376. if (textOr(details.overview) != null) { show.tmdbSummary = details.overview }
  377. if (tvmazeSummary != null) { show.tvmazeSummary = tvmazeSummary }
  378. // tracker#35: TVmaze's status beside TMDB's (`status`) — the page's pill shows TVmaze's when there is one (fresher)
  379. if (tvmazeStatus != null) { show.tvmazeStatus = tvmazeStatus }
  380. show.image = poster.image
  381. show.tmdbPoster = poster.tmdbPoster
  382. show.imdbId = ids.imdbId
  383. show.tvdbId = ids.tvdbId
  384. show.tvmzId = ids.tvmzId
  385. if (adultOf(details) != null) { show.adult = adultOf(details) }
  386. if (textOr(details.type) != null) { show.tmdbType = details.type show.kind = kindOfTitle(details.type, show.genres) }
  387. show.tmdbSync = now()
  388. if (showsTable.update(show.id, show) == null) { res.errors = res.errors + 1 res.error = show.title + ': show not updated: ' + showsTable.lastError() }
  389. return res
  390. }
  391. // ---- the LIGHT step of the daily delta run (tracker#18) ---------------------------------------------------------------
  392. // A changed title NOBODY follows (dailysync.hl): its details (+ ids + credits: the record, applySynced) and only the seasons
  393. // that can have changed — the ones we don't have, the ones where TMDB counts MORE episodes than we have (fewer: TVmaze's
  394. // extras, nothing to fetch), and the newest one (new or renamed episodes land there). No TVmaze (its merge only matters for the followed shows' lists; their full step still does
  395. // it). Real data (2026-10-01): Today (67 seasons / 15,716 episodes) and EastEnders (43 / 7,349) change every day; their full
  396. // sync blocked the server 20.8 s each and grew the process by ~5 GB each.
  397. static changedSeasonNumbers = (&details, &show) => {
  398. ours = {}
  399. for (sid of show.seasons) {
  400. let s = seasonsTable.fetch(sid)
  401. if (s != null) { ours['' + s.seasonNumber] = s.episodes.length }
  402. }
  403. let latest = -1
  404. for (x of (details.seasons != null ? details.seasons : [])) {
  405. if (x != null && x.season_number != null && x.season_number > latest && (x.episode_count == null || x.episode_count > 0)) { latest = x.season_number }
  406. }
  407. out = []
  408. for (x of (details.seasons != null ? details.seasons : [])) {
  409. if (x != null && x.season_number != null) {
  410. let n = x.season_number
  411. if (n == latest || ours['' + n] == null || (x.episode_count != null && x.episode_count > ours['' + n])) { out.push(n) }
  412. }
  413. }
  414. return out
  415. }
  416. // tracker#35: `withStatus` — TVmaze's change list named this series too: its TVmaze status as well (one more TVmaze request)
  417. static syncShowDelta = (&showId, &withStatus) => {
  418. show = showsTable.fetch(showId)
  419. if (show == null || show.tmdbId == null || show.type == 'movie') { return syncShow(showId) }
  420. details = tmdbGet('/tv/' + show.tmdbId + '?append_to_response=external_ids,aggregate_credits')
  421. if (details.failed != null) {
  422. let res = emptyResult()
  423. res.requests = 1
  424. res.errors = 1
  425. res.error = show.title + ': ' + details.failed
  426. return res
  427. }
  428. r = syncShowPart(showId, details, { seasons = changedSeasonNumbers(details, show) finish = true tvmaze = false })
  429. r.requests = r.requests + 1
  430. r.details = details
  431. if (withStatus) {
  432. st = syncTvmazeStatus(showId)
  433. r.tvmazeRequests = r.tvmazeRequests + st.tvmazeRequests
  434. if (st.error != '') { r.errors = r.errors + 1 r.error = st.error }
  435. }
  436. return r
  437. }
  438. // tracker#35: TVmaze's status of ONE series (`GET /shows/<tvmzId>`, one TVmaze request) → `tvmazeStatus` when it changed — the
  439. // daily delta run for a series nobody follows that TVmaze's change list names (a followed one gets TVmaze's merge, which
  440. // brings it). Answers the sync's counts (emptyResult: tvmazeRequests, errors, error; no `details`).
  441. static syncTvmazeStatus = (&showId) => {
  442. let res = emptyResult()
  443. show = showsTable.fetch(showId)
  444. if (show == null || show.tvmzId == null || ('' + show.tvmzId).trim() == '') { return res }
  445. res.tvmazeRequests = 1
  446. got = tvmazeShow(show.tvmzId)
  447. if (got.failed != null) { res.errors = 1 res.error = show.title + ': ' + got.failed return res }
  448. if (got.status != null && got.status != show.tvmazeStatus) {
  449. show.tvmazeStatus = got.status
  450. if (showsTable.update(show.id, show) == null) { res.errors = 1 res.error = show.title + ': show not updated: ' + showsTable.lastError() }
  451. }
  452. return res
  453. }
  454. // flush the three tables' index/meta state to disk (after a run, and every few shows)
  455. static persistSync = () => {
  456. showsTable.persist()
  457. seasonsTable.persist()
  458. episodesTable.persist()
  459. return true
  460. }

Branches

Latest commits

  • 718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre
  • 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
  • eb3b9205tracker: report 031mre
  • 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
  • 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
  • a386dc92tracker: reports 029 + 030mre
  • 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
  • d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
  • 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
  • 661c2592tracker: report 028mre
  • 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
  • d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre
  • 2e89b968tracker mission 028 (code order) 5/5 let: `let` only where a variable is reassigned — 667 never-reassigned lets became plain declarations (project.hl, lib/, components/, tools/, tests/); kept: 264 in loop bodies (a plain declaration there is 'Cannot reassign' on the 2nd pass), 234 reassigned, 27 whose name is also a member/outer/free name (a plain write would rebind it); tools/let-audit.py decides and fixes (README 'Code order'); tests/realdata-m028.{sh,mjs} = the page-output diff on a real copy; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 54796ff2tracker mission 028 (code order) 4/5 thin faces + last copies: the show page's check/follow faces call lib/watches.hl toggleWatched / toggleSeasonWatched (seasonAllWatched moved there) and lib/follows.hl toggleFollowed; both logins (header selector face, /login/callback) share lib/users.hl userOfCode; todayStr/listOf copies in components and the export readers copied into tools/migrate.hl + tools/old-short-ids.hl now once (lib/util.hl, lib/export.hl); gates 342/0, 32/0, 52/0; old-short-ids output byte-identical, migrate output identicalmre
  • 06b078e3tracker mission 028 (code order) 3/5 project.hl is the map: config, routes, wiring and a feature → file index (914 → 258 lines); the background jobs (daily sync run, backfills, details repair, credits job, merge, short ids, collection seed) moved unchanged into lib/jobs.hl (a class: their state is reassigned every step, a static cannot be; one instance made after the server), the login callback into lib/users.hl, poster/photo serving into lib/images.hl, the /shows/<slug> rule into lib/shows.hl showsMovedPath; route handlers are thin wrappers; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 94716fd2tracker mission 028 (code order) 2/5 util + topics: lib/util.hl holds envOr, storageDir, postersDir, profilesDir, newId, hexDigits, todayStr, dateOr, textOr, hasId, listOr, firstOf, sortDesc once (were copied into up to 5 files); tmdbsync.hl split into tmdb.hl (TMDB/TVmaze requests), sync.hl (one title's sync), sync-helpers.hl, backfill.hl; details.hl split into details.hl, credits.hl, credits-helpers.hl (isIncomplete to shows.hl); search-helpers.hl (words, query, ranking, slugs); collections.hl (the TMDB collection seed, out of franchises.hl); deltasync.hl renamed dailysync.hl; no behaviour change: gates 342/0, 32/0, 52/0, real-copy pages identicalmre
  • 186079b0tracker mission 028 (code order) 1/5 move: every root .hl except project.hl into lib/ (styles.hl into components/), import paths only; gates 342/0, 32/0, 52/0; real-copy pages identicalmre
  • 4f47f181tracker: report 027mre
  • dc1d4be4tracker mission 027: Hybriel master 06617221 vendored (plugin allocator fixes 3a781359 + 413f60e4); real copy RSS through first-start jobs + 400 loads flat ~2.55 GB (190aa11d 2.3 -> 5.6 GB), page times <= 1.1x; gates 342/0, 32/0, 52/0mre
  • 84e1b3e1tracker: reports 025 + 026mre