"use client"; import Link from "next/link"; import { useEffect, useState, useTransition } from "react"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; import { Button } from "yt-dlp-transcript-common/components/ui/button"; import { cancelJobAction } from "../../../../../jobs/actions"; import { ImportFileForm, RecordLiveForm } from "../../../components/LiveMediaTools"; import { archiveOrgRefreshAction, attachVideoMediaAction, fetchChatAction, playableVideoAction, waybackRefreshAction, type RecordsRefreshResult, } from "../mediaToolsActions"; // "Media tools" (release 32): the video-level operations that were CLI- or // ops-only — attach this video's file from a local archive, make a playable // copy of its saved container, and bring the channel's Wayback or archive.org // records up to their rules. Every one previews first where it writes. const input = "rounded border border-border bg-card px-2 py-1 text-sm"; export function VideoMediaTools({ slug, videoId, saved, wayback, archiveOrg, }: { slug: string; videoId: string; // A source container is in the saved-video store. saved: boolean; // A Wayback Machine copy (wayback.json, or a web.archive.org page URL). wayback: boolean; // An archive.org file record. archiveOrg: boolean; }) { return (
Media tools

Live chat replay

fetchChatAction(slug, videoId)} cancelAction={cancelJobAction} buttonLabel="Fetch live chat" runningLabel="Fetching the chat…" label={`Fetch live chat of ${videoId}`} />
{saved && (

Playable copy

playableVideoAction(slug, videoId)} cancelAction={cancelJobAction} buttonLabel="Make playable copy" runningLabel="Remuxing…" label={`Make playable copy of ${videoId}`} />
)} {wayback && ( waybackRefreshAction(slug, { dryRun, ...(title ? { title } : {}) })} /> )} {archiveOrg && ( archiveOrgRefreshAction(slug, { dryRun })} /> )}
); } function AttachFromArchive({ slug, videoId, saved }: { slug: string; videoId: string; saved: boolean }) { const [source, setSource] = useState(""); const [file, setFile] = useState(""); const [replace, setReplace] = useState(false); const key = `${source}\u0000${file}\u0000${replace}`; const [previewed, setPreviewed] = useState(null); const opts = { source, ...(file.trim() ? { file } : {}), ...(replace ? { replace: true } : {}) }; return (

Attach from a local archive

{saved && ( )}
attachVideoMediaAction(slug, videoId, { ...opts, dryRun: true })} cancelAction={cancelJobAction} buttonLabel="Preview attach" runningLabel="Reading the archive…" label={`Preview attach of ${videoId}`} disabled={!source.trim()} onSettled={(started) => setPreviewed(started ? key : null)} /> attachVideoMediaAction(slug, videoId, opts)} cancelAction={cancelJobAction} buttonLabel="Attach" runningLabel="Attaching…" label={`Attach media to ${videoId}`} disabled={previewed !== key} />
); } function RecordsRefresh({ title, what, slug, videoId, withTitle = false, run, }: { title: string; what: string; slug: string; videoId: string; withTitle?: boolean; run: (dryRun: boolean, title?: { id: string; title?: string; upload_date?: string }) => Promise; }) { const [hydrated, setHydrated] = useState(false); useEffect(() => setHydrated(true), []); const [recTitle, setRecTitle] = useState(""); const [recDate, setRecDate] = useState(""); const key = `${recTitle}\u0000${recDate}`; const [previewed, setPreviewed] = useState(null); const [result, setResult] = useState(null); const [pending, start] = useTransition(); const go = (dryRun: boolean) => start(async () => { const t = withTitle && (recTitle.trim() || recDate.trim()) ? { id: videoId, title: recTitle, upload_date: recDate } : undefined; const res = await run(dryRun, t); setResult(res); if (dryRun && res.ok) setPreviewed(key); }); const label = `${what} refresh`; return (

{title}

{withTitle && (
)}
{result && !result.ok && (

{result.error}

)} {result?.ok && (

{result.summary}

{result.renamed.length > 0 && (
    {result.renamed.map((r) => (
  • {r.from} → {result.dryRun ? r.to : {r.to}}
  • ))}
)} {result.log.length > 0 && (
{result.log.join("\n")}
)}
)}
); }