// BitChute as a platform: detection, ids, the extractor's label, the playable // file, the queue, moment links and the "auto" format. Synthetic ids only. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/bitchute.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { PLATFORM_VALUES, defaultWebpageUrl, detectPlatform, isSocialPlatform, queueKeyForUrl, } from "./platform"; import { extractVideoId } from "./videoId"; import { bitchutePlayableUrl } from "./bitchute"; import { platformFromMetadata, summarize } from "./transcripts-server"; import { platformMomentBaseUrl, platformMomentUrl } from "./momentUrl"; import { resolveDownloadFormatSelector } from "../ytdlp/downloadFormat"; import { dataDirIdForUrl } from "../ytdlp/runYtdlp"; const ID = "Zq3xVb7Kp2Lm"; const PAGE = `https://www.bitchute.com/video/${ID}/`; const FILE = `https://seed901.bitchute.com/AbCdEfGhIjKl/${ID}.mp4`; test("bitchute is a video platform", () => { assert.ok(PLATFORM_VALUES.includes("bitchute")); assert.equal(isSocialPlatform("bitchute"), false); }); test("every BitChute host is detected as bitchute; look-alikes are not", () => { for (const url of [ PAGE, `https://bitchute.com/video/${ID}/`, `https://old.bitchute.com/video/${ID}/`, `https://www.bitchute.com/embed/${ID}/`, "https://www.bitchute.com/channel/examplechannel/", "https://api.bitchute.com/api/beta/video", FILE, ]) { assert.equal(detectPlatform(url), "bitchute", url); } assert.equal(detectPlatform("https://notbitchute.com/video/x/"), null); assert.equal(detectPlatform("https://www.youtube.com/watch?v=AbC123xyz_9"), "youtube"); }); test("a video or embed URL gives the video id; a channel, playlist or profile gives none", () => { assert.equal(extractVideoId(PAGE), ID); assert.equal(extractVideoId(`https://www.bitchute.com/video/${ID}`), ID); assert.equal(extractVideoId(`https://old.bitchute.com/video/${ID}/?list=x`), ID); assert.equal(extractVideoId(`https://www.bitchute.com/embed/${ID}/`), ID); assert.equal(extractVideoId("https://www.bitchute.com/channel/examplechannel/"), null); assert.equal(extractVideoId("https://www.bitchute.com/playlist/Pl4yL1st0001/"), null); assert.equal(extractVideoId("https://www.bitchute.com/profile/Pr0f1le00001/"), null); // A single-video spawn pins its output to data//. assert.equal(dataDirIdForUrl(PAGE), ID); }); test("the canonical page is /video//, and BitChute has its own queue", () => { assert.equal(defaultWebpageUrl("bitchute", ID), PAGE); assert.equal(queueKeyForUrl(PAGE), "platform:bitchute"); assert.equal(queueKeyForUrl("https://www.bitchute.com/channel/examplechannel/"), "platform:bitchute"); }); test("yt-dlp's BitChute extractors label a record bitchute, as does a BitChute page", () => { assert.equal(platformFromMetadata({ extractor_key: "BitChute" }), "bitchute"); assert.equal(platformFromMetadata({ extractor_key: "BitChuteChannel" }), "bitchute"); assert.equal(platformFromMetadata({ extractor: "BitChute" }), "bitchute"); assert.equal(platformFromMetadata({ extractor_key: "Generic", webpage_url: PAGE }), "bitchute"); // An unknown host still lands where it always has. assert.equal(platformFromMetadata({ extractor_key: "Generic", webpage_url: "https://example.com/a.mp4" }), "youtube"); }); test("the playable file is the offered mp4 on a bitchute.com host", () => { assert.equal(bitchutePlayableUrl({ formats: [{ format_id: "0", ext: "mp4", url: FILE }] } as never), FILE); // The top-level url is the fallback. assert.equal(bitchutePlayableUrl({ url: FILE, ext: "mp4" }), FILE); // A live stream's manifest, or a file on another host, is not played. assert.equal(bitchutePlayableUrl({ formats: [{ ext: "mp4", url: "https://seed901.bitchute.com/x/live.m3u8" }] }), undefined); assert.equal(bitchutePlayableUrl({ formats: [{ ext: "mp4", url: "https://cdn.example.com/a.mp4" }] }), undefined); assert.equal(bitchutePlayableUrl({}), undefined); }); test("summarize: a BitChute record keeps its id and page and carries the file to play", () => { const s = summarize("example-channel", ID, { id: ID, title: "A synthetic upload", upload_date: "20240102", duration: 61, extractor: "BitChute", extractor_key: "BitChute", webpage_url: PAGE, formats: [{ format_id: "0", ext: "mp4", url: FILE }], url: FILE, }); assert.equal(s.platform, "bitchute"); assert.equal(s.id, ID); assert.equal(s.slug, `example-channel/${ID}`); assert.equal(s.webpageUrl, PAGE); assert.equal(s.mediaUrl, FILE); // No page URL on record: the canonical one. const bare = summarize("example-channel", ID, { id: ID, upload_date: "20240102", extractor_key: "BitChute" }); assert.equal(bare.webpageUrl, PAGE); assert.equal(bare.mediaUrl, undefined); }); test("a moment on BitChute links the bare page: its watch page takes no start time", () => { assert.equal(platformMomentUrl(PAGE, "bitchute", 125), PAGE); assert.equal(platformMomentUrl(PAGE, null, 125), PAGE); assert.equal(platformMomentBaseUrl(PAGE, "bitchute"), null); }); test('"auto" takes BitChute\'s one file', () => { // BitChute offers one format (an mp4 with no codec fields): `bestaudio` // matches nothing and `worst` takes that file. assert.equal(resolveDownloadFormatSelector("auto", "bitchute"), "bestaudio/worst"); });