gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2b7fdd6c2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre2b7fdd6c/shows.hl

7.3 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
  23. static showBySlug = (slug) => {
  24. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  25. for (s of showsTable.find(null, null)) { if (s.urlSegment == slug) { return s } }
  26. return null
  27. }
  28. static genreById = (id) => { return id == null ? null : genresTable.fetch(id) }
  29. static personById = (id) => { return id == null ? null : personsTable.fetch(id) }
  30. static seasonById = (id) => { return id == null ? null : seasonsTable.fetch(id) }
  31. static showById = (id) => { return id == null ? null : showsTable.fetch(id) }
  32. static episodeById = (id) => { return id == null ? null : episodesTable.fetch(id) }
  33. // EVERY show / episode (tracker.worldapi.org#13, catalog.hl): read ONCE when the app starts, to build the public lists —
  34. // never per request
  35. static allShows = () => { return showsTable.find(null, null) }
  36. static allEpisodes = () => { return episodesTable.find(null, null) }
  37. // insertion sort, hand-written (no list sort(), hybriel#1) — a show has a handful of seasons at most
  38. static insertDesc = (sorted, s) => {
  39. let out = []
  40. let inserted = false
  41. for (x of sorted) {
  42. if (!inserted && s.seasonNumber >= x.seasonNumber) { out.push(s) inserted = true }
  43. out.push(x)
  44. }
  45. if (!inserted) { out.push(s) }
  46. return out
  47. }
  48. static insertAsc = (sorted, e) => {
  49. let out = []
  50. let inserted = false
  51. for (x of sorted) {
  52. if (!inserted && e.episodeNumber <= x.episodeNumber) { out.push(e) inserted = true }
  53. out.push(x)
  54. }
  55. if (!inserted) { out.push(e) }
  56. return out
  57. }
  58. // a show's seasons, latest (highest seasonNumber) first — creator: "all seasons in reverse order,
  59. // latest on top"
  60. static seasonsOfShow = (show) => {
  61. let sorted = []
  62. for (id of show.seasons) {
  63. let s = seasonsTable.fetch(id)
  64. if (s != null) { sorted = insertDesc(sorted, s) }
  65. }
  66. return sorted
  67. }
  68. // a season's episodes, in episode-number order
  69. static episodesOfSeason = (season) => {
  70. let sorted = []
  71. for (id of season.episodes) {
  72. let e = episodesTable.fetch(id)
  73. if (e != null) { sorted = insertAsc(sorted, e) }
  74. }
  75. return sorted
  76. }
  77. // ---- labels shared by every list (tracker.worldapi.org#8) -------------------------------------
  78. static pad2 = (n) => {
  79. let s = '' + n
  80. while (s.length < 2) { s = '0' + s }
  81. return s
  82. }
  83. // an episode as `S01E01` (creator: "write it like that: S01E01") — /my/shows, /my/unwatched, /my/schedule
  84. static episodeCode = (seasonNumber, episodeNumber) => { return 'S' + pad2(seasonNumber) + 'E' + pad2(episodeNumber) }
  85. // the show's year: `year`, else the first 4 characters of `release` ('YYYY-MM-DD'; 197 migrated shows have
  86. // no year, a few of those an empty release) — null when neither gives one
  87. static showYear = (show) => {
  88. if (show.year != null) { return '' + show.year }
  89. if (show.release != null && hlTypeName(show.release) == 'String' && show.release.length >= 4) { return show.release.slice(0, 4) }
  90. return null
  91. }
  92. // a show's title as every list shows it: `Doctor Who (2005)` (creator: so same-named shows can be told apart)
  93. static titleWithYear = (show) => {
  94. let y = showYear(show)
  95. return y != null ? show.title + ' (' + y + ')' : show.title
  96. }
  97. // ---- adult titles (mission 054) -----------------------------------------------------------------
  98. // `adult` on every title: true / false from TMDB, null = not known yet (the migrated rows; the app's backfill, tmdbsync.hl
  99. // `backfillTitle`, asks TMDB). The PUBLIC lists (catalog.hl: homepage rows, /movies, /shows) and the search (search.hl) show
  100. // ONLY a title TMDB says is not adult — unknown counts as hidden. A title the user follows stays on /my/* and its page.
  101. static isPublicTitle = (show) => { return show != null && show.adult == false }
  102. // the poster file name (oldId + the migrated extension) — null when either is missing; served at
  103. // /posters/<name> (project.hl), which falls back to a placeholder when the file itself isn't there
  104. // yet (the real poster files are not part of the mongo export, see the report's `open`)
  105. static posterName = (show) => {
  106. if (show.oldId == null || show.image == null || show.image == '') { return null }
  107. return show.oldId + '.' + show.image
  108. }
  109. // the poster's URL for a LIST (/my/shows, tracker.worldapi.org#8): `/posters/<name>` only when the file really
  110. // is in storage/mpackdb/posters/ (project.hl posterRoute reads the same folder), else the ONE placeholder URL
  111. // `/posters/none` — the real data has no poster files yet, and 128 different URLs all answering the same
  112. // placeholder were 128 requests per page load (the browser can't cache them as one)
  113. static posterUrlOf = (show) => {
  114. let name = posterName(show)
  115. return name != null && exists(storageDir + '/posters/' + name) ? '/posters/' + name : '/posters/none'
  116. }
  117. // ---- the show on other sites (tracker.worldapi.org#12) ------------------------------------------
  118. // the header's link icons: TMDB, IMDb, TheTVDB, TVmaze — ONLY for the ids the show has; a movie (`type = 'movie'`)
  119. // gets TMDB + IMDb. TheTVDB's id form is `/dereferrer/series/<id>` (checked 2026-10-01: it and the old
  120. // `?tab=series&id=` both 301 to the slug page); the others are the sites' own id URLs (they too 301 to a slug).
  121. static hasExternalId = (v) => { return v != null && ('' + v).trim() != '' }
  122. static externalLinksOf = (show) => {
  123. let out = []
  124. let movie = show.type == 'movie'
  125. if (hasExternalId(show.tmdbId)) { out.push({ site = 'tmdb' label = 'TMDB' title = 'On TMDB' href = 'https://www.themoviedb.org/' + (movie ? 'movie/' : 'tv/') + show.tmdbId }) }
  126. if (hasExternalId(show.imdbId)) { out.push({ site = 'imdb' label = 'IMDb' title = 'On IMDb' href = 'https://www.imdb.com/title/' + show.imdbId + '/' }) }
  127. if (!movie && hasExternalId(show.tvdbId)) { out.push({ site = 'tvdb' label = 'TVDB' title = 'On TheTVDB' href = 'https://thetvdb.com/dereferrer/series/' + show.tvdbId }) }
  128. if (!movie && hasExternalId(show.tvmzId)) { out.push({ site = 'tvmaze' label = 'TVmaze' title = 'On TVmaze' href = 'https://www.tvmaze.com/shows/' + show.tvmzId }) }
  129. return out
  130. }

Branches

Latest commits

  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre
  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 139fafd8tracker#16: short bio (4 lines, click = all), real-data check script, README + STATUSmre
  • 93be9476tracker#16: person pages /person/<slug> with the filmography fetched from TMDB on the first visit (step by step), gatemre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
  • b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
  • 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
  • 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
  • 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre
  • 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre