gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitac58c1e5ac58c1e5mission: HM56mreac58c1e5/lib/tmdbfix.hl

4.9 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 { tcNorm, tcYearOf, tcAssess } from './tmdbcheck.hl'
  16. // the group of one assessed title: { group (0 = fine, 1..4), why }
  17. static tfGroupOf = (&tfA) => {
  18. if (tfA.notFound) { return { group = 3 why = 'TMDB has no such id (404)' } }
  19. if (tfA.failed != null) { return { group = -1 why = tfA.failed } }
  20. if (tfA.verdict == 'ok') { return { group = 0 why = 'ok' } }
  21. tfKnown = tfA.old.year != null && tfA.newYear != null
  22. if ((tfA.match == 'same' || tfA.match == 'part') && tfA.old.year == null) { return { group = 1 why = 'our year is missing' } }
  23. if (tfA.match == 'same' && tfKnown) { return { group = 1 why = 'same name, other year' } }
  24. if (tfA.match == 'other' && tfA.verdict == 'ambiguous') { return { group = 2 why = 'same year, other name' } }
  25. return { group = 4 why = 'name and year differ' }
  26. }
  27. // TMDB's search for a group-3 title → { state ('unique' | 'none' | 'many' | 'noyear' | 'failed'), cands [{ id, name, year }], failed }
  28. // ONE request. Only a result with the same normalized name (title or original title) AND the same year as ours counts.
  29. static tfSearch = (&tfA) => {
  30. if (tfA.old.year == null) { return { state = 'noyear' cands = [] failed = null } }
  31. tfPath = (tfA.movie ? '/search/movie?query=' : '/search/tv?query=') + encodeURIComponent(tfA.old.title) + '&include_adult=true&page=1&'
  32. + (tfA.movie ? 'year=' : 'first_air_date_year=') + tfA.old.year
  33. tfJ = tmdbGet(&tfPath)
  34. if (tfJ.failed != null) { return { state = 'failed' cands = [] failed = tfJ.failed } }
  35. tfWant = tcNorm(&tfA.old.title)
  36. tfCands = []
  37. for (tfR of listOr(&tfJ.results)) {
  38. tfName = textOr(tfA.movie ? tfR.title : tfR.name)
  39. tfOrig = textOr(tfA.movie ? tfR.original_title : tfR.original_name)
  40. tfYear = tcYearOf(tfA.movie ? tfR.release_date : tfR.first_air_date)
  41. if (tfR.id != null && tfYear == tfA.old.year && ((tfName != null && tcNorm(&tfName) == tfWant) || (tfOrig != null && tcNorm(&tfOrig) == tfWant))) {
  42. tfCands.push({ id = tfR.id name = tfName != null ? tfName : tfOrig year = tfYear })
  43. }
  44. }
  45. return { state = tfCands.length == 1 ? 'unique' : (tfCands.length == 0 ? 'none' : 'many') cands = tfCands failed = null }
  46. }
  47. // 'id "Name" (year); …'
  48. static tfCandText = (&tfCands) => {
  49. let tfOut = ''
  50. for (tfC of tfCands) { tfOut = tfOut + (tfOut == '' ? '' : '; ') + tfC.id + ' "' + tfC.name + '" (' + tfC.year + ')' }
  51. return tfOut == '' ? 'none' : tfOut
  52. }
  53. // the key under which a TMDB id is taken: 'movie:123' / 'series:123'
  54. static tfKey = (&tfType, &tfId) => { return tfType + ':' + tfId }
  55. // the markers a backfill stored for a TMDB 404 (adultCheck, kindCheck, artCheck, creditsCheck): cleared on a switched id
  56. static tfClearMarks = (&tfShow) => {
  57. tfX = tfShow
  58. for (tfF of ['adultCheck', 'kindCheck', 'artCheck', 'creditsCheck']) {
  59. if (textOr(&tfX[tfF]) != null && ('' + tfX[tfF]).includes('404')) { tfX[tfF] = null }
  60. }
  61. return tfX
  62. }
  63. // 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
  64. // migratedYear / migratedRelease
  65. static tfWithYear = (&tfShow, &tfYear, &tfDate) => {
  66. tfX = tfShow
  67. if (tfX.year != null && tfX.migratedYear == null) { tfX.migratedYear = tfX.year }
  68. tfX.year = tfYear
  69. if (textOr(&tfDate) != null && tfX.release != tfDate) {
  70. if (textOr(&tfX.release) != null && tfX.migratedRelease == null) { tfX.migratedRelease = tfX.release }
  71. tfX.release = tfDate
  72. }
  73. return tfX
  74. }
  75. // the record with the other TMDB id (the old one kept once in tmdbIdWas)
  76. static tfWithTmdb = (&tfShow, &tfId) => {
  77. tfX = tfShow
  78. if (tfX.tmdbIdWas == null) { tfX.tmdbIdWas = tfX.tmdbId }
  79. tfX.tmdbId = tfId
  80. return tfClearMarks(&tfX)
  81. }

Branches

Latest commits

  • ac58c1e5mission: HM56mre
  • 58979c0clog: HM54 held for decision, DP65 startedmre
  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre