diff --git a/packages/cli/src/commands/capture.ts b/packages/cli/src/commands/capture.ts index f1bc33216e..baa74ec321 100644 --- a/packages/cli/src/commands/capture.ts +++ b/packages/cli/src/commands/capture.ts @@ -8,7 +8,11 @@ export const examples: Example[] = [ ["JSON output for AI agents", "hyperframes capture https://example.com --json"], [ "Pull a video from the captured manifest by index", - "hyperframes capture video ./linear-video --index 0", + "hyperframes capture --video ./linear-video --index 0", + ], + [ + "List videos referenced in the captured manifest", + "hyperframes capture --video ./linear-video --list", ], ]; @@ -17,14 +21,11 @@ export default defineCommand({ name: "capture", description: "Capture a website as editable HyperFrames components", }, - subCommands: { - video: () => import("./capture/video.js").then((m) => m.default), - }, args: { url: { type: "positional", - description: "Website URL to capture", - required: true, + description: "Website URL to capture (omit when using --video)", + required: false, }, output: { type: "string", @@ -49,12 +50,44 @@ export default defineCommand({ description: "Output JSON (for AI agents / programmatic use)", default: false, }, + video: { + type: "string", + description: + "Switch to video-download mode: path to a captured project directory whose video-manifest.json should be read. Pair with --index, --video-url, or --list.", + }, + index: { + type: "string", + description: "(--video mode) Manifest entry index to download (0-based)", + }, + "video-url": { + type: "string", + description: "(--video mode) Exact video URL to download (must match a manifest entry)", + }, + list: { + type: "boolean", + description: "(--video mode) List manifest entries and exit", + default: false, + }, }, async run({ args }) { - const url = args.url as string; + if (args.video) { + const { runVideoMode } = await import("./capture/video.js"); + await runVideoMode({ + project: args.video as string, + index: (args.index as string | undefined) ?? null, + url: (args["video-url"] as string | undefined) ?? null, + list: args.list as boolean, + }); + return; + } - // citty fires parent's run AFTER routing to a subcommand; skip when args.url is a subcommand name. - if (url === "video") return; + const url = args.url as string | undefined; + if (!url) { + console.error( + "Missing URL. Pass a website URL, or use --video for video download.", + ); + process.exit(1); + } try { new URL(url); diff --git a/packages/cli/src/commands/capture/video.ts b/packages/cli/src/commands/capture/video.ts index 7bcd4f9a74..8aa612eb1d 100644 --- a/packages/cli/src/commands/capture/video.ts +++ b/packages/cli/src/commands/capture/video.ts @@ -1,21 +1,7 @@ -import { defineCommand } from "citty"; import { createWriteStream, existsSync, mkdirSync, readFileSync, unlinkSync } from "node:fs"; import { resolve, join, basename } from "node:path"; import { c } from "../../ui/colors.js"; import { safeFetch } from "../../capture/assetDownloader.js"; -import type { Example } from "../_examples.js"; - -export const examples: Example[] = [ - [ - "Download the hero video (index 0) from a captured project's manifest", - "capture video ./my-project --index 0", - ], - [ - "Download a specific video by exact URL", - "capture video ./my-project --url https://cdn.example.com/hero.mp4", - ], - ["List entries in the manifest without downloading", "capture video ./my-project --list"], -]; const MAX_VIDEO_BYTES = 250 * 1024 * 1024; const VIDEO_CONTENT_TYPE_RE = /^(video\/|application\/(mp4|octet-stream|x-mpegurl))/i; @@ -185,127 +171,108 @@ export function pickManifestEntry( }; } -export default defineCommand({ - meta: { - name: "video", - description: - "Download a video referenced in capture/extracted/video-manifest.json (on-demand; the capture pipeline only writes the manifest + preview PNGs)", - }, - args: { - project: { - type: "positional", - description: "Path to the captured project directory", - required: true, - }, - index: { - type: "string", - description: "Manifest entry index to download (0-based)", - }, - url: { - type: "string", - description: "Exact video URL to download (must match a manifest entry)", - }, - list: { - type: "boolean", - description: "List manifest entries (index, dimensions, heading) and exit", - }, - }, - // fallow-ignore-next-line complexity - async run({ args }) { - const projectDir = resolve(String(args.project)); - // standalone capture writes `/extracted/…`; W2H project nests under `/capture/extracted/…`. - const directPath = join(projectDir, "extracted", "video-manifest.json"); - const w2hPath = join(projectDir, "capture", "extracted", "video-manifest.json"); - const manifestPath = existsSync(directPath) ? directPath : w2hPath; - const isW2hLayout = manifestPath === w2hPath; - if (!existsSync(manifestPath)) { - console.error( - `${c.error("✗")} no video-manifest.json at ${directPath} or ${w2hPath}\n` + - ` Was this directory produced by \`hyperframes capture\`?`, - ); - process.exitCode = 1; - return; - } - let manifest: ManifestEntry[]; - try { - manifest = JSON.parse(readFileSync(manifestPath, "utf-8")); - } catch (e) { - console.error(`${c.error("✗")} video-manifest.json is malformed: ${(e as Error).message}`); - process.exitCode = 1; - return; - } +export interface VideoModeArgs { + project: string; + index?: string | null; + url?: string | null; + list?: boolean; +} - if (args.list) { - if (manifest.length === 0) { - console.log(c.dim("(manifest is empty — no