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
Latest commits
- a401190fTracker: GO for the crash loopmre
- e195d372Tracker: token pathsmre
- 7f541d11Tracker conductor: CONDUCTOR.md, short STATUS.md, old status + decisions archive to archive/2026-10-31mre
- 8dd423f7README: login.js stays by caramboleyo's explicit rulemre
- d8df1493tracker: standby service on port 45018 and a gap-free hand-over in deploy.sh step 4mre
- 36dd1686ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- ff9b838etracker: the Ended status pill uses the same red as layouts (pill danger); gate updatedmre
- 40d9719eTP2: LOG line and report for the tracker pillsmre
- ab3f2ba5tracker: status, genres, TMDB/IMDb/TVDB/TVmaze links and list kinds use the theme's pill; dense season list with the season check centred on its title line; gates for bothmre
- 521061d6tracker header on phones: signed in, the brand fits whole at 360 and 390 px (tighter gaps and side paddings, slightly smaller brand, narrow screens and signed in only); mobile gate checks itmre
- 18114a53tracker: franchises gate waits for the signed-out selector instead of the removed Log in buttonmre
- 08561d73ident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
- 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
- 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
- 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre
- 1d98dcfdbrowser gate: the badges' size check reads the padding box (the 44 px tap area is transparent border)mre
- 2f9e29ffreports/MK-mobile.md, deploy.sh GATES: tests/mobile.mjs, theme check markermre
- 7cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre
- 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre