"use client"; import Link from "next/link"; import { useState } from "react"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; import { cancelJobAction } from "../jobs/actions"; import { findWholeCopiesAction } from "../channels/[slug]/videos/findCopyAction"; import { FIND_COPY_MARKER, FIND_COPY_OUTCOME_TEXT, readResultMarker, type FindCopiesResultView, } from "../lib/resultMarker"; // "Find copies of gone videos" (release 32; find-copy's scope mode, release // 31 lane C): for a channel — or every channel of a site — the gone videos // holding no media are looked up on the Wayback Machine and archive.org. // Preview is a dry run (the same paced lookups, nothing recorded or fetched) // listing each candidate and the copy it would use; Run is armed by a preview // of the same settings, looks again, records what has no copy and sends every // copy found to ONE fetch-copies job, linked here. type Gone = "no-transcript" | "all"; type Params = { gone: Gone; max: number; retryFailed: boolean }; const sameParams = (a: Params, b: Params) => a.gone === b.gone && a.max === b.max && a.retryFailed === b.retryFailed; export function FindCopiesControl(scope: { slug: string } | { siteId: string }) { const name = "slug" in scope ? scope.slug : scope.siteId; const [gone, setGone] = useState("no-transcript"); const [maxText, setMaxText] = useState("10"); const [retryFailed, setRetryFailed] = useState(false); const max = Math.min(200, Math.max(1, Math.floor(Number(maxText) || 10))); const params: Params = { gone, max, retryFailed }; const [preview, setPreview] = useState<{ params: Params; result: FindCopiesResultView | null } | null>(null); const [run, setRun] = useState<{ jobId: string | null; result: FindCopiesResultView | null } | null>(null); const armed = preview !== null && preview.result !== null && sameParams(preview.params, params); const body = (dryRun: boolean) => ({ ...("slug" in scope ? { slug: scope.slug } : { siteId: scope.siteId }), gone, max, retryFailed, dryRun }); return (

Find copies of gone videos

findWholeCopiesAction(body(true))} cancelAction={cancelJobAction} buttonLabel="Preview" runningLabel="Looking…" label={`Preview copies for ${name}`} onSettled={(started, out) => { if (!started) return; setPreview({ params, result: readResultMarker(out.log, FIND_COPY_MARKER) }); }} /> {preview?.result && } findWholeCopiesAction(body(false))} cancelAction={cancelJobAction} buttonLabel="Find and fetch copies" runningLabel="Finding copies…" label={`Find copies for ${name}`} disabled={!armed} onSettled={(started, out) => { if (!started) return; setRun({ jobId: out.jobId, result: readResultMarker(out.log, FIND_COPY_MARKER) }); }} /> {!armed &&

Preview these settings first.

} {run && (

{run.jobId && ( <> find-copy job {run.jobId} {": "} )} {run.result ? `${run.result.looked.filter((l) => l.outcome === "fetch").length} cop${run.result.looked.filter((l) => l.outcome === "fetch").length === 1 ? "y" : "ies"} found` : "finished"} {run.result?.fetchJobId && ( <> {" · "} fetch-copies job {run.result.fetchJobId} )} {run.result?.refused && · fetch refused: {run.result.refused}}

)}
); } function FindCopiesResult({ result, label }: { result: FindCopiesResultView; label: string }) { const s = result.skipped; return (

{result.eligible} gone video{result.eligible === 1 ? "" : "s"} with no media in {result.channels.length} channel {result.channels.length === 1 ? "" : "s"}; {result.looked.length} looked up {result.left > 0 && `, ${result.left} left for a later run`} {s.recent.length > 0 && `; ${s.recent.length} left out (a recent attempt found none)`} {s.unreadable.length > 0 && `; ${s.unreadable.length} channel(s) unreadable`} {result.stopped && ` · stopped: ${result.stopped}`}

{result.looked.length > 0 && ( {result.looked.map((l) => ( ))}
Video Gone Outcome Copy
{l.slug}/{l.id} {!l.noTranscript && (transcribed)} {l.gone} {FIND_COPY_OUTCOME_TEXT[l.outcome] ?? l.outcome} {l.via ?? "—"}
)}
); }