// Tests that umtool's two yt-dlp spawns carry the platform's fixed args from // common's ONE table — a Rumble clip fetch or availability check without // `--impersonate chrome` 403s at Cloudflare (yt-dlp #17496). // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { PLATFORM_ARGS } from "yt-dlp-transcript-common/ytdlp/platformArgs.mjs"; import { clipFetchArgs } from "./build-video.mjs"; import { simulateArgs } from "./check-availability.mjs"; const RUMBLE = "https://rumble.com/v7e07us-some-title.html"; const YOUTUBE = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"; /** The args between two markers, so the assertion names the position too. */ const slice = (argv, from, to) => argv.slice(argv.indexOf(from) + 1, argv.indexOf(to)); test("a Rumble clip fetch carries the rumble platform args, before the retry's extra", () => { const argv = clipFetchArgs({ url: RUMBLE, from: 12, to: 20.5, fmt: "b", dest: "/x/out.mp4", extra: ["--downloader-args", "ffmpeg_i:-extension_picky 0"], }); assert.deepEqual( slice(argv, "--force-keyframes-at-cuts", "-f"), [...PLATFORM_ARGS.rumble, "--downloader-args", "ffmpeg_i:-extension_picky 0"], ); assert.ok(argv.includes("--impersonate")); assert.deepEqual(argv.slice(-2), ["--", RUMBLE]); assert.equal(argv[argv.indexOf("--download-sections") + 1], "*12.00-20.50"); }); test("a YouTube clip fetch gets youtube's request pace and no impersonation", () => { const argv = clipFetchArgs({ url: YOUTUBE, from: 1, to: 2, fmt: "b", dest: "/x/out.mp4" }); assert.deepEqual(slice(argv, "--force-keyframes-at-cuts", "-f"), ["--sleep-requests", "1"]); assert.ok(!argv.includes("--impersonate")); }); test("youtube carries --sleep-requests 1; a URL on no known platform carries nothing", () => { assert.deepEqual([...PLATFORM_ARGS.youtube], ["--sleep-requests", "1"]); const other = "https://example.com/some/video"; assert.deepEqual(slice(simulateArgs(other), "--no-warnings", "--"), []); assert.deepEqual( slice(clipFetchArgs({ url: other, from: 1, to: 2, fmt: "b", dest: "/x/o.mp4" }), "--force-keyframes-at-cuts", "-f"), [], ); }); test("the availability simulate carries each platform's args", () => { const rumble = simulateArgs(RUMBLE); assert.deepEqual(slice(rumble, "--no-warnings", "--"), [...PLATFORM_ARGS.rumble]); assert.deepEqual(rumble.slice(-2), ["--", RUMBLE]); assert.ok(rumble.includes("--simulate")); assert.ok(!simulateArgs(YOUTUBE).includes("--impersonate")); assert.deepEqual(slice(simulateArgs(YOUTUBE), "--no-warnings", "--"), ["--sleep-requests", "1"]); });