"use client"; import Link from "next/link"; import { useEffect, useState, useTransition } from "react"; import { Button } from "yt-dlp-transcript-common/components/ui/button"; import type { KeepVideosByIdsResult, KeepVideosResult } from "yt-dlp-transcript-common/controller/keepVideosMatching"; import type { PendingKeepEntry } from "yt-dlp-transcript-common/lib/pendingKeep-server"; import { keepVideoIdsAction, keepVideosAction, pendingKeepAction } from "../videos/[id]/videoActions"; // "Keep videos by id" (plans/live-capture.md; `pnpm ops keep-videos {ids}`): // a held video is marked now; one the channel does not hold yet — a live // stream, a VOD not fetched — is PENDING, and marked when its record is first // written. The channel's pending ids are listed. export function KeepByIdControl({ slug }: { slug: string }) { const [hydrated, setHydrated] = useState(false); const [ids, setIds] = useState(""); const [note, setNote] = useState(""); const [pendingList, setPendingList] = useState(null); const [result, setResult] = useState(null); const [error, setError] = useState(null); const [busy, start] = useTransition(); useEffect(() => { setHydrated(true); void pendingKeepAction(slug).then(setPendingList, () => setPendingList([])); }, [slug]); const list = ids .split(/[\s,]+/) .map((s) => s.trim()) .filter(Boolean); const go = () => start(async () => { setError(null); const res = await keepVideoIdsAction({ slug, ids: list, ...(note.trim() ? { note: note.trim() } : {}) }); if (!res.ok) { setError(res.error); return; } setResult(res.result); setPendingList(res.result.pendingAll); }); return (

Keep videos by id

setIds(e.target.value)} aria-label="keep ids" placeholder="ids, e.g. v7h8pxg (held or not yet)" className="rounded border border-border bg-card px-2 py-1 text-sm font-mono w-72 max-w-full" /> setNote(e.target.value)} aria-label="keep ids note" placeholder="note (optional)" className="rounded border border-border bg-card px-2 py-1 text-sm w-56 max-w-full" />
{error && (

{error}

)} {result && (

{result.marked.length} kept now {result.takenOver.length > 0 && ` (${result.takenOver.length} made yours: another writer had set them)`},{" "} {result.alreadyKept.length} already kept, {result.pending.length} pending (not here yet) {Object.keys(result.keptBy).length > 0 && ( {Object.entries(result.keptBy) .map(([id, by]) => `${id}: was set by ${by}`) .join("; ")} )}

)} {pendingList && pendingList.length > 0 && (

Kept when they arrive:

    {pendingList.map((e) => (
  • {e.id} {e.note ? ` — ${e.note}` : ""}
  • ))}
)}
); } // "Keep videos matching" (release 32; `pnpm ops keep-videos` before it): the // do-not-clean marker on every video of the channel whose title (or // description) matches a pattern — the cleanup sweeps then never delete their // audio. Preview lists the matches; Keep is armed by a preview of the same // pattern. export function KeepMatchingControl({ slug }: { slug: string }) { const [hydrated, setHydrated] = useState(false); useEffect(() => setHydrated(true), []); const [pattern, setPattern] = useState(""); const [description, setDescription] = useState(false); const [note, setNote] = useState(""); const key = `${pattern}\u0000${description}`; const [previewed, setPreviewed] = useState(null); const [result, setResult] = useState(null); const [error, setError] = useState(null); const [pending, start] = useTransition(); const go = (dryRun: boolean) => start(async () => { setError(null); const res = await keepVideosAction({ slug, pattern, fields: description ? ["title", "description"] : ["title"], ...(note.trim() ? { note: note.trim() } : {}), dryRun, }); if (!res.ok) { setError(res.error); setResult(null); return; } setResult(res.result); if (dryRun) setPreviewed(key); }); return (

Keep videos matching

setPattern(e.target.value)} aria-label="keep pattern" placeholder="pattern, e.g. interview|debate" className="rounded border border-border bg-card px-2 py-1 text-sm font-mono w-72 max-w-full" /> setNote(e.target.value)} aria-label="keep note" placeholder="note (optional)" className="rounded border border-border bg-card px-2 py-1 text-sm w-56 max-w-full" />
{error && (

{error}

)} {result && (

{result.matched.length} match{result.matched.length === 1 ? "" : "es"} of {result.considered} {result.dryRun ? "" : `; ${result.marked} kept now`} {result.takenOver > 0 && ` (${result.takenOver} ${result.dryRun ? "would be" : ""} made yours)`}, {result.alreadyKept} already kept {result.notDownloaded.length > 0 && `, ${result.notDownloaded.length} not downloaded`} {result.unscanned > 0 && `, ${result.unscanned} never scanned (not tested)`}

    {result.matched.slice(0, 200).map((m) => (
  • {m.id} {" "} {m.title} {m.alreadyKept ? ` (kept: ${m.keptBy ?? "you"})` : m.takenOver ? ` (${m.marked ? "made yours" : "would be made yours"}; was set by ${m.keptBy})` : m.marked ? " (kept now)" : ""}
  • ))}
)}
); }