import path from "node:path"; import { readFile } from "node:fs/promises"; import { liveDownloadRefusal, liveNowState, type LiveNowState } from "./liveNow"; // The live state a video's metadata.info.json records (lib/liveNow.ts), null // when it records none — or there is no readable record, which says nothing // either way: a download is not refused on a guess. export async function readLiveNowState(videoDir: string): Promise { try { const meta = JSON.parse(await readFile(path.join(videoDir, "metadata.info.json"), "utf8")) as unknown; return liveNowState(meta as Parameters[0]); } catch { return null; } } // The refusal for a download of this video, or null when its record says it // is not a stream in progress. export async function liveDownloadRefusalFor( videoDir: string, ids: { slug: string; videoId: string }, ): Promise { const state = await readLiveNowState(videoDir); return state ? liveDownloadRefusal(state, ids) : null; }