tracker
All repositories: gitoria
7.3 KB
// lib/sync-helpers.hl — the small pieces of the sync (sync.hl) that need no table and no request: placeholder titles, day// numbers, TVmaze's HTML stripped, whether TVmaze numbers a show like we do, which seasons to ask, batches, changed texts,// migrated rows, and the totals of a run (mission 028: out of tmdbsync.hl).import { textOr } from './util.hl'// ---- TVmaze merge (tracker.worldapi.org#15) ------------------------------------------------------// a title that is none yet: empty, "TBA"/"TBD", or "Episode <n>" (what TMDB and TVmaze name an untitled episode; also// French/German/Spanish: real data has TVmaze "Épisode 1" where TMDB says "Episode 1")static placeholderWords = ['episode', 'épisode', 'Épisode', 'folge', 'episodio']static isPlaceholderTitle = (&v) => {t = textOr(v)if (t == null) { return true }l = t.trim().toLowerCase()if (l == 'tba' || l == 'tbd' || l == 'tba.' || l == 'to be announced') { return true }parts = l.split(' ')if (parts.length != 2 || !placeholderWords.includes(parts[0]) || parts[1].length == 0) { return false }let i = 0while (i < parts[1].length) {if (!'0123456789'.includes(parts[1][i])) { return false }i = i + 1}return true}// 'YYYY-MM-DD' → a day number (only differences matter), null when it is no such datestatic dayNumber = (&v) => {t = textOr(v)if (t == null || t.length < 10) { return null }y = toNumber(t.slice(0, 4))m = toNumber(t.slice(5, 7))d = toNumber(t.slice(8, 10))if (y == null || m == null || d == null || m < 1 || m > 12) { return null }before = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]py = m <= 2 ? y - 1 : yleaps = (py - py % 4) / 4 - (py - py % 100) / 100 + (py - py % 400) / 400return y * 365 + leaps + before[m - 1] + d}static daysApart = (&a, &b) => {x = dayNumber(a)y = dayNumber(b)if (x == null || y == null) { return null }return x > y ? x - y : y - x}// TVmaze's text without its HTML (tracker#18: `tvmazeSummary`): tags dropped — a block tag (p, br, div, li) becomes a space —// the common entities decoded, white space collapsed; null when nothing is leftstatic blockTags = ['p', 'br', 'div', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'blockquote']static entities = [[' ', ' '], ['"', '"'], [''', "'"], [''', "'"], ['<', '<'], ['>', '>'], ['–', '–'], ['—', '—'], ['…', '…'], ['&', '&']]static stripHtml = (&v) => {t = textOr(v)if (t == null) { return null }let out = ''let i = 0while (i < t.length) {if (t[i] == '<') {let close = t.indexOf('>', i)if (close < 0) { close = t.length }let name = t.slice(i + 1, close).trim().toLowerCase()if (name.startsWith('/')) { name = name.slice(1) }let sp = name.indexOf(' ')if (sp >= 0) { name = name.slice(0, sp) }if (name.endsWith('/')) { name = name.slice(0, name.length - 1) }if (blockTags.includes(name)) { out = out + ' ' }i = close + 1} else {// a line break / tab (a control character) is a space too (strings have no escapes to name them)out = out + (t.charCodeAt(i) < 32 ? ' ' : t[i])i = i + 1}}for (e of entities) { out = out.replaceAll(e[0], e[1]) }words = []for (w of out.split(' ')) { if (w != '') { words.push(w) } }return words.length > 0 ? words.join(' ') : null}// do we and TVmaze number a show the same way? Of the episodes both know (same S/E), at least 80 % must air within a day// of each other OR carry the same title (a streaming show TVmaze dates all on its release day, TMDB week by week, still// agrees by title). A show we have episodes of but TVmaze numbers none of the same (e.g. seasons by year) never agrees.// Answers { known, compared, agree, ok }.static sameTitle = (&a, &b) => { return !isPlaceholderTitle(a) && !isPlaceholderTitle(b) && a.trim().toLowerCase() == b.trim().toLowerCase() }static numberingAgrees = (&epByNumber, &list) => {out = { known = 0 compared = 0 agree = 0 ok = true }localCount = epByNumber.keys().lengthfor (te of list) {let e = epByNumber[te.season + 'x' + te.number]if (e != null) {out.known = out.known + 1let apart = daysApart(e.release, te.airdate)let titled = !isPlaceholderTitle(e.title) && !isPlaceholderTitle(te.name)if (apart != null || titled) {out.compared = out.compared + 1if ((apart != null && apart <= 1) || sameTitle(e.title, te.name)) { out.agree = out.agree + 1 }}}}out.ok = !((localCount > 0 && out.known == 0) || (out.compared > 0 && out.agree * 5 < out.compared * 4))return out}// which TMDB seasons to sync: every numbered one with episodes; 0 only when the show has a season 0 alreadystatic wantedSeasonNumbers = (&details, &localByNumber) => {out = []if (details.seasons == null) { return out }for (s of details.seasons) {let n = s.season_numberif (n != null && (n > 0 || localByNumber['' + n] != null) && (s.episode_count == null || s.episode_count > 0 || localByNumber['' + n] != null)) { out.push(n) }}return out}// the seasons in batches of 20 (TMDB's append_to_response limit)static batchesOf = (&list, &size) => {out = []let cur = []for (x of list) {cur.push(x)if (cur.length == size) { out.push(cur) cur = [] }}if (cur.length > 0) { out.push(cur) }return out}// fields of an episode/season from TMDB that differ from the stored record (null/empty never overwrites)static changedText = (stored, &fresh) => { return fresh != null && fresh != stored }// mission 070 (conductor: no step destroys migrated data): a season / episode the old tracker's migration brought (its `oldId`// is neither `tmdb-…` nor `tvmaze-…`) keeps its FIRST title / summary in `migratedTitle` / `migratedSummary` before TMDB's text// replaces it (set once; shown nowhere) — the daily delta run now also refreshes seasons of titles nobody followsstatic isMigratedRow = (&r) => { return r.oldId != null && ('' + r.oldId).slice(0, 5) != 'tmdb-' && ('' + r.oldId).slice(0, 7) != 'tvmaze-' }// totals of a run: the per-show counts added upstatic emptyTotals = () => { return { shows = 0 requests = 0 tvmazeRequests = 0 newSeasons = 0 newEpisodes = 0 updatedEpisodes = 0 updatedSeasons = 0 posters = 0 ids = 0 tvmazeEpisodes = 0 tvmazeSeasons = 0 tvmazeFilled = 0 tvmazeSkipped = 0 errors = 0 } }static addTotals = (t, &r) => {o = to.shows = o.shows + 1o.requests = o.requests + r.requestso.tvmazeRequests = o.tvmazeRequests + r.tvmazeRequestso.ids = o.ids + r.idso.newSeasons = o.newSeasons + r.newSeasonso.newEpisodes = o.newEpisodes + r.newEpisodeso.updatedEpisodes = o.updatedEpisodes + r.updatedEpisodeso.updatedSeasons = o.updatedSeasons + r.updatedSeasonso.posters = o.posters + r.posterso.tvmazeEpisodes = o.tvmazeEpisodes + r.tvmazeEpisodeso.tvmazeSeasons = o.tvmazeSeasons + r.tvmazeSeasonso.tvmazeFilled = o.tvmazeFilled + r.tvmazeFilledo.tvmazeSkipped = o.tvmazeSkipped + r.tvmazeSkippedo.errors = o.errors + r.errorsreturn o}static totalsLine = (&t) => {return 'shows=' + t.shows + ' newSeasons=' + t.newSeasons + ' newEpisodes=' + t.newEpisodes + ' updatedEpisodes=' + t.updatedEpisodes+ ' updatedSeasons=' + t.updatedSeasons + ' posters=' + t.posters + ' ids=' + t.ids + ' requests=' + t.requests + ' tvmazeRequests=' + t.tvmazeRequests + ' errors=' + t.errors+ ' tvmazeEpisodes=' + t.tvmazeEpisodes + ' tvmazeSeasons=' + t.tvmazeSeasons + ' tvmazeFilled=' + t.tvmazeFilled + ' tvmazeSkipped=' + t.tvmazeSkipped}
Branches
- mainmain branch
Latest commits
- 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
- 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
- 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
- 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
- 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
- d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
- 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
- 661c2592tracker: report 028mre
- 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
- d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre