gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfbb903ccfbb903cctracker#33/#37 (mission 032): a title without a TMDB poster gets its backdrop (w780, posterFromBackdrop, shown 2:3 centre-cropped); movies store runtime, the page shows release date + runtime; art backfill (public titles without poster file / movies without runtime) and person photo backfill (tmdbProfile / photoCheck) as the last start jobs (TRACKER_ART, TRACKER_PHOTOS; off in every gate start); gates 379/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy: art 4977 titles in 42 min (115 posters, 15 backdrops, 4609 runtimes), The Remaining shows its backdrop + 7 minmrefbb903cc/lib/dailysync.hl

11.9 KB

  1. // lib/dailysync.hl — WHICH TITLES THE DAILY SYNC ASKS FOR (tracker.worldapi.org#18; deltasync.hl before mission 028). Creator:
  2. // "it checks every show in a request to the api? cause they have an endpoint that gives a delta on bulk". Before: 2 requests
  3. // per FOLLOWED show every day (256 for 126 shows), the other titles never. Now the daily run (jobs.hl syncTick,
  4. // tools/sync-tmdb.hl --delta) first asks what changed since the last run and syncs ONLY those titles of ours — followed or not:
  5. //
  6. // GET <TMDB_BASE_URL>/tv/changes?start_date=<last run day>&end_date=<today>&page=<n> changed TV ids, 100 per page
  7. // GET <TMDB_BASE_URL>/movie/changes?start_date=…&end_date=…&page=<n> changed movie ids, 100 per page
  8. // GET <TVMAZE_BASE_URL>/updates/shows?since=day|week|month { "<tvmaze id>": <updated at> }
  9. //
  10. // → intersected with our titles (search.hl's index: TMDB id by kind, TVmaze id — no table scan) → the sync's queue, FOLLOWED
  11. // titles first. One change-list request per clock step (jobs.hl), 260 ms per TMDB / 550 ms per TVmaze request between them.
  12. // A FOLLOWED title gets the full step (all seasons, TVmaze — as before #18); one NOBODY follows the light step (sync.hl
  13. // syncShowDelta: details, ids, poster, record, cast + only the seasons that can have changed, no TVmaze) — so TVmaze's list
  14. // only brings followed series — tracker#35 (mission 030): and, for a series NOBODY follows, its TVmaze STATUS (the page's pill
  15. // prefers TVmaze's): named by TVmaze's list alone → a status-only step (sync.hl syncTvmazeStatus, one TVmaze request), named by
  16. // both lists → the light step asks it too. `syncRunStep` picks the step.
  17. // Left out: titles without a TMDB id, incomplete ones (shows.hl isIncomplete — the details repair completes them) and ADULT
  18. // ones nobody follows (never public, their posters are not kept — mission 056).
  19. //
  20. // THE LAST RUN: `<storage>/sync-state.txt` = the day ('YYYY-MM-DD', UTC) the last finished run STARTED (its change window began
  21. // at 00:00 of that day, so two runs overlap by a few hours, never leave a gap). FULL WALK (every followed show, as before #18)
  22. // when there is no such day (the first run), when it is more than `maxDeltaDays` (14: TMDB's change lists reach 14 days back)
  23. // ago, or when a change list cannot be read (then the day is NOT advanced: the next run asks for the missed days too).
  24. import { fetch } from 'hl:fetch'
  25. import { now } from 'hl:time'
  26. import { readFile, writeFile, exists } from 'hl:fs'
  27. import { storageDir, textOr, hasId } from './util.hl'
  28. import { showsTable, isIncomplete } from './shows.hl'
  29. import { tmdbGet, tvmazeBase, numIdOr } from './tmdb.hl'
  30. import { syncShow, syncShowDelta, syncTvmazeStatus } from './sync.hl'
  31. import { dayNumber } from './sync-helpers.hl'
  32. import { allFollowedShowIds } from './follows.hl'
  33. import { titleIdByTmdb, titleIdByTvmaze } from './search.hl'
  34. static maxDeltaDays = 14
  35. // TMDB answers at most 500 pages of a list
  36. static maxPages = 500
  37. static stateFile = storageDir + '/sync-state.txt'
  38. // the day of the last finished run, or null
  39. static lastSyncDay = () => {
  40. if (!exists(stateFile)) { return null }
  41. t = readFile(stateFile)
  42. if (t == null || hlTypeName(t) != 'String') { return null }
  43. d = t.trim()
  44. return dayNumber(d) != null ? d.slice(0, 10) : null
  45. }
  46. static markSynced = (&day) => {
  47. writeFile(stateFile, day, 420)
  48. return true
  49. }
  50. // ---- the plan of one run (one run at a time: the app's clock or the tool) --------------------------------------------------
  51. // flat statics written key by key (like people.hl's maps); `run.no` tells this run's entries from older ones
  52. static run = { no = 0 mode = '' why = '' since = '' until = '' tvmazeSince = 'day' phase = 'done' page = 1 pages = 1
  53. requests = 0 tvmazeRequests = 0 tvChanged = 0 movieChanged = 0 tvmazeChanged = 0 count = 0 followed = 0 statusOnly = 0 failed = '' }
  54. static followedRun = {}
  55. static pickedRun = {}
  56. static pickedAt = {}
  57. // tracker#35: named by TVmaze's change list (this run) · picked for its TVmaze status alone
  58. static mazeRun = {}
  59. static statusOnlyRun = {}
  60. static followedList = { ids = [] }
  61. // a run starts: { mode ('delta' | 'full'), why, since, days }. 'delta' → call planStep() until it answers done, then planIds().
  62. // `sinceDay` (the tool's --since) stands in for the stored last day; null = the stored one
  63. static planStart = (today, &sinceDay) => {
  64. run.no = run.no + 1
  65. run.since = ''
  66. run.until = today
  67. run.phase = 'done'
  68. run.page = 1
  69. run.pages = 1
  70. run.requests = 0
  71. run.tvmazeRequests = 0
  72. run.tvChanged = 0
  73. run.movieChanged = 0
  74. run.tvmazeChanged = 0
  75. run.count = 0
  76. run.followed = 0
  77. run.statusOnly = 0
  78. run.failed = ''
  79. last = sinceDay != null ? sinceDay : lastSyncDay()
  80. days = last != null && dayNumber(today) != null ? dayNumber(today) - dayNumber(last) : null
  81. if (last == null) {
  82. run.mode = 'full'
  83. run.why = 'no last run'
  84. } else if (days == null || days > maxDeltaDays || days < 0) {
  85. run.mode = 'full'
  86. run.why = 'last run ' + last + ', ' + days + ' days ago > ' + maxDeltaDays
  87. } else {
  88. run.mode = 'delta'
  89. run.why = 'since ' + last + ' (' + days + (days == 1 ? ' day' : ' days') + ')'
  90. run.since = last
  91. run.tvmazeSince = days <= 1 ? 'day' : (days <= 7 ? 'week' : 'month')
  92. run.phase = 'tv'
  93. ids = allFollowedShowIds()
  94. for (id of ids) { followedRun[id] = run.no }
  95. followedList.ids = ids
  96. }
  97. return { mode = run.mode why = run.why since = run.since days = days }
  98. }
  99. // is this title followed by anyone (as of this run's start)? — such a title gets the FULL step (all seasons + TVmaze, as
  100. // before #18), one nobody follows the LIGHT one (sync.hl syncShowDelta: changed seasons, no TVmaze)
  101. static isFollowedInRun = (&showId) => { return followedRun[showId] == run.no }
  102. // one of ours that changed → into the queue once, when the daily sync may touch it. `viaTvmaze`: found by TVmaze's list — only
  103. // a followed series counts there (TVmaze is merged for the followed ones only)
  104. static pick = (showId, &viaTvmaze) => {
  105. if (showId == null || pickedRun[showId] == run.no) { return false }
  106. s = showsTable.fetch(showId)
  107. followed = followedRun[showId] == run.no
  108. if (s == null || s.tmdbId == null || isIncomplete(s) || (s.adult == true && !followed) || (viaTvmaze && !followed)) { return false }
  109. pickedRun[showId] = run.no
  110. pickedAt['' + run.count] = showId
  111. run.count = run.count + 1
  112. if (followed) { run.followed = run.followed + 1 }
  113. return true
  114. }
  115. // tracker#35: a series nobody follows, only on TVmaze's list → into the queue for its TVmaze status alone (one picked by TMDB's
  116. // list already gets it with its light step)
  117. static pickStatus = (showId) => {
  118. if (showId == null || pickedRun[showId] == run.no || followedRun[showId] == run.no) { return false }
  119. s = showsTable.fetch(showId)
  120. if (s == null || s.type != 'series' || !hasId(s.tvmzId) || s.adult == true || s.mergedInto != null || isIncomplete(s)) { return false }
  121. pickedRun[showId] = run.no
  122. statusOnlyRun[showId] = run.no
  123. pickedAt['' + run.count] = showId
  124. run.count = run.count + 1
  125. run.statusOnly = run.statusOnly + 1
  126. return true
  127. }
  128. // ONE title of the run (jobs.hl syncTick, tools/sync-tmdb.hl): a full walk or a followed title → the full step; a series only on
  129. // TVmaze's list → its TVmaze status; any other → the light step (+ the TVmaze status when TVmaze's list named it too)
  130. static syncRunStep = (&showId, &delta) => {
  131. if (!delta || followedRun[showId] == run.no) { return syncShow(showId) }
  132. if (statusOnlyRun[showId] == run.no) { return syncTvmazeStatus(showId) }
  133. return syncShowDelta(showId, mazeRun[showId] == run.no)
  134. }
  135. static isStatusOnlyInRun = (&showId) => { return statusOnlyRun[showId] == run.no }
  136. // ONE change-list request (TMDB tv page, TMDB movie page or TVmaze's list): { done, requests, tvmazeRequests, failed ('' = none) }
  137. static planStep = () => {
  138. out = { done = false requests = 0 tvmazeRequests = 0 failed = '' }
  139. if (run.phase == 'tv' || run.phase == 'movie') {
  140. kind = run.phase
  141. out.requests = 1
  142. run.requests = run.requests + 1
  143. let j = tmdbGet('/' + kind + '/changes?start_date=' + run.since + '&end_date=' + run.until + '&page=' + run.page)
  144. if (j.failed != null || j.results == null) {
  145. run.failed = j.failed != null ? j.failed : 'no results in /' + kind + '/changes'
  146. run.phase = 'done'
  147. out.failed = run.failed
  148. out.done = true
  149. return out
  150. }
  151. type = kind == 'tv' ? 'series' : 'movie'
  152. for (c of j.results) {
  153. if (c != null && numIdOr(c.id) != null) {
  154. if (kind == 'tv') { run.tvChanged = run.tvChanged + 1 } else { run.movieChanged = run.movieChanged + 1 }
  155. let sid = titleIdByTmdb(type, c.id)
  156. if (sid != null) { pick(sid, false) }
  157. }
  158. }
  159. run.pages = j.total_pages != null && hlTypeName(j.total_pages) == 'Number' ? j.total_pages : 1
  160. if (run.pages > maxPages) { run.pages = maxPages }
  161. if (run.page < run.pages) { run.page = run.page + 1 } else {
  162. run.phase = kind == 'tv' ? 'movie' : 'tvmaze'
  163. run.page = 1
  164. run.pages = 1
  165. }
  166. return out
  167. }
  168. if (run.phase == 'tvmaze') {
  169. out.tvmazeRequests = 1
  170. run.tvmazeRequests = run.tvmazeRequests + 1
  171. run.phase = 'done'
  172. f = fetch(tvmazeBase + '/updates/shows?since=' + run.tvmazeSince, { headers = { 'accept' = 'application/json' 'user-agent' = 'tracker.worldapi.org (tmdb sync)' } timeoutMs = 30000 })
  173. let j = f != null && f.status == 200 ? f.json() : null
  174. if (j == null) {
  175. run.failed = 'TVmaze: ' + (f == null || f.status == null || f.status == 0 ? 'no answer' : 'HTTP ' + f.status) + ' for /updates/shows?since=' + run.tvmazeSince
  176. out.failed = run.failed
  177. out.done = true
  178. return out
  179. }
  180. for (k of j.keys()) {
  181. run.tvmazeChanged = run.tvmazeChanged + 1
  182. let sid = titleIdByTvmaze(k)
  183. if (sid != null) {
  184. mazeRun[sid] = run.no
  185. if (!pick(sid, true)) { pickStatus(sid) }
  186. }
  187. }
  188. }
  189. out.done = true
  190. return out
  191. }
  192. // the queue: the changed titles of ours, the followed ones first (in follow-table order), then the rest (in change-list order)
  193. static planIds = () => {
  194. out = []
  195. for (id of followedList.ids) { if (pickedRun[id] == run.no) { out.push(id) } }
  196. let i = 0
  197. while (i < run.count) {
  198. let id = pickedAt['' + i]
  199. if (followedRun[id] != run.no) { out.push(id) }
  200. i = i + 1
  201. }
  202. return out
  203. }
  204. // the log line of a finished plan
  205. static planLine = () => {
  206. return 'changes ' + run.why + ': tmdb tv=' + run.tvChanged + ' movie=' + run.movieChanged + ' tvmaze(' + run.tvmazeSince + ')=' + run.tvmazeChanged
  207. + ' → ' + run.count + ' of our titles (' + run.followed + ' followed' + (run.statusOnly > 0 ? ', ' + run.statusOnly + ' TVmaze status only' : '') + '), changeRequests=' + run.requests + ' tvmazeChangeRequests=' + run.tvmazeRequests
  208. + (run.failed != '' ? ' FAILED: ' + run.failed : '')
  209. }
  210. // ---- the copied summaries (tracker#18, one time; mission 070: MOVED, never deleted) -------------------------------------------
  211. // The migration copied TMDB's text into `summary` too (9,648 of 10,011 titles on the live copy, 2026-10-01): such a `summary` is
  212. // no text of the creator's — it is MOVED to `migratedSummary` (kept in the record, shown nowhere) and `summary` is emptied, so the
  213. // CURRENT tmdbSummary shows (shows.hl summaryOf). Nothing is lost: the conductor's rule (mission 070) — no step destroys migrated
  214. // data. A `summary` that differs is the creator's own and stays. ONCE: `<storage>/summaries-moved.txt` records that it ran (and
  215. // the counts). → { ran, moved, kept, errors, ms }
  216. static movedFile = storageDir + '/summaries-moved.txt'
  217. static moveCopiedSummaries = () => {
  218. out = { ran = false moved = 0 kept = 0 errors = 0 ms = 0 }
  219. if (exists(movedFile)) { return out }
  220. out.ran = true
  221. t0 = now()
  222. for (s of showsTable.find(null, null)) {
  223. if (textOr(s.summary) != null) {
  224. if (s.summary == s.tmdbSummary) {
  225. let x = s
  226. x.migratedSummary = s.summary
  227. x.summary = null
  228. if (showsTable.update(x.id, x) == null) { out.errors = out.errors + 1 } else { out.moved = out.moved + 1 }
  229. } else { out.kept = out.kept + 1 }
  230. }
  231. }
  232. showsTable.persist()
  233. out.ms = now() - t0
  234. writeFile(movedFile, 'moved=' + out.moved + ' kept=' + out.kept + ' errors=' + out.errors, 420)
  235. return out
  236. }

Branches

Latest commits

  • fbb903cctracker#33/#37 (mission 032): a title without a TMDB poster gets its backdrop (w780, posterFromBackdrop, shown 2:3 centre-cropped); movies store runtime, the page shows release date + runtime; art backfill (public titles without poster file / movies without runtime) and person photo backfill (tmdbProfile / photoCheck) as the last start jobs (TRACKER_ART, TRACKER_PHOTOS; off in every gate start); gates 379/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy: art 4977 titles in 42 min (115 posters, 15 backdrops, 4609 runtimes), The Remaining shows its backdrop + 7 minmre
  • 4ecc67b2tracker: STATUS/LOG for the t38 + t40 merge (gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy checks)mre
  • e5945d2fMerge t40 (tracker#40 curated franchises, Franchises menu, superseded collections) into main: deploy.sh lists all six gates (browser, kinds, franchises, pager, franchiseseed, check-theme); search.hl keeps #37's personPhotoOf + #40's importWithCredits; pager gate runs with TRACKER_FRANCHISE_SEED=0; gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0mre
  • b638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mre
  • f8ffa4dbtracker: report 032 + The Remaining + #39mre
  • 7565a863tracker: LOG timemre
  • b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
  • 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre
  • 9448d643tracker#35 follow-up (mission 033): TVmaze 'Running' is labelled 'Returning', or 'Airing' while a non-special episode of the two newest seasons is released within today +-7 days (data unchanged); gate fixtures Running/Airing/Aired + a special; browser 366/0, kinds 32/0, franchises 52/0, pager 229/0, check-theme 0mre
  • 7d4b293dtracker#40: "Franchises" in the main menu (desktop header after People, phone sidebar) → /franchises, marked on franchise and timeline pages; gates 365/0, 32/0, 53/0, 24/0, check-theme 0mre
  • 8751adb8tracker: report 032mre
  • 9bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre
  • 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
  • 93dfb0batracker#40 (mission 034): the curated franchises — data/franchises.json (17 franchises, 31 timelines, 285 TMDB titles, movies + series, in-universe/release order, 12 TMDB collections attached); lib/franchiseseed.hl + jobs.hl franchiseSeedTick (last start job, imports missing titles via details.hl importWithCredits = the search's Add, one per step paced, then one build; franchiseseed.db: editor changes win, the creator's same-name franchise adopted / timeline left alone, 404 remembered, resumable, idempotent); timeline heads 'N titles · in-universe order' (orderKind) and wrap on a phone; series pages show the widget; new gate tests/franchiseseed.mjs (5th in deploy.sh), the others run with TRACKER_FRANCHISE_SEED=0; gates 365/0, 32/0, 52/0, 24/0, check-theme 0; real copy 196 imported, 0 failed, 7 min, restart unchanged=31mre
  • 03ec792ftracker#38 (mission 033): pagination goes exactly to the clicked page — tilelist read the clicked button's text after pagination.hl's own handler had rebuilt the buttons (real clicks only); now li.current, else the button's own text; new gate tests/pager.mjs (5 lists x 11 pages, 390/1280, real + script clicks, Back/Forward) 229/0; browser 365/0, kinds 32/0, franchises 52/0, check-theme 0mre
  • 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