import { test, expect } from "@playwright/test"; import { mkdir, readFile, readdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { channelStage, resetData, testPaths } from "./helpers"; // plans/live-capture.md: the video page's "Import a file" — a recording made by // hand (an MPEG-TS `.part`) previewed, then landed as the video's source: the // saved-video store, audio, media-import.json, the "Do not clean" marker, the // original moved. And the channel's "Keep videos by id" recording an id the // channel does not hold yet as pending. Synthetic files; the fake ffprobe // reads `__FORMAT=…__` / `__DUR=…__` markers and the fake ffmpeg's remux // copies them. Nothing is fetched. const SLUG = "test-transcribe"; // an Odysee channel (one-transcribe-channel) const ID = "v9import01"; const channelDir = () => join(testPaths().transcriptsDir, "channels", SLUG); test.beforeEach(async () => { await resetData("one-transcribe-channel"); }); test("Import a file: previewed, then landed as the video's source with its audio, kept, the original moved", async ({ page: p }) => { test.setTimeout(90_000); const dir = join(channelDir(), "data", ID); await mkdir(dir, { recursive: true }); await writeFile( join(dir, "metadata.info.json"), // The page URL names this id (an Odysee claim id is what follows the // last ":"), so the snapshot's reconcile pass leaves the dir where it is. JSON.stringify({ id: ID, title: `Synthetic ${ID}`, webpage_url: `https://odysee.com/@example:1/synthetic:${ID}`, duration: 1200 }), ); // Outside the channel and the store: a recording made by hand. const srcDir = join(testPaths().transcriptsDir, "import-src"); await mkdir(srcDir, { recursive: true }); const src = join(srcDir, "stream.from-start.mp4.part"); await writeFile(src, "__FORMAT=mpegts__ __DUR=1200__ synthetic recording bytes\n"); await p.goto(`/channels/${SLUG}/videos/${ID}`); const tools = p.getByRole("group", { name: "media tools" }); await tools.locator("summary").click(); const form = tools.getByLabel("import a file"); await expect(form.getByRole("button", { name: "Import", exact: true })).toBeDisabled(); await form.getByLabel("import file path").fill(src); await form.getByLabel("move the file").check(); await form.getByLabel("do not clean").check(); await form.getByLabel("import note").fill("keep this one"); await form.getByRole("button", { name: "Preview import" }).click(); const preview = form.getByRole("log", { name: `Preview import into ${SLUG}/${ID} output`, exact: true }); await expect(preview).toContainText("remuxed", { timeout: 30_000 }); await expect(preview).toContainText("dry run"); // A dry run lands nothing and moves nothing. expect(await readdir(dir)).not.toContain("saved-video.json"); await readFile(src); await expect(form.getByRole("button", { name: "Import", exact: true })).toBeEnabled(); await form.getByRole("button", { name: "Import", exact: true }).click(); const run = form.getByRole("log", { name: `Import into ${SLUG}/${ID} output`, exact: true }); await expect(run).toContainText("@@import-media", { timeout: 30_000 }); await expect(run).toContainText("Stored"); const pointer = JSON.parse(await readFile(join(dir, "saved-video.json"), "utf8")); expect(pointer.file).toBe("source-media.mp4"); expect(pointer.origin.requestedBy).toBe("import-media"); const prov = JSON.parse(await readFile(join(dir, "media-import.json"), "utf8")); expect(prov.entries[0].source.name).toBe("stream.from-start.mp4.part"); expect(prov.entries[0].finalized).toBe("remuxed"); expect(prov.entries[0].kept).toBe("new"); expect(await readdir(dir)).toEqual(expect.arrayContaining(["do-not-clean.json"])); expect((await readdir(dir)).some((n) => /^audio\./.test(n))).toBe(true); expect(await readdir(srcDir)).toEqual([]); }); test("Keep videos by id: a video the channel does not hold yet is pending, and listed", async ({ page: p }) => { await p.goto(channelStage(SLUG, "cleanup")); const box = p.getByLabel("keep videos by id"); await box.getByLabel("keep ids", { exact: true }).fill("v9notyet01"); await box.getByLabel("keep ids note").fill("keep when it lands"); await box.getByRole("button", { name: "Keep them" }).click(); await expect(box.getByRole("status")).toContainText("1 pending (not here yet)"); await expect(box.getByLabel("pending keep ids")).toContainText("v9notyet01 — keep when it lands"); const pending = JSON.parse(await readFile(join(channelDir(), "pending-keep.json"), "utf8")); expect(pending.entries.map((e: { id: string }) => e.id)).toEqual(["v9notyet01"]); });