tracker
All repositories: gitoria
9.7 KB
// tools/tmdb-fix.hl — tracker#36 (mission T36): fix the years and the wrong TMDB ids tools/tmdb-check.hl found, as the creator said// yes on 2026-10-29 (groups 1 and 3 of lib/tmdbfix.hl; 2 and 4 and every non-unique group-3 case are only LISTED).// TRACKER_STORAGE=/abs/copy/storage/mpackdb TMDB_READ_TOKEN=<never printed> ./bin/hybriel tools/tmdb-fix.hl --dry-run [--plan-out FILE] [--from N] [--limit N]// TRACKER_STORAGE=/abs/copy/storage/mpackdb TMDB_READ_TOKEN=<never printed> ./bin/hybriel tools/tmdb-fix.hl --apply FILE// --dry-run asks TMDB for every migrated title (one request each, 260 ms apart, 2 for a group-3 title), prints every planned change// (`fix-year`, `fix-tmdb`) and every title left for the creator (`list-1`, `list-3`, `list-4`; `leave-2` the translations) and// CHANGES NOTHING; --plan-out writes the planned changes (space separated: kind, record id, slug, old ('-' = none), new). --apply reads such a plan,// asks TMDB ONCE MORE per planned title (the year / the new id must still hold, the record must still be as planned) and writes it;// a second --apply of the same plan changes nothing (the record no longer is as planned). hl:mpackdb rewrites files when it opens a// table, so ONLY on a COPY or with the app stopped. Never against the live storage without the creator's go.import { env, args, exit } from 'hl:proc'import { now, sleep } from 'hl:time'import { writeFile, tryReadFile } from 'hl:fs'import { syncEnabled, msPerRequest, tmdbGet } from '../lib/tmdb.hl'import { allShows, showById, showsTable } from '../lib/shows.hl'import { tcWanted, tcAssess } from '../lib/tmdbcheck.hl'import { tfGroupOf, tfSearch, tfCandText, tfKey, tfWithYear, tfWithTmdb } from '../lib/tmdbfix.hl'static tfArgOf = (&tfName) => {tfAll = args()let tfI = 0while (tfI < tfAll.length) {if (tfAll[tfI] == tfName && tfI + 1 < tfAll.length) { return tfAll[tfI + 1] }tfI = tfI + 1}return null}// the title's page pathstatic tfPathOf = (&tfShow) => { return (tfShow.type == 'movie' ? '/movies/' : '/series/') + tfShow.urlSegment }static runDry36 = () => {tfStart = now()tfFrom = tfArgOf('--from') != null ? toNumber(tfArgOf('--from')) : 0tfLimit = tfArgOf('--limit') != null ? toNumber(tfArgOf('--limit')) : -1tfOut = tfArgOf('--plan-out')tfIds = []tfTaken = {}for (tfS of allShows()) {if (tfS.mergedInto == null && tfS.tmdbId != null) { tfTaken[tfKey(&tfS.type, &tfS.tmdbId)] = tfPathOf(&tfS) }if (tcWanted(&tfS)) { tfIds.push(tfS.id) }}console.log('tmdb fix (dry run): ' + tfIds.length + ' migrated titles with a TMDB id')let tfQueue = []let tfPos = 0for (tfId of tfIds) {if (tfPos >= tfFrom && (tfLimit < 0 || tfQueue.length < tfLimit)) { tfQueue.push(tfId) }tfPos = tfPos + 1}tfN = { asked = 0 ok = 0 g1 = 0 g1year = 0 g1none = 0 g2 = 0 g3 = 0 g3switch = 0 g3list = 0 g4 = 0 failed = 0 }let tfPlan = ''let tfRound = 1while (tfRound <= 2 && tfQueue.length > 0) {let tfAgain = []for (tfId of tfQueue) {let tfShow = showById(&tfId)let tfA = tcAssess(&tfShow)if (tfRound == 1) { tfN.asked = tfN.asked + 1 }if (tfA.retry && tfRound == 1) { tfAgain.push(tfId) }else if (tfA.retry) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfA.head + ': ' + tfA.failed) }else {let tfG = tfGroupOf(&tfA)if (tfG.group == 0) { tfN.ok = tfN.ok + 1 }else if (tfG.group < 0) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfA.head + ': ' + tfG.why) }else if (tfG.group == 1) {tfN.g1 = tfN.g1 + 1if (tfA.newYear == null) { tfN.g1none = tfN.g1none + 1 console.log('list-1 ' + tfA.head + ': ' + tfG.why + ', TMDB has no year either, nothing to take') }else {tfN.g1year = tfN.g1year + 1console.log('fix-year ' + tfA.head + ' (' + tfG.why + '): year ' + (tfA.old.year != null ? tfA.old.year : '?') + ' → ' + tfA.newYear)tfPlan = tfPlan + 'year ' + tfShow.id + ' ' + tfShow.urlSegment + ' ' + (tfA.old.year != null ? tfA.old.year : '-') + ' ' + tfA.newYear + ''}}else if (tfG.group == 2) { tfN.g2 = tfN.g2 + 1 console.log('leave-2 ' + tfA.head + ' = "' + tfA.mainName + '" (' + (tfA.newYear != null ? tfA.newYear : '?') + '): ' + tfG.why) }else if (tfG.group == 4) { tfN.g4 = tfN.g4 + 1 console.log('list-4 ' + tfA.head + ' = "' + tfA.mainName + '" (' + (tfA.newYear != null ? tfA.newYear : '?') + '): ' + tfG.why) }else {tfN.g3 = tfN.g3 + 1sleep(msPerRequest / 1000)let tfF = tfSearch(&tfA)if (tfF.state == 'unique' && tfTaken[tfKey(&tfShow.type, &tfF.cands[0].id)] != null) {tfN.g3list = tfN.g3list + 1console.log('list-3 ' + tfA.head + ': one match ' + tfCandText(&tfF.cands) + ' but that id is already ours at ' + tfTaken[tfKey(&tfShow.type, &tfF.cands[0].id)])} else if (tfF.state == 'unique') {tfN.g3switch = tfN.g3switch + 1console.log('fix-tmdb ' + tfA.head + ': tmdb ' + tfShow.tmdbId + ' → ' + tfF.cands[0].id + ' ("' + tfF.cands[0].name + '" ' + tfF.cands[0].year + ')')tfPlan = tfPlan + 'tmdb ' + tfShow.id + ' ' + tfShow.urlSegment + ' ' + tfShow.tmdbId + ' ' + tfF.cands[0].id + ''} else {tfN.g3list = tfN.g3list + 1console.log('list-3 ' + tfA.head + ': ' + (tfF.state == 'noyear' ? 'we have no year to search with' : (tfF.state == 'failed' ? 'search failed: ' + tfF.failed : (tfF.state == 'none' ? 'no TMDB result with this name and year' : 'several TMDB results with this name and year'))) + '. candidates: ' + tfCandText(&tfF.cands))}}}if (tfRound == 1 && tfN.asked % 500 == 0) { console.log('tmdb fix: ' + tfN.asked + '/' + tfQueue.length + ' asked') }sleep(msPerRequest / 1000)}tfQueue = tfAgaintfRound = tfRound + 1}if (tfOut != null) { writeFile(tfOut, tfPlan, 420) }console.log('tmdb fix (dry run) done: asked=' + tfN.asked + ' ok=' + tfN.ok + ' group1=' + tfN.g1 + ' (year fixes=' + tfN.g1year + ' nothing-to-take=' + tfN.g1none + ') group2=' + tfN.g2+ ' group3=' + tfN.g3 + ' (switch=' + tfN.g3switch + ' listed=' + tfN.g3list + ') group4=' + tfN.g4 + ' failed=' + tfN.failed + ' seconds=' + ((now() - tfStart) / 1000) + ' — NOTHING was changed')return 0}static runApply36 = () => {tfPlanFile = tfArgOf('--apply')tfText = tryReadFile(tfPlanFile)if (tfText == null) { console.log('REFUSED: cannot read the plan file ' + tfPlanFile) return 2 }tfN = { planned = 0 applied = 0 year = 0 tmdb = 0 skipped = 0 failed = 0 }let tfTouched = falsefor (tfLine of tfText.split('')) {if (tfLine.trim() != '') {tfCols = tfLine.split(' ')tfN.planned = tfN.planned + 1let tfShow = showById(&tfCols[1])let tfWhat = tfCols[0] + ' ' + tfCols[2]if (tfShow == null || tfShow.mergedInto != null) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': record gone or merged') }else if (tfCols[0] == 'year') {let tfWasYear = tfCols[3] == '-' ? null : toNumber(tfCols[3])let tfNewYear = toNumber(tfCols[4])if (tfShow.year == tfNewYear && (tfShow.release == null || ('' + tfShow.release).slice(0, 4) == '' + tfNewYear)) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': already ' + tfNewYear) }else {let tfA = tcAssess(&tfShow)sleep(msPerRequest / 1000)if (tfA.failed != null) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfWhat + ': ' + tfA.failed) }else if (tfA.newYear != tfNewYear) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': TMDB now says ' + tfA.newYear) }else {let tfPut = showsTable.update(tfShow.id, tfWithYear(&tfShow, &tfNewYear, &tfA.newDate))if (tfPut == null) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfWhat + ': not stored: ' + showsTable.lastError()) }else { tfN.applied = tfN.applied + 1 tfN.year = tfN.year + 1 tfTouched = true console.log('applied ' + tfWhat + ': year ' + (tfWasYear != null ? tfWasYear : '?') + ' → ' + tfNewYear) }}}} else if (tfCols[0] == 'tmdb') {let tfOldId = toNumber(tfCols[3])let tfNewId = toNumber(tfCols[4])if (tfShow.tmdbId == tfNewId) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': already ' + tfNewId) }else if (tfShow.tmdbId != tfOldId) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': the record has tmdb ' + tfShow.tmdbId + ' now, not ' + tfOldId) }else {let tfMovie = tfShow.type == 'movie'let tfD = tmdbGet((tfMovie ? '/movie/' : '/tv/') + tfNewId)sleep(msPerRequest / 1000)if (tfD.failed != null) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfWhat + ': ' + tfD.failed) }else {let tfPut = showsTable.update(tfShow.id, tfWithTmdb(&tfShow, &tfNewId))if (tfPut == null) { tfN.failed = tfN.failed + 1 console.log('failed ' + tfWhat + ': not stored: ' + showsTable.lastError()) }else { tfN.applied = tfN.applied + 1 tfN.tmdb = tfN.tmdb + 1 tfTouched = true console.log('applied ' + tfWhat + ': tmdb ' + tfOldId + ' → ' + tfNewId) }}}}}}if (tfTouched) { showsTable.persist() }console.log('tmdb fix (apply) done: planned=' + tfN.planned + ' applied=' + tfN.applied + ' (year=' + tfN.year + ' tmdb=' + tfN.tmdb + ') skipped=' + tfN.skipped + ' failed=' + tfN.failed)return 0}static runFix36 = () => {tfStorage = env('TRACKER_STORAGE')if (tfStorage == null || !tfStorage.startsWith('/')) { console.log('REFUSED: set TRACKER_STORAGE, absolute (a copy, or the app stopped)') return 2 }if (!syncEnabled) { console.log('REFUSED: TMDB_READ_TOKEN is not set') return 2 }tfA = args()if (tfA.includes('--dry-run')) { return runDry36() }if (tfA.includes('--apply') && tfArgOf('--apply') != null) { return runApply36() }console.log('REFUSED: say --dry-run [--plan-out FILE] or --apply FILE')return 2}exit(runFix36())on Error(e) { console.log(' error absorbed: ' + e.message) }
Branches
Latest commits
- 1fb6664bcompose: TRACKER_QSTATS=1 (GC1 measurement)mre
- 6576c1cdgc1: release the people-view scan lists once the view is builtmre
- 94f8a373gc1: back out the kept episode-id set (no measurable gain on /my/unwatched: 4.69 -> 4.61 GB per 150 loads)mre
- a1a88bd4gc1: search skips the stale-key string while no entry is stale; /my/unwatched asks a kept id set instead of building a key string per episode rowmre
- cd830744gc1: dbSearch: no split / map / list copy per candidate (scores from the stored text, top list touched only when the hit can enter)mre
- 451db7cdgc1: show page and check clicks read the kept watched set instead of building one from a by-value copy of every watchmre
- ddb4127egc1: TRACKER_QSTATS=1 logs queue and cache sizes every 10 s (measurement only)mre
- da60547fstatus: GC1 done, backup bugmre
- e4171021log: GC1 result, backup hard-link bugmre
- f1597214deploy.sh backup: tar --hard-dereference (hot tar stored mpackdb sidecars as hard links to .sessions files)mre
- 6b58571elog: GC windowmre
- 5c8baa1fdeploy lock: hold only around deploy.shmre
- b8dac822log: hybriel#309mre
- bf676d9elog: GC1 startedmre
- c7828541mission GC1mre
- ef949994conductor: neutral ticket rulemre
- 89e91ef3log: RV39 livemre
- ee2b677alog: RV39 deployingmre
- c1c4178cMerge branch 'rv39'mre
- a016e9abReapply "Merge branch 'rv39'"mre