import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; import { test, expect } from "@playwright/test"; import { baseUrl } from "./baseUrl"; import { channelStage, generateReport, readJson, resetData, resolvePath, testPaths } from "./helpers"; import { odyseePageFixtureFile } from "./servers"; import { cdnUrlOf, pageUrlOf, syntheticChannel, syntheticClaim, videoPageRead, } from "yt-dlp-transcript-common/testing/web/fakeOdyseePage.mjs"; // Release 32 R9: the browser lookup, by hand (the UI-without-AI rule). An // Odysee record that stores no media URL is read from its page — here from the // slot's recorded page reads (E2E_ODYSEE_PAGE_FIXTURE, e2e/servers.ts; no // browser opens on the e2e server) — and the record gains the file the page // named. The per-channel setting is on the Configure form; the listing's // button is in the Playlist stage of an Odysee channel. const CHANNEL = "test-transcribe"; const FIXTURE = "one-transcribe-channel"; const ROOT = `${testPaths().transcriptsDir}/channels/${CHANNEL}`; const ch = syntheticChannel({ name: "@synthchan", title: "Synth Channel" }); const claim = syntheticClaim({ name: "a-synthetic-stream", title: "A Synthetic Stream", channel: ch }); const CLAIM = claim.claim_id; async function invalidate() { await fetch(`${baseUrl}/api/test/invalidate-cache`).catch(() => {}); } test("configure: the browser lookup setting saves and clears", async ({ page }) => { await resetData(FIXTURE); await generateReport(page, CHANNEL); await page.goto(channelStage(CHANNEL, "configure")); const box = page.getByLabel("browser lookup", { exact: true }); await expect(box).not.toBeChecked(); await box.check(); await page.getByRole("button", { name: /save changes/i }).click(); await expect .poll(async () => (await readJson<{ browserLookup?: boolean }>(`${ROOT}/config.json`)).browserLookup) .toBe(true); await page.reload(); await expect(page.getByLabel("browser lookup", { exact: true })).toBeChecked(); await page.getByLabel("browser lookup", { exact: true }).uncheck(); await page.getByRole("button", { name: /save changes/i }).click(); await expect .poll(async () => "browserLookup" in (await readJson>(`${ROOT}/config.json`))) .toBe(false); }); test("video page: Read from the page completes the record with the file the page named", async ({ page }) => { test.setTimeout(120_000); await resetData(FIXTURE); const dir = resolvePath(`${ROOT}/data/${CLAIM}`); await mkdir(dir, { recursive: true }); await writeFile( `${dir}/metadata.info.json`, JSON.stringify({ id: CLAIM, extractor: "lbry", title: "A synthetic stream", webpage_url: pageUrlOf(claim) }), ); const fixture = odyseePageFixtureFile(resolvePath(testPaths().transcriptsDir)); await writeFile(fixture, JSON.stringify({ [pageUrlOf(claim)]: videoPageRead({ claim }) })); try { await invalidate(); await page.goto(`/channels/${CHANNEL}/videos/${CLAIM}`); await page.getByRole("button", { name: "Read from the page" }).click(); await expect .poll( async () => { const info = JSON.parse(await readFile(`${dir}/metadata.info.json`, "utf8")) as { formats?: { url: string }[] }; return info.formats?.[0]?.url ?? null; }, { timeout: 90_000 }, ) .toBe(cdnUrlOf(claim)); const info = JSON.parse(await readFile(`${dir}/metadata.info.json`, "utf8")) as Record; expect(info.title).toBe("A synthetic stream"); expect(typeof info._browserLookupAt).toBe("string"); // The page now offers the stored URL the lookup found (R7's control). await invalidate(); await page.reload(); await expect(page.getByLabel("stored media URL", { exact: true })).toBeVisible(); } finally { await rm(fixture, { force: true }); } });