// The channel media tools' results in plain words (release 32 R6, // components/ChannelMediaTools.tsx): an attach-media or prepare-playable job's // `summary: {json}` line, said as sentences. Client-safe and pure. // The last line of an attach-media and a prepare-playable job's log // (controller/attachMedia.ts summaryOf, controller/preparePlayable.ts). export const MEDIA_SUMMARY_MARKER = "summary: "; export type AttachSummary = { dryRun: boolean; counts: Record; attached: number; created: string[]; failed: { id: string; error: string }[]; notHeld: string[]; lost: number; unmatched: string[]; ambiguous: string[]; alreadyAttached: number; heldWithoutMedia: string[] | null; stopped?: string; }; export type PlayableSummary = { dryRun: boolean; root: string; prepared: number; unchanged: number; unplayable: { id: string; reason: string }[]; noContainer: string[]; failed: { id: string; error: string }[]; stopped?: string; }; const n = (k: number, one: string, many = `${one}s`) => `${k} ${k === 1 ? one : many}`; export function attachSummaryWords(s: AttachSummary): string[] { const c = s.counts ?? {}; const lines: string[] = []; if (s.dryRun) { lines.push( `Would attach ${n(c.attach ?? 0, "held video")}` + ((c.create ?? 0) > 0 ? ` and write ${n(c.create ?? 0, "new record")}` : "") + ".", ); } else { lines.push( `Attached ${n(s.attached, "video")}` + (s.created.length > 0 ? ` (${n(s.created.length, "new record")})` : "") + ".", ); } if (s.alreadyAttached > 0) lines.push(`${n(s.alreadyAttached, "video")} already had a saved file (left alone; tick Replace to swap).`); if (s.notHeld.length > 0) lines.push(`${n(s.notHeld.length, "file")} for videos this channel does not hold (tick Create records to add them).`); if (s.unmatched.length > 0) lines.push(`${n(s.unmatched.length, "file")} with no video id in the name.`); if (s.ambiguous.length > 0) lines.push(`${n(s.ambiguous.length, "video")} with more than one candidate file: ${s.ambiguous.slice(0, 5).join(", ")}${s.ambiguous.length > 5 ? "…" : ""}.`); if (s.lost > 0) lines.push(`${n(s.lost, "folder")} marked lost (never attached).`); if (s.heldWithoutMedia && s.heldWithoutMedia.length > 0) lines.push(`${n(s.heldWithoutMedia.length, "held video")} with no file in the archive.`); if (s.failed.length > 0) lines.push(`${n(s.failed.length, "video")} failed: ${s.failed.slice(0, 3).map((f) => `${f.id} (${f.error})`).join("; ")}.`); if (s.stopped) lines.push(`Stopped (${s.stopped}): run it again to continue.`); return lines; } export function playableSummaryWords(s: PlayableSummary): string[] { const lines = [ s.dryRun ? `Would make ${n(s.prepared, "playable copy", "playable copies")}; ${s.unchanged} already up to date.` : `Made ${n(s.prepared, "playable copy", "playable copies")} with their torrents; ${s.unchanged} already up to date.`, `Under ${s.root}.`, ]; if (s.unplayable.length > 0) lines.push(`${n(s.unplayable.length, "video")} cannot be made playable without re-encoding: ${s.unplayable.slice(0, 3).map((u) => `${u.id} (${u.reason})`).join("; ")}.`); if (s.noContainer.length > 0) lines.push(`${n(s.noContainer.length, "video")} with no saved container.`); if (s.failed.length > 0) lines.push(`${n(s.failed.length, "video")} failed: ${s.failed.slice(0, 3).map((f) => `${f.id} (${f.error})`).join("; ")}.`); if (s.stopped) lines.push(`Stopped (${s.stopped}): run it again to continue.`); return lines; }