// yt-dlp IS NEVER STARTED ON AN instagram.com URL (lane instagram, review 1 // S11, review 2 N8). Instagram is read as a posts channel, by its own // fetcher, on its own queue, behind its own guard; a yt-dlp run on a reel or // an account would be a second, unguarded path to the same site. A single // reel's import comes with a later slice. // // Plain JS (with JSDoc types) so the ONE pass every yt-dlp argv takes before a // spawn — `jitterSleepArgs` in ../jitter.mjs — can ask it for common's TS and // for umtool's .mjs scripts alike. `./ytdlp.ts` re-exports this for TS callers. export const INSTAGRAM_YTDLP_REFUSAL = "Instagram is read as a posts channel; a single reel import comes with a later slice. " + "No yt-dlp process was started for this instagram.com URL."; /** * Whether `value` is an http(s) URL on instagram.com. * @param {unknown} value * @returns {boolean} */ export function isInstagramComUrl(value) { if (typeof value !== "string" || !/^https?:\/\//i.test(value.trim())) return false; try { return new URL(value.trim()).hostname.toLowerCase().replace(/^www\./, "") === "instagram.com"; } catch { return false; } } /** * The first argument that is an instagram.com URL, or null. * @param {readonly string[]} args * @returns {string | null} */ export function instagramUrlInArgs(args) { for (const a of args) if (isInstagramComUrl(a)) return a; return null; } /** * Throws the refusal when the argv names an instagram.com URL. * @param {readonly string[]} args */ export function refuseInstagramYtdlp(args) { if (instagramUrlInArgs(args)) throw new Error(INSTAGRAM_YTDLP_REFUSAL); }