gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit17feb7ab17feb7abHM55 WIP: hm54-fill re-applied on main; browser gate fails at ep3 toggleTracker17feb7ab/lib/shows.hl

51.0 KB

  1. // lib/shows.hl — title data, page rows and actions for a show's page (tracker.worldapi.org#4): shows, seasons,
  2. // episodes, persons, genres (storage/mpackdb/, migrated by tools/migrate.hl, tracker.worldapi.org#2).
  3. // Kept apart from watches.hl (the per-user watch state) and from components/show.hl (the page itself)
  4. // so /unwatched and /schedule (tickets #5/#6, "reuse, don't copy") can import the same functions.
  5. //
  6. // Person slug/TMDB indexes are native; title slug maps remain in this module.
  7. import { MPackDB } from 'hl:mpackdb'
  8. import { warm } from './warm.hl'
  9. import { exists } from 'hl:fs'
  10. import { storageDir, postersDir, hasId, dayStr, textOr, envOr } from './util.hl'
  11. import { isFollowing, toggleFollowed } from './follows.hl'
  12. import { watchesOfUser, watchedSetOf, isWatched, watchClassOf, seasonAllWatched, toggleWatched, toggleSeasonWatched } from './watches.hl'
  13. import { needsDetails } from './details.hl'
  14. import { widgetsOf } from './franchises.hl'
  15. import { listOr } from './util.hl'
  16. import { dateText } from './people.hl'
  17. static genresTable = new MPackDB(file = storageDir + '/genres.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  18. // tracker#62: first open builds missing indexes from data; compact stays false.
  19. static personsTable = new MPackDB(file = storageDir + '/persons.db', primaryKey = '@id', indexes = ['!oldId', 'urlSegment', 'tmdbId'], compact = false)
  20. static showsTable = new MPackDB(file = storageDir + '/shows.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  21. static seasonsTable = new MPackDB(file = storageDir + '/seasons.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  22. static episodesTable = new MPackDB(file = storageDir + '/episodes.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  23. // the show with this urlSegment (slug), or null. tracker#28: by a slug → id map (one scan, at the first call) — the old scan of
  24. // every record per call (twice per show page) decoded every title's cast + crew: 82 ms per call on the live copy before the
  25. // credits, growing with them. tracker#42 (mission 038): a slug the map does not know is NOT a title — no scan any more (an unknown
  26. // slug, a bot's or a typo, cost one scan of every title per lookup and the page does 4: ~9 s on the live copy, the one-request-at-a-
  27. // time server blocked). A title added since the build (search import, filmography fill — the only two puts) is in the map through
  28. // catalog.hl refreshCatalogShow → refreshTitleCaches → noteSlugsOf, which both call right after the put; merge.hl notes its own.
  29. // (Flat static written key by key, like people.hl's maps.)
  30. // tracker#31 (mission 026): a MERGED title's slug (a tombstone's, below) and a keeper's former slug (`oldSlugs`) answer the
  31. // KEEPER — several records can share one slug (migrated duplicates did), so each slug has a rank: a live record's own slug (3)
  32. // beats a live record's former one (2) beats a tombstone's (1).
  33. static slugIds = {}
  34. static slugRank = {}
  35. static slugIdsBuilt = { yes = false }
  36. // ---- merged titles (tracker#31, mission 026, merge.hl) ----------------------------------------------------------------------
  37. // The old tracker left 68 titles as 2–6 records each (same type + TMDB id). The repair (merge.hl) keeps ONE record (the keeper)
  38. // and turns the others into TOMBSTONES — never deleted: `mergedInto` = the keeper's id, `mergedTmdbId` (their `tmdbId` is
  39. // null, so nothing looks them up by it), `mergedSeasons` (their `seasons` are empty). Every list skips them (isPublicTitle),
  40. // every job skips them, a tombstone's slug and short id lead to the keeper.
  41. static isMerged = (&show) => { return show != null && show.mergedInto != null }
  42. // the record a page shows for this one: the keeper of a tombstone (a chain is followed, at most 5 steps), else itself
  43. static liveShowOf = (&show) => {
  44. let s = show
  45. let n = 0
  46. while (s != null && s.mergedInto != null && n < 5) {
  47. s = showsTable.fetch(s.mergedInto)
  48. n = n + 1
  49. }
  50. return s
  51. }
  52. static holdsSlug = (&s, &slug) => { return s.urlSegment == slug || (s.oldSlugs != null && s.oldSlugs.includes(slug)) }
  53. // this record's slugs into the map (at the build, and by merge.hl after a merge changed a record)
  54. static noteSlugsOf = (&s) => {
  55. live = s.mergedInto == null
  56. mine = []
  57. if (s.urlSegment != null) { mine.push({ slug = s.urlSegment rank = live ? 3 : 1 }) }
  58. if (live && s.oldSlugs != null) { for (o of s.oldSlugs) { mine.push({ slug = o rank = 2 }) } }
  59. for (m of mine) {
  60. cur = slugRank[m.slug]
  61. if (cur == null || m.rank >= cur || slugIds[m.slug] == s.id) {
  62. slugIds[m.slug] = s.id
  63. slugRank[m.slug] = m.rank
  64. }
  65. }
  66. return null
  67. }
  68. // bootscan.hl streamed every title through noteSlugsOf
  69. static markSlugIdsBuilt = () => {
  70. slugIdsBuilt.yes = true
  71. return true
  72. }
  73. static ensureSlugIds = () => {
  74. // mission T17: during the progressive start the map is being filled (bootscan.hl) — no blocking full scan here
  75. if (!slugIdsBuilt.yes && !warm.running) {
  76. // mission 043: streamed (one title decoded at a time); at boot bootscan.hl fills the map in its own pass over the titles
  77. for (s of showsTable.iterate(null, null)) { noteSlugsOf(&s) }
  78. slugIdsBuilt.yes = true
  79. }
  80. return true
  81. }
  82. static showBySlug = (&slug) => {
  83. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  84. ensureSlugIds()
  85. id = slugIds[slug]
  86. if (id != null) {
  87. hit = showsTable.fetch(id)
  88. if (hit != null && holdsSlug(&hit, &slug)) { return liveShowOf(&hit) }
  89. }
  90. return null
  91. }
  92. // tracker#31/#41 (missions 026, 037b): a slug that is not a live title's own any more (a tombstone's, a keeper's former one) → the
  93. // keeper's path, or null (a live title's own slug, an unknown one). Only the slug map (built at boot, kept current by merge.hl
  94. // noteSlugsOf), never a scan. No route per such slug (hl:web writes every route into each page's HTML; the moved slugs there
  95. // included adult titles'): /movies/<slug> and /series/<slug> render the keeper's page (showBySlug), its head names this path.
  96. static movedSlugPath = (&slug) => {
  97. ensureSlugIds()
  98. rank = slugRank[slug]
  99. if (rank == null || rank >= 3) { return null }
  100. keeper = liveShowOf(showsTable.fetch(slugIds[slug]))
  101. if (keeper == null || keeper.mergedInto != null || keeper.urlSegment == null || keeper.urlSegment == slug) { return null }
  102. return titlePath(&keeper)
  103. }
  104. // how many slugs lead to a keeper now (project.hl's boot log line)
  105. static movedSlugCount = () => {
  106. ensureSlugIds()
  107. let n = 0
  108. for (slug of slugRank.keys()) { if (slugRank[slug] < 3 && movedSlugPath(&slug) != null) { n = n + 1 } }
  109. return n
  110. }
  111. static genreById = (&id) => { return id == null ? null : genresTable.fetch(id) }
  112. // /genres/<genre> (mission 058): the genre with this urlSegment ('Action', 'Sci-Fi-Fantasy'), exact first, else ignoring case
  113. // — a scan of the genres table (27 rows)
  114. static genreBySlug = (&slug) => {
  115. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  116. lower = slug.toLowerCase()
  117. let loose = null
  118. for (g of genresTable.find(null, null)) {
  119. if (g.urlSegment == slug) { return g }
  120. if (loose == null && g.urlSegment != null && ('' + g.urlSegment).toLowerCase() == lower) { loose = g }
  121. }
  122. return loose
  123. }
  124. static personById = (&id) => { return id == null ? null : personsTable.fetch(id) }
  125. // GC1: the five request caches (personLinkCache, cardCache, episodeRowsCache, episodeKeyCache, creditRowCache) only ever grew: every title
  126. // a bot or a visitor opened, every person it linked, stayed in the heap for good and every collection marked it again. Each now holds
  127. // at most `cacheLimit` entries; the one that is full is emptied before it takes the next (an entry is a plain recomputation of the
  128. // stored record, so a dropped one is read again at its next ask and the page is the same). The limits sit far above what the warm
  129. // set needs (the followed titles and their watched episodes, warmed at boot). TRACKER_CACHE_MAX sets all five (a test).
  130. static cacheMax = toNumber(envOr('TRACKER_CACHE_MAX', '0'))
  131. static cacheLimit = { card = cacheMax > 0 ? cacheMax : 20000 episodeRows = cacheMax > 0 ? cacheMax : 2000 episodeKey = cacheMax > 0 ? cacheMax : 60000 creditRow = cacheMax > 0 ? cacheMax : 20000 personLink = cacheMax > 0 ? cacheMax : 50000 }
  132. static cacheCount = { card = 0 episodeRows = 0 episodeKey = 0 creditRow = 0 personLink = 0 }
  133. // tracker#42 (mission 038): what a cast / crew row needs of a person — { name, urlSegment } — cached per person: a series page linked
  134. // up to 300 cast + crew people by fetching each WHOLE record (their `shows` credits: Saturday Night Live's 303 cast carry 4,761) —
  135. // ~49k allocations and 11 ms per render, a third of the page's allocations (every ~3M allocations the GC stops the server for
  136. // ~0.8 s on the live copy's heap). A person's name and slug never change once stored (people.hl creates them; the fill, photos and
  137. // merge.hl only add data), so the cache is never stale. null = no such person (not remembered: a guest's person can come later).
  138. static personLinkCache = {}
  139. static personLinkOf = (&personId) => {
  140. if (personId == null) { return null }
  141. if (personLinkCache[personId] != null) { return personLinkCache[personId] }
  142. linkPerson = personsTable.fetch(personId)
  143. if (linkPerson == null) { return null }
  144. if (cacheCount.personLink >= cacheLimit.personLink) {
  145. for (k of personLinkCache.keys()) { delete personLinkCache[k] }
  146. cacheCount.personLink = 0
  147. }
  148. personLinkCache[personId] = { name = linkPerson.name urlSegment = linkPerson.urlSegment }
  149. cacheCount.personLink = cacheCount.personLink + 1
  150. return personLinkCache[personId]
  151. }
  152. static seasonById = (&id) => { return id == null ? null : seasonsTable.fetch(id) }
  153. static showById = (&id) => { return id == null ? null : showsTable.fetch(id) }
  154. static episodeById = (&id) => { return id == null ? null : episodesTable.fetch(id) }
  155. // EVERY show / episode as one array — for the tools in tools/ only (the app streams: bootscan.hl, mission 043)
  156. static allShows = () => { return showsTable.find(null, null) }
  157. static allEpisodes = () => { return episodesTable.find(null, null) }
  158. // insertion sort, hand-written (no list sort(), hybriel#1) — a show has a handful of seasons at most
  159. static insertDesc = (&sorted, &s) => {
  160. out = []
  161. let inserted = false
  162. for (x of sorted) {
  163. if (!inserted && s.seasonNumber >= x.seasonNumber) { out.push(s) inserted = true }
  164. out.push(x)
  165. }
  166. if (!inserted) { out.push(s) }
  167. return out
  168. }
  169. static insertAsc = (&sorted, &e) => {
  170. out = []
  171. let inserted = false
  172. for (x of sorted) {
  173. if (!inserted && e.episodeNumber <= x.episodeNumber) { out.push(e) inserted = true }
  174. out.push(x)
  175. }
  176. if (!inserted) { out.push(e) }
  177. return out
  178. }
  179. // a show's seasons, latest (highest seasonNumber) first — creator: "all seasons in reverse order,
  180. // latest on top"
  181. static seasonsOfShow = (&show) => {
  182. let sorted = []
  183. for (id of show.seasons) {
  184. s = seasonsTable.fetch(id)
  185. if (s != null) { sorted = insertDesc(&sorted, &s) }
  186. }
  187. return sorted
  188. }
  189. // a season's episodes, in episode-number order
  190. static episodesOfSeason = (&season) => {
  191. let sorted = []
  192. for (id of season.episodes) {
  193. e = episodesTable.fetch(id)
  194. if (e != null) { sorted = insertAsc(&sorted, &e) }
  195. }
  196. return sorted
  197. }
  198. // ---- labels shared by every list (tracker.worldapi.org#8) -------------------------------------
  199. static pad2 = (&n) => {
  200. let s = '' + n
  201. while (s.length < 2) { s = '0' + s }
  202. return s
  203. }
  204. // an episode as `S01E01` (creator: "write it like that: S01E01") — /my/shows, /my/unwatched, /my/schedule
  205. static episodeCode = (&seasonNumber, &episodeNumber) => { return 'S' + pad2(&seasonNumber) + 'E' + pad2(&episodeNumber) }
  206. // the show's year: `year`, else the first 4 characters of `release` ('YYYY-MM-DD'; 197 migrated shows have
  207. // no year, a few of those an empty release) — null when neither gives one
  208. static showYear = (&show) => {
  209. if (show.year != null) { return '' + show.year }
  210. if (show.release != null && hlTypeName(show.release) == 'String' && show.release.length >= 4) { return show.release.slice(0, 4) }
  211. return null
  212. }
  213. // a show's title as every list shows it: `Doctor Who (2005)` (creator: so same-named shows can be told apart)
  214. static titleWithYear = (&show) => {
  215. y = showYear(&show)
  216. return y != null ? show.title + ' (' + y + ')' : show.title
  217. }
  218. // ---- the description (tracker#18) ---------------------------------------------------------------
  219. // creator: "i put the summary in an own field for tmdb because some summaries i wanted to rewrite ... in that case the summary
  220. // has priority over maze or tmdb" — `summary` (the creator's own text, never written by the sync), else TMDB's `tmdbSummary`,
  221. // else TVmaze's `tvmazeSummary` (HTML stripped); '' when none
  222. static hasText = (&v) => { return v != null && hlTypeName(v) == 'String' && v.trim() != '' }
  223. static summaryOf = (&show) => {
  224. if (show == null) { return '' }
  225. if (hasText(&show.summary)) { return show.summary }
  226. if (hasText(&show.tmdbSummary)) { return show.tmdbSummary }
  227. if (hasText(&show.tvmazeSummary)) { return show.tvmazeSummary }
  228. return ''
  229. }
  230. // ---- a series' status (tracker#35, mission 030) -----------------------------------------------------------------------
  231. // The page's status pill (components/show.hl) next to a series' or show's title: TVmaze's `tvmazeStatus` (Running, Ended, To Be
  232. // Determined, In Development — stored by the sync and backfill.hl's status backfill) when there is one — creator: "this was also
  233. // something tvmaze was better updated about" — else TMDB's `status` (Returning Series, In Production, Planned, Pilot, Ended,
  234. // Canceled). TVmaze has no "canceled": its Ended + TMDB's Canceled shows Canceled (the same state, TMDB's word says more).
  235. // tracker#35 follow-up (mission 033): TVmaze's "Running" reads stale to the creator (Twisted Metal between seasons) — its LABEL
  236. // is "Returning", or "Airing" while an episode of the series aired in the last 7 days or airs in the next 7 (the stored episodes'
  237. // `release`, `isAiring`). Only the label: the stored tvmazeStatus stays "Running"; every other word (Ended, Canceled, To Be
  238. // Determined, TMDB's) is shown as before.
  239. // { text, tone } — tone running | pending | ended | canceled | other (the pill's colour, styles.hl); text '' = no pill (a movie,
  240. // or no status known).
  241. static statusTones = { 'Running' = 'running' 'Returning Series' = 'running' 'To Be Determined' = 'pending' 'In Development' = 'pending'
  242. 'In Production' = 'pending' 'Planned' = 'pending' 'Pilot' = 'pending' 'Ended' = 'ended' 'Canceled' = 'canceled' }
  243. static statusOf = (&show) => {
  244. if (show == null || show.type == 'movie') { return { text = '' tone = '' } }
  245. let word = hasText(&show.tvmazeStatus) ? show.tvmazeStatus : (hasText(&show.status) ? show.status : '')
  246. if (word == 'Ended' && show.status == 'Canceled') { word = 'Canceled' }
  247. if (word == '') { return { text = '' tone = '' } }
  248. tone = statusTones[word]
  249. let text = word == 'Returning Series' ? 'Returning' : word
  250. if (word == 'Running') { text = isAiring(&show) ? 'Airing' : 'Returning' }
  251. return { text = text tone = tone != null ? tone : 'other' }
  252. }
  253. // an episode released today-7 … today+7 (UTC days, both ends included); only the two newest numbered seasons are looked at (an
  254. // airing episode is in one of them — The Simpsons has 36 seasons). Specials (season 0; the sync keeps them only for a show that
  255. // already has one) do not count: Family Guy's special of 2026-10-05 between S24 and S25 is no "Airing".
  256. static isAiring = (&show) => {
  257. firstDay = dayStr(-7)
  258. lastDay = dayStr(7)
  259. seasons = []
  260. for (se of seasonsOfShow(&show)) { if (se.seasonNumber != 0 && seasons.length < 2) { seasons.push(se) } }
  261. let k = 0
  262. while (k < seasons.length) {
  263. for (id of seasons[k].episodes) {
  264. e = episodesTable.fetch(id)
  265. if (e != null && hasText(&e.release)) {
  266. d = e.release.slice(0, 10)
  267. if (d >= firstDay && d <= lastDay) { return true }
  268. }
  269. }
  270. k = k + 1
  271. }
  272. return false
  273. }
  274. // ---- adult titles (mission 054) -----------------------------------------------------------------
  275. // `adult` on every title: true / false from TMDB, null = not known yet (the migrated rows; the app's backfill, backfill.hl
  276. // `backfillTitle`, asks TMDB). The PUBLIC lists (catalog.hl: homepage rows, /movies, /shows) and the search (search.hl) show
  277. // ONLY a title TMDB says is not adult — unknown counts as hidden. A title the user follows stays on /my/* and its page.
  278. // A merged tombstone (tracker#31) is never public.
  279. static isPublicTitle = (&show) => { return show != null && show.adult == false && show.mergedInto == null }
  280. // ---- incomplete titles (tracker.worldapi.org#26; details.hl completes them, credits.hl and dailysync.hl skip them) ------------
  281. // COMPLETE = TMDB's details answer went through this app once: completed (`detailsAt`, details.hl) or synced (`tmdbSync`, the
  282. // last step of sync.hl's sync — the daily run, a search import) — or given up on (`detailsCheck`: TMDB 404 / adult).
  283. // INCOMPLETE = every other title with a TMDB id: a filmography title (`minimal`, #26) until it is completed, an import whose
  284. // sync never finished, and (tracker#33, mission 029) the old tracker's MIGRATED rows that were never synced — #26 only looked
  285. // at `minimal`/`imported`, so they passed: live copy 2026-10-03, 5,697 non-adult titles (4,206 movies, 1,491 series), 691
  286. // series without a single season, 209 + 84 without a poster, 389 + 120 without genres (tools/count-incomplete.hl). Also a
  287. // movie with a TV answer's leftovers (below). What a title still lacks that a page shows: `missingParts`.
  288. static isIncomplete = (&s) => {
  289. return s != null && s.tmdbId != null && s.detailsCheck == null
  290. && ((s.detailsAt == null && (s.minimal == true || s.tmdbSync == null)) || hasTvLeftovers(&s))
  291. }
  292. // tracker#33: what a title's page would miss — the parts a complete record has when TMDB has them: 'poster', 'summary',
  293. // 'genres', 'cast', 'ids' (no IMDb id), 'release', 'seasons' (a series without any). The repair does these titles first
  294. // (details.hl detailsRepairQueue); tools/count-incomplete.hl counts them. A complete title can still miss one — TMDB has none
  295. // (The Remaining, a 7-minute Finnish short: no poster, no IMDb id on TMDB).
  296. static missingParts = (&s) => {
  297. out = []
  298. if (s.image == null || s.image == '') { out.push('poster') }
  299. if (summaryOf(&s) == '') { out.push('summary') }
  300. if (s.genres == null || s.genres.length == 0) { out.push('genres') }
  301. if (s.cast == null || s.cast.length == 0) { out.push('cast') }
  302. if (s.imdbId == null) { out.push('ids') }
  303. if (s.release == null || s.release == '') { out.push('release') }
  304. if (s.type != 'movie' && (s.seasons == null || s.seasons.length == 0)) { out.push('seasons') }
  305. return out
  306. }
  307. // mission 025 (report 021's "wrong TMDB id"): the #9 sync once asked TMDB for every followed title as `/tv/<tmdbId>` — a movie's
  308. // id is ANOTHER title there (fixed in mission 006: movies go to /movie/) and the TV title's overview, status and season/episode
  309. // counts were stored on the movie. On the real data only Star Trek: First Contact: its tmdbId 199 IS the movie (/movie/199),
  310. // tmdbSummary was TV 199's ("Kabuhayang Swak na Swak …"), status 'Ended', seasonsCount/episodesCount 0. The movie path never
  311. // writes the counts, so a movie that has them is such a record: the repair asks /movie/<id> again (withDetailsFields: overview →
  312. // tmdbSummary, status, …) and firstStep drops the counts — repaired once, then it no longer matches.
  313. static hasTvLeftovers = (&s) => { return s.type == 'movie' && (s.seasonsCount != null || s.episodesCount != null) }
  314. // ---- the kind of a title (tracker.worldapi.org#21, mission 068; #43, mission 037) ------------------------------------------
  315. // A TV title (`type = 'series'`) is either a SERIES (TMDB's TV type Scripted, Miniseries, Documentary) or a SHOW (Reality,
  316. // Talk Show, News, Video — or one of our genres Reality / Talk / News, whatever the type — or, #43, TVmaze's type Variety, Talk
  317. // Show, Reality, Game Show, News, Panel Show, Award Show, Sports: TMDB calls Saturday Night Live UK "Scripted", TVmaze
  318. // "Variety"; TVmaze's type is stored as `tvmazeType` by the sync and the TVmaze status backfill). Stored on the title as `kind`
  319. // ('series' | 'show') and TMDB's type as `tmdbType`: by the kind backfill (backfill.hl `kindTitle`, one TMDB request per
  320. // title without a show genre), the daily sync and the search import. Until a title has `kind`, its genres decide (no
  321. // type known yet = series). Movies are `type = 'movie'` and have no kind.
  322. static showTmdbTypes = ['Reality', 'Talk Show', 'News', 'Video']
  323. static showGenreNames = ['Reality', 'Talk', 'News']
  324. // #43 (mission 037): TVmaze's show types that are SHOWS ("all that game show and reality and talkshow stuff", #21); its others —
  325. // Scripted, Animation, Documentary — are series. '' = TVmaze was asked and gave none
  326. static showTvmazeTypes = ['Variety', 'Talk Show', 'Reality', 'Game Show', 'News', 'Panel Show', 'Award Show', 'Sports']
  327. static showGenreIdsOf = () => {
  328. out = {}
  329. for (g of genresTable.find(null, null)) { if (g.name != null && showGenreNames.includes('' + g.name)) { out[g.id] = true } }
  330. return out
  331. }
  332. // the genre ids that make a title a show — read once (the genres table never changes while the app runs)
  333. static showGenreIds = showGenreIdsOf()
  334. static hasShowGenre = (&genres) => {
  335. if (genres == null) { return false }
  336. for (g of genres) { if (showGenreIds[g] == true) { return true } }
  337. return false
  338. }
  339. // 'show' | 'series' from TMDB's type, the title's genre ids and TVmaze's type (#43; null = not known)
  340. static kindOfTitle = (&tmdbType, &genres, &tvmazeType) => {
  341. if (hasShowGenre(&genres)) { return 'show' }
  342. if (tmdbType != null && showTmdbTypes.includes('' + tmdbType)) { return 'show' }
  343. if (tvmazeType != null && showTvmazeTypes.includes('' + tvmazeType)) { return 'show' }
  344. return 'series'
  345. }
  346. // #43: the kind to STORE after TVmaze's type came in — the rule once TMDB's or TVmaze's type is known, else the stored one (null:
  347. // the genres decide until the kind backfill asks TMDB, which it does only for a title without a stored kind)
  348. static kindWithTvmaze = (&show) => {
  349. known = (show.tmdbType != null && '' + show.tmdbType != '') || (show.tvmazeType != null && showTvmazeTypes.includes('' + show.tvmazeType))
  350. return known ? kindOfTitle(&show.tmdbType, &show.genres, &show.tvmazeType) : show.kind
  351. }
  352. // 'movie' | 'series' | 'show' of a stored title
  353. static titleKind = (&show) => {
  354. if (show.type == 'movie') { return 'movie' }
  355. if (show.kind == 'show' || show.kind == 'series') { return show.kind }
  356. return kindOfTitle(&show.tmdbType, &show.genres, &show.tvmazeType)
  357. }
  358. // a title's own page: /movies/<slug>, /series/<slug>, /shows/<slug> (the old /shows/<slug> of a movie or series answers 301,
  359. // project.hl showsRoute)
  360. static titlePath = (&show) => {
  361. k = titleKind(&show)
  362. return (k == 'movie' ? '/movies/' : (k == 'show' ? '/shows/' : '/series/')) + show.urlSegment
  363. }
  364. // `/shows/<slug>` (#21, mission 068; project.hl showsRoute): since the split only the game / reality / talk / news SHOWS live
  365. // there — the page a series or a movie answers with a 301 instead (its own page), as does a merged duplicate's slug or a
  366. // keeper's former one (tracker#31: the keeper's page); null = render the title page here (a show, or an unknown slug)
  367. static showsMovedPath = (&slug) => {
  368. show = showBySlug(&slug)
  369. return show != null && (titleKind(&show) != 'show' || show.urlSegment != slug) ? titlePath(&show) : null
  370. }
  371. // tracker.worldapi.org#20: the type word of a page heading / list label and its colour class (styles.hl `type-*`)
  372. static kindWord = (&kind) => { return kind == 'movie' ? 'Movie' : (kind == 'show' ? 'Show' : 'Series') }
  373. static typeWordOf = (&show) => { return kindWord(titleKind(&show)) }
  374. // the theme's pill classes of a kind (layouts "Type colours and pills": Movie = type-1, Series = type-2, Show = type-3) — the kind label of a list row
  375. static pillClassOfWord = (&word) => { return word == 'Movie' ? 'pill type-1' : (word == 'Show' ? 'pill type-3' : 'pill type-2') }
  376. static typeClassOf = (&show) => { return pillClassOfWord(typeWordOf(&show)) }
  377. // the poster file name (oldId + the migrated extension) — null when either is missing; served at
  378. // /posters/<name> (images.hl), which falls back to a placeholder when the file itself isn't there
  379. // yet (the real poster files are not part of the mongo export, see the report's `open`)
  380. static posterName = (&show) => {
  381. if (show == null) { return null }
  382. if (show.oldId == null || show.image == null || show.image == '') { return null }
  383. return show.oldId + '.' + show.image
  384. }
  385. // the poster's URL for a LIST (/my/shows, tracker.worldapi.org#8): `/posters/<name>` only when the file really
  386. // is in storage/mpackdb/posters/ (images.hl serves the same folder), else the ONE placeholder URL
  387. // `/posters/none` — the real data has no poster files yet, and 128 different URLs all answering the same
  388. // placeholder were 128 requests per page load (the browser can't cache them as one)
  389. static posterUrlOf = (&show) => { return posterUrlOfName(posterName(&show)) }
  390. static posterUrlOfName = (&name) => { return name != null && exists(postersDir + '/' + name) ? '/posters/' + name : '/posters/none' }
  391. // ---- slim per-title caches for the lists (tracker.worldapi.org#30, mission 025) ------------------------------------
  392. // /my/series took 4.4 s on a process that had run the first-start jobs (0.4 s fresh): every load fetched each followed title's
  393. // WHOLE record (cast + crew, up to 300 entries) and one episode per watch (11.7k fetches); /my/unwatched every season and
  394. // episode of every followed title. Each fetch decodes a new object, and with a big live heap (after the jobs) every byte
  395. // allocated feeds the byte-triggered GC. Now a list reads two small cached things per title:
  396. // - `cardOf(id)`: { id type kind title year titleYear href posterName } — what a row shows;
  397. // - `episodeRowsOf(id)`: every episode of the title as { id s e title release }, seasons latest first, episodes in order
  398. // (the same order as seasonsOfShow/episodesOfSeason);
  399. // - `episodeKeyOf(id)`: one episode as { show s e } — /my/series' last watched episode goes by the WATCHED episode's own
  400. // `show` (as before): migrated episodes the sync left outside the title's seasons (a duplicate season, e.g. Reacher S03 on
  401. // the real data) still count. project.hl warms every watched episode at boot.
  402. // Filled at the first ask (project.hl warms the followed titles at boot) and kept in sync by catalog.hl `refreshCatalogShow`,
  403. // which every writer of a title already calls after it changed one (daily sync, repair, kinds, adult backfill, imports):
  404. // it calls `refreshTitleCaches(show)`, which rebuilds the entries that exist. Cached values are only ever RETURNED from a
  405. // function (a `let x = map[k]` deep-copies the value; a return does not — measured: 3.7 ms per 20k-row copy).
  406. static cardCache = {}
  407. static episodeRowsCache = {}
  408. static episodeKeyCache = {}
  409. static cardFrom = (&show) => {
  410. y = showYear(&show)
  411. return {
  412. id = show.id type = show.type kind = titleKind(&show) title = show.title year = y != null ? y : ''
  413. titleYear = titleWithYear(&show) href = titlePath(&show) posterName = posterName(&show)
  414. }
  415. }
  416. // tracker#46 (mission 046): what the PERSON page needs of a title, per title id — { id mergedInto public title year release href
  417. // posterName typeLabel typeClass }. The person page used to fetch every credit's WHOLE title record (cast + crew, up to 300
  418. // entries each: 311 decoded records for Tom Hanks) on every request — the allocation fed the byte-triggered GC (a 6 s+ pause
  419. // on the live heap). Filled at the first ask, rebuilt by `refreshTitleCaches` (every writer of a title calls it); returned, never copied.
  420. static creditRowCache = {}
  421. static creditRowFrom = (&show) => {
  422. y = showYear(&show)
  423. return { id = show.id mergedInto = show.mergedInto public = isPublicTitle(&show) title = show.title year = y != null ? y : ''
  424. release = textOr(&show.release) href = titlePath(&show) posterName = posterName(&show) typeLabel = typeWordOf(&show) typeClass = typeClassOf(&show) }
  425. }
  426. static creditRowOf = (&id) => {
  427. if (id == null) { return null }
  428. if (creditRowCache[id] != null) { return creditRowCache[id] }
  429. show = showsTable.fetch(id)
  430. if (show == null) { return null }
  431. if (cacheCount.creditRow >= cacheLimit.creditRow) {
  432. for (k of creditRowCache.keys()) { delete creditRowCache[k] }
  433. cacheCount.creditRow = 0
  434. }
  435. creditRowCache[id] = creditRowFrom(&show)
  436. cacheCount.creditRow = cacheCount.creditRow + 1
  437. return creditRowCache[id]
  438. }
  439. // the row of the title a page shows for this id: the keeper of a merged tombstone (chain followed, at most 5 steps, like liveShowOf)
  440. static creditRowLive = (&id) => {
  441. let r = creditRowOf(&id)
  442. let n = 0
  443. while (r != null && r.mergedInto != null && n < 5) {
  444. r = creditRowOf(&r.mergedInto)
  445. n = n + 1
  446. }
  447. return r
  448. }
  449. // GC1 measurement (TRACKER_QSTATS=1, jobs.hl): how many entries the request caches hold
  450. static cacheSizes = () => {
  451. return { card = cardCache.keys().length episodeRows = episodeRowsCache.keys().length episodeKey = episodeKeyCache.keys().length creditRow = creditRowCache.keys().length personLink = personLinkCache.keys().length }
  452. }
  453. static cardOf = (&id) => {
  454. if (id == null) { return null }
  455. if (cardCache[id] != null) { return cardCache[id] }
  456. show = showsTable.fetch(id)
  457. if (show == null) { return null }
  458. if (cacheCount.card >= cacheLimit.card) {
  459. for (k of cardCache.keys()) { delete cardCache[k] }
  460. cacheCount.card = 0
  461. }
  462. cardCache[id] = cardFrom(&show)
  463. cacheCount.card = cacheCount.card + 1
  464. return cardCache[id]
  465. }
  466. static episodeRowsFrom = (&show) => {
  467. out = []
  468. if (show.seasons == null) { return out }
  469. // loop names apart from the row's own `s`/`e` keys: inside an object literal a key set earlier shadows the variable
  470. for (sn of seasonsOfShow(&show)) {
  471. for (ep of episodesOfSeason(&sn)) {
  472. out.push({ id = ep.id s = ep.seasonNumber e = ep.episodeNumber title = ep.title != null ? ep.title : '' release = ep.release })
  473. }
  474. }
  475. return out
  476. }
  477. static episodeRowsOf = (&id) => {
  478. if (id == null) { return [] }
  479. if (episodeRowsCache[id] != null) { return episodeRowsCache[id] }
  480. show = showsTable.fetch(id)
  481. if (show == null) { return [] }
  482. if (cacheCount.episodeRows >= cacheLimit.episodeRows) {
  483. for (k of episodeRowsCache.keys()) { delete episodeRowsCache[k] }
  484. cacheCount.episodeRows = 0
  485. }
  486. episodeRowsCache[id] = episodeRowsFrom(&show)
  487. cacheCount.episodeRows = cacheCount.episodeRows + 1
  488. return episodeRowsCache[id]
  489. }
  490. // an episode that is not stored is { show = null } (never fetched again)
  491. static episodeKeyOf = (&id) => {
  492. if (id == null) { return { show = null s = null e = null } }
  493. if (episodeKeyCache[id] != null) { return episodeKeyCache[id] }
  494. ep = episodesTable.fetch(id)
  495. if (cacheCount.episodeKey >= cacheLimit.episodeKey) {
  496. for (k of episodeKeyCache.keys()) { delete episodeKeyCache[k] }
  497. cacheCount.episodeKey = 0
  498. }
  499. cacheCount.episodeKey = cacheCount.episodeKey + 1
  500. episodeKeyCache[id] = ep != null ? { show = ep.show s = ep.seasonNumber e = ep.episodeNumber } : { show = null s = null e = null }
  501. return episodeKeyCache[id]
  502. }
  503. // a title changed (catalog.hl refreshCatalogShow): its cached entries again from the stored record; the episode keys of its
  504. // episodes from the new rows (numbers the sync changed). Keys of a title nobody follows (no rows cached) are not refreshed —
  505. // /my/series only reads followed titles, and warmTitleCaches covers every followed one at boot.
  506. static refreshTitleCaches = (&show) => {
  507. // tracker#42: its slugs into the slug map (a new title's page is found without a scan)
  508. noteSlugsOf(&show)
  509. if (cardCache[show.id] != null) { cardCache[show.id] = cardFrom(&show) }
  510. if (creditRowCache[show.id] != null) { creditRowCache[show.id] = creditRowFrom(&show) }
  511. if (episodeRowsCache[show.id] != null) {
  512. episodeRowsCache[show.id] = episodeRowsFrom(&show)
  513. sid = show.id
  514. for (r of episodeRowsOf(&sid)) {
  515. if (episodeKeyCache[r.id] != null) { episodeKeyCache[r.id] = { show = sid s = r.s e = r.e } }
  516. }
  517. }
  518. return null
  519. }
  520. // project.hl at boot: the titles anyone follows and every watched episode, so the first /my/ load after a start is not the one
  521. // that fills them
  522. static warmTitleCaches = (&ids) => {
  523. let n = 0
  524. for (id of ids) {
  525. if (cardOf(&id) != null) { episodeRowsOf(&id) n = n + 1 }
  526. }
  527. return n
  528. }
  529. static warmEpisodeKeys = (&ids) => {
  530. for (id of ids) { episodeKeyOf(&id) }
  531. return ids.length
  532. }
  533. // merge.hl (tracker#31): an episode that moved to another title — its key is read again at the next ask
  534. static forgetEpisodeKey = (&id) => {
  535. episodeKeyCache[id] = null
  536. return null
  537. }
  538. // ---- the show on other sites (tracker.worldapi.org#12) ------------------------------------------
  539. // the header's link icons: TMDB, IMDb, TheTVDB, TVmaze — ONLY for the ids the show has; a movie (`type = 'movie'`)
  540. // gets TMDB + IMDb. TheTVDB's id form is `/dereferrer/series/<id>` (checked 2026-10-01: it and the old
  541. // `?tab=series&id=` both 301 to the slug page); the others are the sites' own id URLs (they too 301 to a slug).
  542. static externalLinksOf = (&show) => {
  543. if (show == null) { return [] }
  544. out = []
  545. movie = show.type == 'movie'
  546. if (hasId(&show.tmdbId)) { out.push({ site = 'tmdb' label = 'TMDB' title = 'On TMDB' href = 'https://www.themoviedb.org/' + (movie ? 'movie/' : 'tv/') + show.tmdbId }) }
  547. if (hasId(&show.imdbId)) { out.push({ site = 'imdb' label = 'IMDb' title = 'On IMDb' href = 'https://www.imdb.com/title/' + show.imdbId + '/' }) }
  548. if (!movie && hasId(&show.tvdbId)) { out.push({ site = 'tvdb' label = 'TVDB' title = 'On TheTVDB' href = 'https://thetvdb.com/dereferrer/series/' + show.tvdbId }) }
  549. if (!movie && hasId(&show.tvmzId)) { out.push({ site = 'tvmaze' label = 'TVmaze' title = 'On TVmaze' href = 'https://www.tvmaze.com/shows/' + show.tvmzId }) }
  550. return out
  551. }
  552. // ---- title page rows and actions (tracker#59; moved from components/show.hl) --------------------
  553. static initialCollapsed = (&seasons) => {
  554. m = {}
  555. let i = 0
  556. while (i < seasons.length) {
  557. // mobile audit MK: a season of more than 150 episodes starts closed too (a soap whose 1,175 episodes are ONE season made a 69,000 px page
  558. // of 1,200 tap targets); a tap on its header opens it
  559. if (i > 0 || seasons[i].episodes.length > 150) { m[seasons[i].id] = true }
  560. i = i + 1
  561. }
  562. return m
  563. }
  564. static genreRowsOf = (&show) => {
  565. if (show == null) { return [] }
  566. out = []
  567. for (gid of show.genres) {
  568. g = genreById(&gid)
  569. if (g != null) { out.push({ id = g.id name = g.name href = '/genres/' + g.urlSegment }) }
  570. }
  571. return out
  572. }
  573. // tracker#28: how many names show before "Show all" (cast; per crew job)
  574. static castShown = 20
  575. static crewShown = 6
  576. // the cast as flat rows (no nested for, see THE ROWS above; tracker#42: people by shows.hl personLinkOf, not whole records): `isPerson` rows { name, href, roleText (' (Character)' or ''),
  577. // itemClass } and before the first guest one `isLabel` row "Guest stars". itemClass: `more` = hidden until "Show all", `end` =
  578. // no comma after it (the last of a group), `cut` = the last one shown while collapsed (no comma then)
  579. static castRowsOf = (show) => {
  580. people = []
  581. for (c of listOr(&show.cast)) {
  582. p = c != null && c.person != null ? personLinkOf(&c.person) : null
  583. // mission 062: a guest without a person record — the link creates it on the first open (project.hl guestRoute)
  584. if (p != null) { people.push({ name = c.actor != null ? c.actor : p.name href = '/person/' + p.urlSegment role = c.character != null ? c.character : '' guest = c.guest == true }) }
  585. else if (c != null && c.person == null && c.tmdbId != null && c.actor != null) { people.push({ name = c.actor href = '/person/tmdb/' + c.tmdbId + '?show=' + show.id role = c.character != null ? c.character : '' guest = true }) }
  586. }
  587. out = []
  588. let k = 0
  589. let guests = false
  590. while (k < people.length) {
  591. let c = people[k]
  592. if (c.guest && !guests && k > 0) {
  593. guests = true
  594. out.push({ isLabel = true isPerson = false text = 'Guest stars' name = '' href = '' roleText = '' itemClass = k >= castShown ? 'more' : '' })
  595. }
  596. last = k == people.length - 1 || (people[k + 1].guest && !c.guest)
  597. cls = (k >= castShown ? ' more' : '') + (last ? ' end' : '') + (k == castShown - 1 ? ' cut' : '')
  598. out.push({ isLabel = false isPerson = true text = '' name = c.name href = c.href roleText = c.role != '' ? ' (' + c.role + ')' : '' itemClass = 'artist-link' + cls })
  599. k = k + 1
  600. }
  601. return out
  602. }
  603. static castCountOf = (&rows) => {
  604. let n = 0
  605. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  606. return n
  607. }
  608. static crewLabels = { creator = 'Created by' director = 'Directed by' writer = 'Written by' screenplay = 'Screenplay' story = 'Story' composer = 'Music' }
  609. // the crew as flat rows: per job (in stored order) an `isLabel` row, then its people (itemClass as for the cast, `more` after
  610. // the first crewShown of a job)
  611. static crewRowsOf = (&show) => {
  612. people = []
  613. for (c of listOr(&show.crew)) {
  614. p = c != null ? personLinkOf(&c.person) : null
  615. if (p != null && crewLabels[c.job] != null) { people.push({ name = c.name != null ? c.name : p.name href = '/person/' + p.urlSegment job = c.job }) }
  616. }
  617. out = []
  618. let k = 0
  619. let inJob = 0
  620. while (k < people.length) {
  621. let c = people[k]
  622. if (k == 0 || people[k - 1].job != c.job) {
  623. inJob = 0
  624. out.push({ isLabel = true isPerson = false text = crewLabels[c.job] name = '' href = '' itemClass = '' })
  625. }
  626. last = k == people.length - 1 || people[k + 1].job != c.job
  627. out.push({ isLabel = false isPerson = true text = '' name = c.name href = c.href itemClass = 'crew-link' + (inJob >= crewShown ? ' more' : '') + (last ? ' end' : '') + (inJob == crewShown - 1 ? ' cut' : '') })
  628. inJob = inJob + 1
  629. k = k + 1
  630. }
  631. return out
  632. }
  633. // how many crew names are hidden while collapsed (0 = no toggle) and how many there are
  634. static crewHiddenOf = (&rows) => {
  635. let n = 0
  636. for (r of rows) { if (r.isPerson && r.itemClass.includes(' more')) { n = n + 1 } }
  637. return n
  638. }
  639. static crewCountOf = (&rows) => {
  640. let n = 0
  641. for (r of rows) { if (r.isPerson) { n = n + 1 } }
  642. return n
  643. }
  644. // a View attribute must be a literal, a member or a field path — never an inline expression — so
  645. // every ternary (watched -> icon class, collapsed -> row class) is resolved HERE, once, into a
  646. // plain field the View just reads (row.watchClass, row.rowClass); `watchClassOf` itself lives in
  647. // watches.hl (shared with /unwatched and /schedule, "reuse, don't copy")
  648. // #22: an episode's air date as the lists show it ('YYYY-MM-DD'), '' when it has none
  649. static airDateOf = (&e) => { return e.release != null && hlTypeName(e.release) == 'String' ? e.release : '' }
  650. static buildRows = (&show, &uid, collapsed) => {
  651. // GC1: the user's kept watched set (watches.hl watchedSetOf, rebuilt after their next write), not a new one built from a by-value copy of
  652. // every watch row (12,866 rows on the creator's data) on every page and every check click
  653. watched = uid != null ? watchedSetOf(&uid) : {}
  654. out = []
  655. for (s of seasonsOfShow(&show)) {
  656. isCollapsed = collapsed[s.id] == true
  657. label = s.title != null && s.title != '' ? s.title : 'Season ' + s.seasonNumber
  658. seasonWatched = seasonAllWatched(&s, &watched)
  659. out.push({ kind = 'season' isSeason = true isEpisode = false isSkeleton = false @id = s.id id = s.id skeletonCount = s.episodes.length < 8 ? s.episodes.length : 8 label = label episodeCountText = s.episodes.length == 1 ? '1 episode' : s.episodes.length + ' episodes' watched = seasonWatched watchClass = watchClassOf(&seasonWatched) collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' })
  660. if (!isCollapsed) {
  661. for (e of episodesOfSeason(&s)) {
  662. epWatched = watched['episode:' + e.id] == true
  663. out.push({ kind = 'episode' isSeason = false isEpisode = true isSkeleton = false id = e.id seasonId = s.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' airDate = airDateOf(&e) watched = epWatched watchClass = watchClassOf(&epWatched) })
  664. }
  665. }
  666. }
  667. return out
  668. }
  669. // what the client marks the rows of a season it opens with (tracker#17) — only this show's, never the user's whole watch
  670. // list (every member is shipped to the browser). Per season with a watched episode: `{ all, except }` — `all` = most of
  671. // it is watched, then `except` holds the UNwatched ids, else the watched ones (a fully watched 142-episode season is
  672. // `{ all = true except = {} }`, not 142 ids). No entry = nothing watched.
  673. static watchedEpisodesOf = (&show, &uid) => {
  674. m = {}
  675. if (uid == null) { return m }
  676. watched = watchedSetOf(&uid)
  677. for (s of seasonsOfShow(&show)) {
  678. yes = {}
  679. no = {}
  680. let n = 0
  681. for (eid of s.episodes) {
  682. if (watched['episode:' + eid] == true) { yes[eid] = true n = n + 1 } else { no[eid] = true }
  683. }
  684. if (n > 0) { m[s.id] = n * 2 > s.episodes.length ? { all = true except = no } : { all = false except = yes } }
  685. }
  686. return m
  687. }
  688. // is this episode watched, by that per-season shape (client-side, pure)
  689. static watchedIn = (&entry, &episodeId) => {
  690. if (entry == null) { return false }
  691. listed = entry.except[episodeId] == true
  692. return entry.all ? !listed : listed
  693. }
  694. // ---- the rows as the CLIENT changes them (tracker#17) — pure: no import is reached, so they run in the browser ----------
  695. // (`watchClassOf` is an import of the mpackdb-backed watches.hl, so `filledRows` writes its two classes itself)
  696. static seasonRowAs = (&row, &isCollapsed) => {
  697. return { kind = 'season' isSeason = true isEpisode = false isSkeleton = false @id = row.id id = row.id skeletonCount = row.skeletonCount label = row.label episodeCountText = row.episodeCountText watched = row.watched watchClass = row.watchClass collapsed = isCollapsed rowClass = isCollapsed ? 'collapsed' : 'expanded' }
  698. }
  699. // the season opened: its caret up at once, `skeletonCount` placeholder rows under it
  700. static openingRows = (&rows, seasonId) => {
  701. out = []
  702. for (row of rows) {
  703. if (row.isSeason && row.id == seasonId) {
  704. out.push(seasonRowAs(&row, false))
  705. let i = 0
  706. while (i < row.skeletonCount) {
  707. out.push({ kind = 'skeleton' isSeason = false isEpisode = false isSkeleton = true id = seasonId + '-skeleton-' + i seasonId = seasonId })
  708. i = i + 1
  709. }
  710. } else { out.push(row) }
  711. }
  712. return out
  713. }
  714. // the season closed (rows are keyed records: `id` is the key, `@id` marks the lookup of upsert/remove, hybriel#331): its caret
  715. // down = ONE upsert of its row; its episode (and skeleton) rows = one `remove(id = …)` each. The other rows are not touched.
  716. static closeSeasonRows = (&rows, &seasonId) => {
  717. gone = []
  718. let season = null
  719. for (row of rows) {
  720. if (row.isSeason && row.id == seasonId) { season = seasonRowAs(&row, true) }
  721. else if (!row.isSeason && row.seasonId == seasonId) { gone.push(row.id) }
  722. }
  723. if (season != null) { rows.upsert(season) }
  724. for (g of gone) { rows.remove(id = g) }
  725. }
  726. // the episodes arrived: they replace the season's skeleton rows. No skeleton of it left (closed meanwhile, or a watch face
  727. // already rebuilt every row) → the rows stay as they are (no double rows)
  728. static filledRows = (&rows, seasonId, &episodes, watched) => {
  729. out = []
  730. let done = false
  731. for (row of rows) {
  732. if (row.isSkeleton && row.seasonId == seasonId) {
  733. if (!done) {
  734. for (e of episodes) {
  735. w = watchedIn(&watched[seasonId], &e.id)
  736. out.push({ kind = 'episode' isSeason = false isEpisode = true isSkeleton = false id = e.id seasonId = seasonId episodeNumber = e.episodeNumber title = e.title airDate = e.airDate watched = w watchClass = w ? 'checkicon solid' : 'checkicon regular' })
  737. }
  738. done = true
  739. }
  740. } else { out.push(row) }
  741. }
  742. return out
  743. }
  744. // a LOCAL static like buildRows (an imported mpackdb helper called straight from a member's initializer came back false
  745. // after a client-side navigation to the page — the gate's follow check)
  746. static followingOf = (&show, &uid) => {
  747. if (show == null) { return false }
  748. return uid != null && isFollowing(&uid, &show.id)
  749. }
  750. // #24: has this user watched this movie (a watch `movie:<title id>`)?
  751. static movieWatchedOf = (&show, &uid) => {
  752. if (show == null) { return false }
  753. if (uid == null) { return false }
  754. rows = watchesOfUser(&uid)
  755. return isWatched(&rows, 'movie', &show.id)
  756. }
  757. // mission 056: an ADULT title's page (TMDB's flag `adult == true`, mission 054) is "Not found" for everyone who does not
  758. // follow it (signed out too); a follower sees it as before. Unknown (`null`) is not hidden here — only in the lists.
  759. // With hybriel ≥ 73267707 (#121/#122) `showRow`/`found` are server sites re-derived after every session face with the page's
  760. // slug, so an Unfollow on the page hides it at once (the gate proves it; the old build left the page up until a reload).
  761. // Mission 054's try (`found = … && !adultHiddenFor(showRow, me)`, `collapsed`/`rows` from `found`) broke the checks.
  762. static adultHiddenFor = (&show, &uid) => { return show.adult == true && !followingOf(&show, &uid) }
  763. // the page's show — null when there is none OR it is hidden for this user: every member is shipped to the browser, so the
  764. // row of a hidden title must never be one
  765. static visibleShow = (&slug, &uid) => {
  766. s = showBySlug(&slug)
  767. return s != null && adultHiddenFor(&s, &uid) ? null : s
  768. }
  769. // tracker.worldapi.org#19 (mission 066): the franchise widget(s), one per timeline the title is in (components/franchisewidget.hl)
  770. static franchiseWidgetsOf = (&show) => {
  771. if (show == null) { return [] }
  772. return widgetsOf(&show.id)
  773. }
  774. // tracker#33 (mission 032): a movie's release date and runtime under its title — "17 September 2026 · 7 min", "… · 2 h 15 min";
  775. // what is missing is left out ('' = no line)
  776. static runtimeText = (&m) => {
  777. if (m == null || hlTypeName(m) != 'Number' || m <= 0) { return '' }
  778. mins = m % 60
  779. hours = (m - mins) / 60
  780. if (hours == 0) { return mins + ' min' }
  781. return mins == 0 ? hours + ' h' : hours + ' h ' + mins + ' min'
  782. }
  783. static movieFactsOf = (&s) => {
  784. if (s == null) { return '' }
  785. if (s.type != 'movie') { return '' }
  786. parts = []
  787. d = dateText(&s.release)
  788. if (d != null) { parts.push(d) }
  789. r = runtimeText(&s.runtime)
  790. if (r != '') { parts.push(r) }
  791. return parts.join(' · ')
  792. }
  793. // mission 062: what the page shows of the title, as a SMALL object — `showRow` reads the session, so hl:web ships it with the page
  794. // AND re-sends it after every watch/follow click (SESSION SYNC below): the whole record was ~1 MB on The Simpsons (300 cast + crew
  795. // entries). null = not found / hidden.
  796. static pageShowOf = (&slug, &uid) => {
  797. s = visibleShow(&slug, &uid)
  798. if (s == null) { return null }
  799. movie = s.type == 'movie'
  800. st = statusOf(&s)
  801. return { id = s.id title = s.title summary = summaryOf(&s) type = s.type adult = s.adult == true shortId = s.shortId != null ? '' + s.shortId : '' statusText = st.text statusTone = st.tone
  802. poster = posterName(&s) genreRows = genreRowsOf(&s) linkRows = externalLinksOf(&s) completing = completingOf(&s) following = followingOf(&s, &uid)
  803. movieWatched = movie ? movieWatchedOf(&s, &uid) : false facts = movieFactsOf(&s) }
  804. }
  805. // the seasons/episodes rows and the per-season watch state by the slug (the record itself stays on the server)
  806. static rowsOfSlug = (&slug, &uid, &collapsed) => {
  807. s = showBySlug(&slug)
  808. return s != null ? buildRows(&s, &uid, collapsed) : []
  809. }
  810. static watchedEpisodesOfSlug = (&slug, &uid) => {
  811. s = showBySlug(&slug)
  812. return s != null ? watchedEpisodesOf(&s, &uid) : {}
  813. }
  814. // the initial open/closed seasons and the title's kind (tracker#20/#21: the heading's type word) from the SLUG alone (not from
  815. // `showRow`, which reads the session — see `collapsed`) — one slug lookup for both
  816. static slugInfoOf = (&slug) => {
  817. s = showBySlug(&slug)
  818. return s != null ? { collapsed = initialCollapsed(seasonsOfShow(&s)) kind = titleKind(&s) canonical = titlePath(&s) } : { collapsed = {} kind = 'series' canonical = '' }
  819. }
  820. // mission 062: the cast and crew rows by the SLUG alone (not from `showRow`, which reads the session — see `castRows`). An
  821. // ADULT title (its page only for its followers) shows none: every member is shipped to the browser, and adult titles never get
  822. // credits anyway (details.hl skips them; at most a migrated cast)
  823. static publicShowOf = (&slug) => {
  824. s = showBySlug(&slug)
  825. return s != null && s.adult != true ? s : null
  826. }
  827. static castOfSlug = (&slug) => {
  828. s = publicShowOf(&slug)
  829. return s != null ? castRowsOf(s) : []
  830. }
  831. static crewOfSlug = (&slug) => {
  832. s = publicShowOf(&slug)
  833. return s != null ? crewRowsOf(&s) : []
  834. }
  835. static completingOf = (&show) => {
  836. if (show == null) { return false }
  837. return needsDetails(&show)
  838. }
  839. static showRowsOf = (slug, collapsed, uid) => {
  840. show = showBySlug(&slug)
  841. if (show == null || adultHiddenFor(&show, &uid)) { return { error = 'no such show' } }
  842. return { ok = true rows = buildRows(&show, &uid, collapsed) }
  843. }
  844. static showSeasonEpisodesOf = (seasonId) => {
  845. if (seasonId == null || hlTypeName(seasonId) != 'String') { return { error = 'no such season' } }
  846. season = seasonById(&seasonId)
  847. if (season == null) { return { error = 'no such season' } }
  848. show = showById(&season.show)
  849. if (show == null || show.adult == true) { return { error = 'no such season' } }
  850. out = []
  851. for (e of episodesOfSeason(&season)) { out.push({ id = e.id episodeNumber = e.episodeNumber title = e.title != null ? e.title : '' airDate = airDateOf(&e) }) }
  852. return { ok = true episodes = out }
  853. }
  854. static showToggleEpisodeOf = (slug, episodeId, collapsed, withRows, uid) => {
  855. show = showBySlug(&slug)
  856. if (show == null) { return { error = 'no such show' } }
  857. if (uid == null) { return { error = 'you are not signed in' } }
  858. if (adultHiddenFor(&show, &uid)) { return { error = 'no such show' } }
  859. // mission SK: only an episode OF THIS SHOW — the id is the peer's (any text became a watch row before)
  860. ep = episodeId != null && hlTypeName(episodeId) == 'String' ? episodeById(&episodeId) : null
  861. if (ep == null || ep.show != show.id) { return { error = 'no such episode' } }
  862. if (toggleWatched(&uid, 'episode', &episodeId) == null) { return { error = 'could not save the watch' } }
  863. return withRows == true ? { ok = true rows = buildRows(&show, &uid, collapsed) } : { ok = true }
  864. }
  865. static showToggleSeasonOf = (slug, seasonId, collapsed, withRows, uid) => {
  866. show = showBySlug(&slug)
  867. if (show == null) { return { error = 'no such show' } }
  868. if (uid == null) { return { error = 'you are not signed in' } }
  869. if (adultHiddenFor(&show, &uid)) { return { error = 'no such show' } }
  870. season = seasonId != null && hlTypeName(seasonId) == 'String' ? seasonById(&seasonId) : null
  871. if (season == null || season.show != show.id) { return { error = 'no such season' } }
  872. // #23: not all episodes watched → watch them all; all watched → unwatch them all (lib/watches.hl)
  873. if (toggleSeasonWatched(&uid, &season) == null) { return { error = 'could not save the watch' } }
  874. return withRows == true ? { ok = true rows = buildRows(&show, &uid, collapsed) } : { ok = true }
  875. }
  876. static showToggleMovieOf = (slug, uid) => {
  877. show = showBySlug(&slug)
  878. if (show == null || show.type != 'movie') { return { error = 'no such movie' } }
  879. if (uid == null) { return { error = 'you are not signed in' } }
  880. if (adultHiddenFor(&show, &uid)) { return { error = 'no such movie' } }
  881. watched = toggleWatched(&uid, 'movie', &show.id)
  882. if (watched == null) { return { error = 'could not save the watch' } }
  883. return { ok = true watched = watched }
  884. }
  885. static showToggleFollowOf = (slug, uid) => {
  886. show = showBySlug(&slug)
  887. if (show == null) { return { error = 'no such show' } }
  888. if (uid == null) { return { error = 'you are not signed in' } }
  889. // mission SK: an adult title is its followers' only — nobody else may start following it (that opened its page to anyone who
  890. // guessed the slug); a follower may still stop
  891. if (adultHiddenFor(&show, &uid)) { return { error = 'no such show' } }
  892. follow = toggleFollowed(&uid, &show.id)
  893. if (follow == null) { return { error = 'could not save the follow' } }
  894. return { ok = true following = follow }
  895. }

Branches

Latest commits

  • 17feb7abHM55 WIP: hm54-fill re-applied on main; browser gate fails at ep3 toggleTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
  • b9c7c3c8Merge branch 'records-dp74' into mainTracker
  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
  • 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
  • 0b86324aMerge branch 'records-dp73' into mainTracker
  • 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
  • 613ae0ecMerge branch 'bs3' into mainTracker