// LOCAL MEDIA LIBRARY, slice 1 (lane/local-media): a Local Archive channel made // from the New channel form, its library previewed, one recording with // provider metadata and one prepared by hand imported, and the local record's // page — all through the UI, against a synthetic library of a few bytes the // spec writes in the OS temp dir: a library may not lie inside the corpus or the // checkout (controller/localMediaLocation.ts). // Nothing is fetched; the library's files are never changed. import { test, expect } from "@playwright/test"; import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { resetData, testPaths, writeChannelConfig } from "./helpers"; const VTT = "WEBVTT\n\n00:00:01.000 --> 00:00:03.000\nA synthetic library cue\n"; // Short-form cue timings (mm:ss.mmm), what FFmpeg and hand-made subtitle files // write: the prepared recording carries them through preview (both cues // counted) and import (byte for byte). Its index is // common/controller/buildIndexLocalRecording.test.ts. const SHORT_VTT = "WEBVTT\n\n00:01.000 --> 00:03.000\nA short-form library cue\n\n01:02.500 --> 01:04.000\nA second short-form cue\n"; test("a Local Archive channel imports a library recording and a prepared one, playback left off", async ({ page }) => { await resetData("empty"); const library = join(tmpdir(), `archilyzer-e2e-local-library-${process.env.TEST_PARALLEL_INDEX ?? "0"}`); await rm(library, { recursive: true, force: true }); await mkdir(library, { recursive: true }); await writeFile(join(library, "aaaaaaaaaaa.mp4"), "synthetic mp4 a"); await writeFile(join(library, "aaaaaaaaaaa.info.json"), JSON.stringify({ id: "aaaaaaaaaaa", title: "Library episode", webpage_url: "https://www.youtube.com/watch?v=aaaaaaaaaaa", upload_date: "20200102", duration: 12, extractor_key: "Youtube", })); await writeFile(join(library, "aaaaaaaaaaa.vtt"), VTT); await writeFile(join(library, "talk.mp4"), "synthetic mp4 talk"); await writeFile(join(library, "talk.vtt"), SHORT_VTT); const before = (await readdir(library)).sort(); await page.goto("/channels/new"); await page.getByLabel("Local Archive").check(); await page.locator('input[name="name"]').fill("Local Spec Library"); await page.locator('input[name="localDirectory"]').fill(library); await page.getByRole("button", { name: "Create channel" }).click(); await expect(page).toHaveURL(/\/channels\/local-spec-library\/local-media$/); const config = JSON.parse(await readFile(join(testPaths().transcriptsDir, "channels", "local-spec-library", "config.json"), "utf8")); expect(config.localMedia).toEqual({ sourceId: "library-1", directory: library }); expect(config.url).toBeUndefined(); await page.getByRole("button", { name: "Preview library" }).click(); await expect(page.getByRole("status").filter({ hasText: "discovered" })).toHaveText( "2 discovered · 1 new · 0 occupied · 1 need review", ); // Cues / notes: the short-form transcript's two cues are read, not "no usable cues". const cuesOf = (media: string) => page.getByRole("row").filter({ has: page.getByLabel(`Import ${media}`) }).getByRole("cell").nth(3); await expect(cuesOf("talk.mp4")).toHaveText(/^2(?!\d)/); await expect(cuesOf("aaaaaaaaaaa.mp4")).toHaveText(/^1(?!\d)/); await page.getByLabel("Import aaaaaaaaaaa.mp4").check(); await page.getByRole("button", { name: "Prepare details for talk.mp4" }).click(); const form = page.getByRole("form", { name: "Prepare details for talk.mp4" }); await form.getByLabel("Method").selectOption("manual"); await form.getByLabel("Title").fill("A prepared talk"); await form.getByLabel("Recording date (optional)").fill("2021-03-04"); await form.getByRole("button", { name: "Review details" }).click(); await expect(form.getByLabel("Prepared recording details")).toContainText("Recording date: 2021-03-04"); await form.getByRole("button", { name: "Use details for import" }).click(); await expect(page.getByLabel("Import talk.mp4")).toBeChecked(); await page.getByRole("button", { name: "Import selected (2)" }).click(); await expect(page.getByText(/Imported 2; already occupied 0; rejected 0/)).toBeVisible({ timeout: 30_000 }); const data = join(testPaths().transcriptsDir, "channels", "local-spec-library", "data"); const ids = (await readdir(data)).sort(); expect(ids).toHaveLength(2); expect(ids).toContain("aaaaaaaaaaa"); const local = ids.find((id) => id.startsWith("local-"))!; expect((await readdir(join(data, local))).sort()).toEqual(["external-media.json", "metadata.info.json", "transcript.en.vtt"]); expect(JSON.parse(await readFile(join(data, local, "metadata.info.json"), "utf8")).title).toBe("A prepared talk"); // The short-form transcript is imported byte for byte, never rewritten. expect(await readFile(join(data, local, "transcript.en.vtt"), "utf8")).toBe(SHORT_VTT); // A local record's page names it a local recording, with no download card. await page.goto(`/channels/local-spec-library/videos/${local}`); await expect(page.getByLabel("Local recording")).toBeVisible(); await expect(page.getByRole("link", { name: "Open local media library" })).toBeVisible(); await expect(page.getByText("Download audio")).toHaveCount(0); // The channel page offers its Local library tab (it has a library). await page.goto("/channels/local-spec-library"); await expect(page.getByLabel("Local library stage tab")).toBeVisible(); // Playback stayed off, and the library was never touched. const after = JSON.parse(await readFile(join(testPaths().transcriptsDir, "channels", "local-spec-library", "config.json"), "utf8")); expect(after.localMedia.playback).toBeUndefined(); expect((await readdir(library)).sort()).toEqual(before); await rm(library, { recursive: true, force: true }); }); // Review fix 8: the tab is only on a channel that has a library; a library is // added through the New channel form or `pnpm ops local-media-configure`, and // the route, reachable by URL, says so for a channel without one. test("a channel without a library has no Local library tab, and its route names the command", async ({ page }) => { await resetData("empty"); await writeChannelConfig("plain-channel", { name: "Plain", url: "https://www.youtube.com/@plain" }); await page.goto("/channels/plain-channel"); await expect(page.getByLabel("Overview stage tab")).toBeVisible(); await expect(page.getByLabel("Local library stage tab")).toHaveCount(0); await page.goto("/channels/plain-channel/local-media"); await expect(page.getByText("This channel has no local media library.")).toBeVisible(); await expect(page.getByText(/pnpm ops local-media-configure --json '\{"slug":"plain-channel"/)).toBeVisible(); await expect(page.getByRole("button", { name: "Save library" })).toHaveCount(0); });