"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 { attachMediaAction } from "../attachMediaActions"; import { preparePlayableAction } from "../playableActions"; import { ImportFileForm, RecordLiveForm } from "./LiveMediaTools"; import { readResultMarker } from "../../../lib/resultMarker"; import { MEDIA_SUMMARY_MARKER, attachSummaryWords, playableSummaryWords, type AttachSummary, type PlayableSummary, } from "../lib/mediaToolsWords"; // The channel-wide media operations that were CLI-only (release 32 R6), beside // the saved-video store they write into: // // Attach media from a local archive `archilyzer media attach // ` — every held video's file out of a directory, a .zip or a // .7z into the store (`--match`, `--create-records`, `--replace`) // Playable copies `archilyzer media playable ` — // every saved container remuxed to a browser-playable copy with its // torrent (`--trackers`, `--root`) // // Each previews first (the job's dry run, which writes nothing) and the run is // armed by a preview of the same settings. Both jobs end their log with a // `summary: {json}` line: the result is said from it in plain words, and the // job is linked. function Outcome({ label, jobId, lines }: { label: string; jobId: string | null; lines: string[] | null }) { return (
{lines ? lines.map((l) =>

{l}

) :

The job left no summary; see its log.

} {jobId && (

job {jobId}

)}
); } export function ChannelMediaTools({ slug }: { slug: string }) { return (
Media for the whole channel
); } function AttachArchive({ slug }: { slug: string }) { const [source, setSource] = useState(""); const [match, setMatch] = useState(""); const [createRecords, setCreateRecords] = useState(false); const [replace, setReplace] = useState(false); const key = JSON.stringify([source.trim(), match.trim(), createRecords, replace]); const [previewed, setPreviewed] = useState(null); const [out, setOut] = useState<{ what: "preview" | "run"; jobId: string | null; lines: string[] | null } | null>(null); const opts = (dryRun: boolean) => ({ source: source.trim(), ...(match.trim() ? { match: match.trim() } : {}), ...(createRecords ? { createRecords: true } : {}), ...(replace ? { replace: true } : {}), ...(dryRun ? { dryRun: true } : {}), }); const settle = (what: "preview" | "run") => (started: boolean, o: { log: string; jobId: string | null }) => { if (!started) return; const s = readResultMarker(o.log, MEDIA_SUMMARY_MARKER); setOut({ what, jobId: o.jobId, lines: s ? attachSummaryWords(s) : null }); if (what === "preview") setPreviewed(key); }; return (

Attach media from a local archive

Every video this channel holds gets its file from the archive — matched by the id in the folder or file name — copied into the saved-video store with where it came from. Nothing is downloaded.

attachMediaAction(slug, opts(true))} cancelAction={cancelJobAction} buttonLabel="Preview attach" runningLabel="Reading the archive…" label={`Preview attach into ${slug}`} disabled={!source.trim()} onSettled={settle("preview")} /> attachMediaAction(slug, opts(false))} cancelAction={cancelJobAction} buttonLabel="Attach" runningLabel="Attaching…" label={`Attach media into ${slug}`} disabled={previewed !== key} onSettled={settle("run")} /> {previewed !== key &&

Preview these settings first.

} {out && }
); } function PlayableCopies({ slug }: { slug: string }) { const [trackers, setTrackers] = useState(""); const [root, setRoot] = useState(""); const trackerList = trackers .split(/[\s,]+/) .map((t) => t.trim()) .filter(Boolean); const key = JSON.stringify([trackerList, root.trim()]); const [previewed, setPreviewed] = useState(null); const [out, setOut] = useState<{ what: "preview" | "run"; jobId: string | null; lines: string[] | null } | null>(null); const opts = (dryRun: boolean) => ({ ...(trackerList.length > 0 ? { trackers: trackerList } : {}), ...(root.trim() ? { root: root.trim() } : {}), ...(dryRun ? { dryRun: true } : {}), }); const settle = (what: "preview" | "run") => (started: boolean, o: { log: string; jobId: string | null }) => { if (!started) return; const s = readResultMarker(o.log, MEDIA_SUMMARY_MARKER); setOut({ what, jobId: o.jobId, lines: s ? playableSummaryWords(s) : null }); if (what === "preview") setPreviewed(key); }; return (

Playable copies

Every saved container is copied, without re-encoding, into a file a browser can play (mp4 or webm), each with a torrent. A copy already made from the same file is skipped.

preparePlayableAction(slug, opts(true))} cancelAction={cancelJobAction} buttonLabel="Preview playable copies" runningLabel="Checking…" label={`Preview playable copies of ${slug}`} onSettled={settle("preview")} /> preparePlayableAction(slug, opts(false))} cancelAction={cancelJobAction} buttonLabel="Make playable copies" runningLabel="Remuxing…" label={`Playable copies of ${slug}`} disabled={previewed !== key} onSettled={settle("run")} /> {previewed !== key &&

Preview these settings first.

} {out && }
); }