// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/bitchuteImport.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { importPlatformSignal, resolveBitchuteImportUrl } from "./bitchuteImport"; import type { DownloadOutcomeRecord } from "../lib/downloadOutcome"; const ID = "Zq3xVb7Kp2Lm"; const PAGE = `https://www.bitchute.com/video/${ID}/`; test("every URL of one video resolves to its canonical page", () => { for (const url of [ PAGE, `https://www.bitchute.com/video/${ID}`, `https://old.bitchute.com/video/${ID}/`, `https://bitchute.com/embed/${ID}/`, ]) { assert.deepEqual(resolveBitchuteImportUrl(url), { ok: true, id: ID, url: PAGE }, url); } }); test("a channel or playlist page is refused with the way to take one", () => { for (const url of [ "https://www.bitchute.com/channel/examplechannel/", "https://www.bitchute.com/playlist/Pl4yL1st0001/", ]) { const r = resolveBitchuteImportUrl(url); assert.equal(r.ok, false, url); assert.match((r as { error: string }).error, /make it a channel with that URL and sync it/); } }); function outcome(over: Partial): DownloadOutcomeRecord { return { videoId: ID, status: "ok", startedAt: "2026-01-01T00:00:00.000Z", finishedAt: "2026-01-01T00:01:00.000Z", attempts: [], ...over, }; } test("a 429 backs BitChute off; a download that came down settles it; a per-video failure says nothing", () => { assert.equal(importPlatformSignal(outcome({ status: "ok" })), "clean"); assert.equal(importPlatformSignal(outcome({ status: "ok-auto-transcribed" })), "clean"); assert.equal( importPlatformSignal(outcome({ status: "failed", failureClass: "rate_limit" })), "rate_limit", ); assert.equal( importPlatformSignal(outcome({ status: "failed", failureClass: "network" })), "network", ); // Classified from the last attempt when the record carries no class. assert.equal( importPlatformSignal( outcome({ status: "failed", attempts: [ { mode: "default", startedAt: "", finishedAt: "", error: "ERROR: [BitChute] x: HTTP Error 429: Too Many Requests" } as never, ], }), ), "rate_limit", ); assert.equal( importPlatformSignal(outcome({ status: "failed", failureClass: "per_video" })), null, ); assert.equal(importPlatformSignal(outcome({ status: "skipped-filtered" })), null); // The media came down; only a subtitle fetch was refused. assert.equal( importPlatformSignal(outcome({ status: "ok", failureClass: "subs_rate_limit" })), null, ); });