gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit975d06d1975d06d1log: #36 live, DP66 startedmre975d06d1/lib/tmdbfix.hl

6.1 KB

  1. // lib/tmdbfix.hl — tracker#36 (mission T36): FIX WHAT tools/tmdb-check.hl FOUND, as the creator said yes on 2026-10-29 to the proposal of
  2. // 2026-10-19. The groups (lib/tmdbcheck.hl tcAssess gives the facts):
  3. // 1 our year is missing, or the name is the same and the year another → TMDB's year is stored (`year`; an old `year` is kept in
  4. // `migratedYear`). Nothing to take when TMDB has no year either → listed only.
  5. // 2 same year, other name (translations) → LEFT, only listed.
  6. // 3 TMDB no longer knows the id (404) → TMDB's search by name; the id is switched ONLY when exactly ONE result has the same name
  7. // (title / original title, compared normalized) AND the same year as ours, and no other record of ours already has that id. The
  8. // record keeps everything: watches, follows, seasons and episodes hang on the record's own id, never on the TMDB id. The old id
  9. // is kept in `tmdbIdWas`, a stored "TMDB 404" marker of a backfill is cleared so the backfills ask again for the new id.
  10. // 4 name and year both (or partly) differ → LEFT, only listed.
  11. // tfPlanOf decides, tfApplyYear / tfApplyTmdb write ONE record (the caller persists). Names carry the tf prefix on purpose (hybriel
  12. // #162: a callee's local can overwrite a caller's same-named variable).
  13. import { tmdbGet } from './tmdb.hl'
  14. import { textOr, listOr } from './util.hl'
  15. import { showsTable } from './shows.hl'
  16. import { tcNorm, tcYearOf, tcMigratedOf } from './tmdbcheck.hl'
  17. // the group of one assessed title: { group (0 = fine, 1..4), why }
  18. static tfGroupOf = (&tfA) => {
  19. if (tfA.notFound) { return { group = 3 why = 'TMDB has no such id (404)' } }
  20. if (tfA.failed != null) { return { group = -1 why = tfA.failed } }
  21. if (tfA.verdict == 'ok') { return { group = 0 why = 'ok' } }
  22. tfKnown = tfA.old.year != null && tfA.newYear != null
  23. if ((tfA.match == 'same' || tfA.match == 'part') && tfA.old.year == null) { return { group = 1 why = 'our year is missing' } }
  24. if (tfA.match == 'same' && tfKnown) { return { group = 1 why = 'same name, other year' } }
  25. if (tfA.match == 'other' && tfA.verdict == 'ambiguous') { return { group = 2 why = 'same year, other name' } }
  26. return { group = 4 why = 'name and year differ' }
  27. }
  28. // TMDB's search for a group-3 title → { state ('unique' | 'none' | 'many' | 'noyear' | 'failed'), cands [{ id, name, year }], failed }
  29. // ONE request. Only a result with the same normalized name (title or original title) AND the same year as ours counts.
  30. static tfSearch = (&tfA) => {
  31. if (tfA.old.year == null) { return { state = 'noyear' cands = [] failed = null } }
  32. tfPath = (tfA.movie ? '/search/movie?query=' : '/search/tv?query=') + encodeURIComponent(tfA.old.title) + '&include_adult=true&page=1&'
  33. + (tfA.movie ? 'year=' : 'first_air_date_year=') + tfA.old.year
  34. tfJ = tmdbGet(&tfPath)
  35. if (tfJ.failed != null) { return { state = 'failed' cands = [] failed = tfJ.failed } }
  36. tfWant = tcNorm(&tfA.old.title)
  37. tfCands = []
  38. for (tfR of listOr(&tfJ.results)) {
  39. tfName = textOr(tfA.movie ? tfR.title : tfR.name)
  40. tfOrig = textOr(tfA.movie ? tfR.original_title : tfR.original_name)
  41. tfYear = tcYearOf(tfA.movie ? tfR.release_date : tfR.first_air_date)
  42. if (tfR.id != null && tfYear == tfA.old.year && ((tfName != null && tcNorm(&tfName) == tfWant) || (tfOrig != null && tcNorm(&tfOrig) == tfWant))) {
  43. tfCands.push({ id = tfR.id name = tfName != null ? tfName : tfOrig year = tfYear })
  44. }
  45. }
  46. return { state = tfCands.length == 1 ? 'unique' : (tfCands.length == 0 ? 'none' : 'many') cands = tfCands failed = null }
  47. }
  48. // 'id "Name" (year); …'
  49. static tfCandText = (&tfCands) => {
  50. let tfOut = ''
  51. for (tfC of tfCands) { tfOut = tfOut + (tfOut == '' ? '' : '; ') + tfC.id + ' "' + tfC.name + '" (' + tfC.year + ')' }
  52. return tfOut == '' ? 'none' : tfOut
  53. }
  54. // the key under which a TMDB id is taken: 'movie:123' / 'series:123'
  55. static tfKey = (&tfType, &tfId) => { return tfType + ':' + tfId }
  56. // the markers a backfill stored for a TMDB 404 (adultCheck, kindCheck, artCheck, creditsCheck): cleared on a switched id
  57. static tfClearMarks = (&tfShow) => {
  58. tfX = tfShow
  59. for (tfF of ['adultCheck', 'kindCheck', 'artCheck', 'creditsCheck']) {
  60. if (textOr(&tfX[tfF]) != null && ('' + tfX[tfF]).includes('404')) { tfX[tfF] = null }
  61. }
  62. return tfX
  63. }
  64. // the record with TMDB's year AND release date (the year comes from it; Apollo 2026-10-30). The old year / release are kept once in
  65. // migratedYear / migratedRelease
  66. static tfWithYear = (&tfShow, &tfYear, &tfDate) => {
  67. tfX = tfShow
  68. if (tfX.year != null && tfX.migratedYear == null) { tfX.migratedYear = tfX.year }
  69. tfX.year = tfYear
  70. if (textOr(&tfDate) != null && tfX.release != tfDate) {
  71. if (textOr(&tfX.release) != null && tfX.migratedRelease == null) { tfX.migratedRelease = tfX.release }
  72. tfX.release = tfDate
  73. }
  74. return tfX
  75. }
  76. // the record with the other TMDB id (the old one kept once in tmdbIdWas)
  77. static tfWithTmdb = (&tfShow, &tfId) => {
  78. tfX = tfShow
  79. if (tfX.tmdbIdWas == null) { tfX.tmdbIdWas = tfX.tmdbId }
  80. tfX.tmdbId = tfId
  81. return tfClearMarks(&tfX)
  82. }
  83. // Plan preconditions cover every field used to decide identity or a year/release write.
  84. static tfStateOf = (&tfShow) => {
  85. return encodeURIComponent(JSON.stringify({ type = tfShow.type title = tfShow.title migratedTitle = tfShow.migratedTitle
  86. year = tfShow.year release = tfShow.release tmdbId = tfShow.tmdbId urlSegment = tfShow.urlSegment }))
  87. }
  88. // Fresh details must still identify the exact name and year selected by search.
  89. static tfMatches = (&tfShow, &tfD, &tfId) => {
  90. tfOld = tcMigratedOf(&tfShow)
  91. tfMovie = tfShow.type == 'movie'
  92. tfName = textOr(tfMovie ? tfD.title : tfD.name)
  93. tfOrig = textOr(tfMovie ? tfD.original_title : tfD.original_name)
  94. tfYear = tcYearOf(tfMovie ? tfD.release_date : tfD.first_air_date)
  95. tfWant = tcNorm(&tfOld.title)
  96. return tfD.id == tfId && tfOld.year != null && tfYear == tfOld.year
  97. && ((tfName != null && tcNorm(&tfName) == tfWant) || (tfOrig != null && tcNorm(&tfOrig) == tfWant))
  98. }
  99. static tfOtherOwner = (&tfShow, &tfId) => {
  100. for (tfRow of showsTable.iterate(null, null)) {
  101. if (tfRow.id != tfShow.id && tfRow.mergedInto == null && tfRow.type == tfShow.type && tfRow.tmdbId == tfId) {
  102. return tfRow.id
  103. }
  104. }
  105. return null
  106. }

Branches

Latest commits

  • 975d06d1log: #36 live, DP66 startedmre
  • d6d03fa3mission: T36Bmre
  • e7512d00status: #36 rolled back, retry askedmre
  • c98e2043log: T36A rollbackmre
  • ae905f15Merge t36a: tracker#36 apply rechecks, reportmre
  • 796bfaceT36A: report validated fixes, failed live SSH check and verified rollbackmre
  • 55257852log: #53 live, #56 mergedmre
  • 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
  • 7aea52batmdb fix: protect owners without slugs and record passing gatesmre
  • 9b3c2559tmdb fix: revalidate planned identities and reserve target idsmre
  • 6da612fclog: T36A tool defectmre
  • d56ee0daT36A: report unsafe TMDB apply revalidation and stop before livemre
  • 08e55255log: HM56 done, T36A startedmre
  • 91bcdf0eAvoid per-row list copies and reproduce keyed-row blockersmre
  • 5fd2ac75status: #36 GOmre
  • 0d253b45mission: T36Amre
  • 2aa22d23log: #36 GOmre
  • 833aee2flog: #50 closed, HM56 startedmre
  • ac58c1e5mission: HM56mre
  • 58979c0clog: HM54 held for decision, DP65 startedmre