tracker
All repositories: gitoria
10.6 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, encoded identity snapshot). --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, tfStateOf, tfMatches, tfOtherOwner } 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) {tfAgain = []for (tfId of tfQueue) {tfShow = showById(&tfId)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 {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 + ' ' + tfStateOf(&tfShow) + ''}}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)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 + ' ' + tfStateOf(&tfShow) + ''tfTaken[tfKey(&tfShow.type, &tfF.cands[0].id)] = tfPathOf(&tfShow)} 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 + 1tfShow = showById(&tfCols[1])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.length != 6 || tfShow.urlSegment != tfCols[2] || tfStateOf(&tfShow) != tfCols[5]) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': record preconditions changed or missing') }else if (tfCols[0] == 'year') {tfWasYear = tfCols[3] == '-' ? null : toNumber(tfCols[3])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 if ((tfShow.year != null ? tfShow.year : (tfShow.release != null ? toNumber(('' + tfShow.release).slice(0, 4)) : null)) != tfWasYear) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': old year changed') }else {tfA = tcAssess(&tfShow)sleep(msPerRequest / 1000)if (tfA.failed != null) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': ' + tfA.failed) }else if (tfA.newYear != tfNewYear || tfGroupOf(&tfA).group != 1) { 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') {tfOldId = toNumber(tfCols[3])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 if (tfOtherOwner(&tfShow, &tfNewId) != null) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': target id already owned by ' + tfOtherOwner(&tfShow, &tfNewId)) }else {tfMovie = tfShow.type == 'movie'tfD = tmdbGet((tfMovie ? '/movie/' : '/tv/') + tfNewId)sleep(msPerRequest / 1000)if (tfD.failed != null) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': ' + tfD.failed) }else if (!tfMatches(&tfShow, &tfD, &tfNewId)) { tfN.skipped = tfN.skipped + 1 console.log('skip ' + tfWhat + ': fresh TMDB name or year no longer matches') }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
- d2e6d26bMerge branch 'records-park55' into mainTracker
- f567f025|||PR records: park #55, no Claude workers ruleTracker
- c21aff6bMerge branch 'records-hm55c' into mainTracker
- 9ba258d3|||PR records: HM55b resultTracker
- 64f2d300Merge branch 'records-hm55b2' into mainTracker
- ae3b80dc|||PR records: HM55b briefTracker
- 7ef3cb3bMerge branch 'records-st55' into mainTracker
- fec2e080|||PR records: STATUS HM55Tracker
- 8e174918Merge branch 'records-hm55b' into mainTracker
- b1ecee57|||PR records: HM55 stateTracker
- 28eab08cMerge branch 'records-hm55' into mainTracker
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker