gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf2b00674f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmref2b00674/shows.hl

8.6 KB

  1. // shows.hl — READ-ONLY data access 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. // No declared index beyond the migration's own ['!oldId'] (opening a table with indexes it wasn't
  7. // created with is untested territory, hybriel#21 "opening a table rewrites its files") — a slug
  8. // lookup is a linear scan of ~9500 shows, cheap for one page load.
  9. import { MPackDB } from 'hl:mpackdb'
  10. import { env } from 'hl:proc'
  11. import { exists } from 'hl:fs'
  12. static envOr = (name, fallback) => {
  13. let v = env(name)
  14. return v != null && v.trim() != '' ? v.trim() : fallback
  15. }
  16. static storageDir = envOr('TRACKER_STORAGE', './storage/mpackdb')
  17. static genresTable = new MPackDB(file = storageDir + '/genres.db', primaryKey = '@id', indexes = ['!oldId'])
  18. static personsTable = new MPackDB(file = storageDir + '/persons.db', primaryKey = '@id', indexes = ['!oldId'])
  19. static showsTable = new MPackDB(file = storageDir + '/shows.db', primaryKey = '@id', indexes = ['!oldId'])
  20. static seasonsTable = new MPackDB(file = storageDir + '/seasons.db', primaryKey = '@id', indexes = ['!oldId'])
  21. static episodesTable = new MPackDB(file = storageDir + '/episodes.db', primaryKey = '@id', indexes = ['!oldId'])
  22. // 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
  23. // every record per call (twice per show page) decoded every title's cast + crew: 82 ms per call on the live copy before the
  24. // credits, growing with them. A slug the map does not know (a title added since: import, filmography) costs one scan as before
  25. // and is remembered; slugs never change. (Flat static written key by key, like people.hl's maps.)
  26. static slugIds = {}
  27. static slugIdsBuilt = { yes = false }
  28. static showBySlug = (slug) => {
  29. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  30. if (!slugIdsBuilt.yes) {
  31. for (s of showsTable.find(null, null)) { if (s.urlSegment != null) { slugIds[s.urlSegment] = s.id } }
  32. slugIdsBuilt.yes = true
  33. }
  34. let id = slugIds[slug]
  35. if (id != null) {
  36. let hit = showsTable.fetch(id)
  37. if (hit != null && hit.urlSegment == slug) { return hit }
  38. }
  39. for (s of showsTable.find(null, null)) {
  40. if (s.urlSegment == slug) {
  41. slugIds[slug] = s.id
  42. return s
  43. }
  44. }
  45. return null
  46. }
  47. static genreById = (id) => { return id == null ? null : genresTable.fetch(id) }
  48. // /genres/<genre> (mission 058): the genre with this urlSegment ('Action', 'Sci-Fi-Fantasy'), exact first, else ignoring case
  49. // — a scan of the genres table (27 rows)
  50. static genreBySlug = (slug) => {
  51. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  52. let lower = slug.toLowerCase()
  53. let loose = null
  54. for (g of genresTable.find(null, null)) {
  55. if (g.urlSegment == slug) { return g }
  56. if (loose == null && g.urlSegment != null && ('' + g.urlSegment).toLowerCase() == lower) { loose = g }
  57. }
  58. return loose
  59. }
  60. static personById = (id) => { return id == null ? null : personsTable.fetch(id) }
  61. static seasonById = (id) => { return id == null ? null : seasonsTable.fetch(id) }
  62. static showById = (id) => { return id == null ? null : showsTable.fetch(id) }
  63. static episodeById = (id) => { return id == null ? null : episodesTable.fetch(id) }
  64. // EVERY show / episode (tracker.worldapi.org#13, catalog.hl): read ONCE when the app starts, to build the public lists —
  65. // never per request
  66. static allShows = () => { return showsTable.find(null, null) }
  67. static allEpisodes = () => { return episodesTable.find(null, null) }
  68. // insertion sort, hand-written (no list sort(), hybriel#1) — a show has a handful of seasons at most
  69. static insertDesc = (sorted, s) => {
  70. let out = []
  71. let inserted = false
  72. for (x of sorted) {
  73. if (!inserted && s.seasonNumber >= x.seasonNumber) { out.push(s) inserted = true }
  74. out.push(x)
  75. }
  76. if (!inserted) { out.push(s) }
  77. return out
  78. }
  79. static insertAsc = (sorted, e) => {
  80. let out = []
  81. let inserted = false
  82. for (x of sorted) {
  83. if (!inserted && e.episodeNumber <= x.episodeNumber) { out.push(e) inserted = true }
  84. out.push(x)
  85. }
  86. if (!inserted) { out.push(e) }
  87. return out
  88. }
  89. // a show's seasons, latest (highest seasonNumber) first — creator: "all seasons in reverse order,
  90. // latest on top"
  91. static seasonsOfShow = (show) => {
  92. let sorted = []
  93. for (id of show.seasons) {
  94. let s = seasonsTable.fetch(id)
  95. if (s != null) { sorted = insertDesc(sorted, s) }
  96. }
  97. return sorted
  98. }
  99. // a season's episodes, in episode-number order
  100. static episodesOfSeason = (season) => {
  101. let sorted = []
  102. for (id of season.episodes) {
  103. let e = episodesTable.fetch(id)
  104. if (e != null) { sorted = insertAsc(sorted, e) }
  105. }
  106. return sorted
  107. }
  108. // ---- labels shared by every list (tracker.worldapi.org#8) -------------------------------------
  109. static pad2 = (n) => {
  110. let s = '' + n
  111. while (s.length < 2) { s = '0' + s }
  112. return s
  113. }
  114. // an episode as `S01E01` (creator: "write it like that: S01E01") — /my/shows, /my/unwatched, /my/schedule
  115. static episodeCode = (seasonNumber, episodeNumber) => { return 'S' + pad2(seasonNumber) + 'E' + pad2(episodeNumber) }
  116. // the show's year: `year`, else the first 4 characters of `release` ('YYYY-MM-DD'; 197 migrated shows have
  117. // no year, a few of those an empty release) — null when neither gives one
  118. static showYear = (show) => {
  119. if (show.year != null) { return '' + show.year }
  120. if (show.release != null && hlTypeName(show.release) == 'String' && show.release.length >= 4) { return show.release.slice(0, 4) }
  121. return null
  122. }
  123. // a show's title as every list shows it: `Doctor Who (2005)` (creator: so same-named shows can be told apart)
  124. static titleWithYear = (show) => {
  125. let y = showYear(show)
  126. return y != null ? show.title + ' (' + y + ')' : show.title
  127. }
  128. // ---- adult titles (mission 054) -----------------------------------------------------------------
  129. // `adult` on every title: true / false from TMDB, null = not known yet (the migrated rows; the app's backfill, tmdbsync.hl
  130. // `backfillTitle`, asks TMDB). The PUBLIC lists (catalog.hl: homepage rows, /movies, /shows) and the search (search.hl) show
  131. // ONLY a title TMDB says is not adult — unknown counts as hidden. A title the user follows stays on /my/* and its page.
  132. static isPublicTitle = (show) => { return show != null && show.adult == false }
  133. // the poster file name (oldId + the migrated extension) — null when either is missing; served at
  134. // /posters/<name> (project.hl), which falls back to a placeholder when the file itself isn't there
  135. // yet (the real poster files are not part of the mongo export, see the report's `open`)
  136. static posterName = (show) => {
  137. if (show.oldId == null || show.image == null || show.image == '') { return null }
  138. return show.oldId + '.' + show.image
  139. }
  140. // the poster's URL for a LIST (/my/shows, tracker.worldapi.org#8): `/posters/<name>` only when the file really
  141. // is in storage/mpackdb/posters/ (project.hl posterRoute reads the same folder), else the ONE placeholder URL
  142. // `/posters/none` — the real data has no poster files yet, and 128 different URLs all answering the same
  143. // placeholder were 128 requests per page load (the browser can't cache them as one)
  144. static posterUrlOf = (show) => {
  145. let name = posterName(show)
  146. return name != null && exists(storageDir + '/posters/' + name) ? '/posters/' + name : '/posters/none'
  147. }
  148. // ---- the show on other sites (tracker.worldapi.org#12) ------------------------------------------
  149. // the header's link icons: TMDB, IMDb, TheTVDB, TVmaze — ONLY for the ids the show has; a movie (`type = 'movie'`)
  150. // gets TMDB + IMDb. TheTVDB's id form is `/dereferrer/series/<id>` (checked 2026-10-01: it and the old
  151. // `?tab=series&id=` both 301 to the slug page); the others are the sites' own id URLs (they too 301 to a slug).
  152. static hasExternalId = (v) => { return v != null && ('' + v).trim() != '' }
  153. static externalLinksOf = (show) => {
  154. let out = []
  155. let movie = show.type == 'movie'
  156. if (hasExternalId(show.tmdbId)) { out.push({ site = 'tmdb' label = 'TMDB' title = 'On TMDB' href = 'https://www.themoviedb.org/' + (movie ? 'movie/' : 'tv/') + show.tmdbId }) }
  157. if (hasExternalId(show.imdbId)) { out.push({ site = 'imdb' label = 'IMDb' title = 'On IMDb' href = 'https://www.imdb.com/title/' + show.imdbId + '/' }) }
  158. if (!movie && hasExternalId(show.tvdbId)) { out.push({ site = 'tvdb' label = 'TVDB' title = 'On TheTVDB' href = 'https://thetvdb.com/dereferrer/series/' + show.tvdbId }) }
  159. if (!movie && hasExternalId(show.tvmzId)) { out.push({ site = 'tvmaze' label = 'TVmaze' title = 'On TVmaze' href = 'https://www.tvmaze.com/shows/' + show.tvmzId }) }
  160. return out
  161. }

Branches

Latest commits

  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre