"use server"; import { persistVideosAction, type PersistVideosActionResult } from "../channels/[slug]/persistActions"; import { isPersistReplacePolicy, type PersistReplacePolicy } from "yt-dlp-transcript-common/controller/persistVideos"; import { isSourceVideoQuality, type SourceVideoQuality } from "yt-dlp-transcript-common/ytdlp/downloadFormat"; import { parseVideoList } from "./lib/videoList"; // "Save these videos" on the Saved videos page (release 32 R6): `pnpm ops // persist-videos` from the UI. The typed list is read (lib/videoList.ts) and // handed to persistVideosAction as the ops route hands it: a preview answers // with the plan's buckets and starts nothing; a run starts one persist-videos // job per channel with something to fetch. // // NOTHING BUT FUNCTIONS IS DECLARED HERE (a "use server" file). export async function persistVideoListAction(input: { text: string; format?: string; replace?: PersistReplacePolicy; dryRun: boolean; }): Promise { const { items, bad } = parseVideoList(input.text); if (bad.length > 0) { return { ok: false, error: `${bad.length} line(s) name no channel and video (slug/id, or a video page link): ` + bad .slice(0, 5) .map((b) => `line ${b.line} "${b.text.slice(0, 60)}"`) .join(", ") + (bad.length > 5 ? "…" : ""), }; } if (items.length === 0) return { ok: false, error: "No videos listed." }; const format: SourceVideoQuality | undefined = isSourceVideoQuality(input.format) ? input.format : undefined; return persistVideosAction({ items, dryRun: input.dryRun, ...(format ? { format } : {}), ...(isPersistReplacePolicy(input.replace) && input.replace !== "never" ? { replace: input.replace } : {}), }); }