// Instagram via gallery-dl (lane instagram): an account's posts and reels as a // posts channel. // // WHAT ONE RUN ASKS OF INSTAGRAM (gallery-dl 1.32.9's extractor/instagram.py): // - the account's id: one search request, and the profile page when that // fails — up to 2, and none once gallery-dl has cached the id; // - the feed: one request per page of up to 30 posts; // - gallery-dl sleeps 6-12 s before every request, by itself. // SYNC NEW reads ONE page (max-posts 30). A WALK (a first fetch, a full // re-walk, a resumed backfill, a sync continuing down to its watermark) reads // up to 120 posts and stops; the next run resumes from the cursor gallery-dl // logged, which re-reads that one page (the resume point is logged when a // page is LEFT, so the page a capped run ended inside is the resume point). // A WALK IS SIZED TO ITS MEDIA: 120 posts is its job's media budget in files, // and the posts whose media would not fit that budget are not archived by this // run, so every post a run archives has its media asked for in the same run. // The next run starts where THIS one did and lists them again (the posts this // run archived are skipped as known): no page size is assumed, so nothing is // lost whatever a page holds, and each run archives at least one post. A run that sent as many requests as // MAX_REQUESTS is stopped, whatever Instagram's page size turns out to be. // // A SYNC THAT CONTINUES (its page was all new, or it stopped part-way) walks on // down to the WATERMARK it began with: the posts it archived on the way are // skipped, never a reason to stop — stopping at them dropped everything // between them and the watermark. // // WHAT IT NEVER DOES: // - run without a login. Logged out, Instagram answers the feed with a // "Page Not Found" (one read, 18 Nov 2026), so a run with no cookie source // costs requests and reads nothing: refused before gallery-dl is spawned. // - retry. `extractor.instagram.retries=0`: gallery-dl's own default is to // wait 60 s on a 429 and ask again, four times. The first 429 (or 401/403) // ends the run and Instagram is left alone for an hour. // - carry on past a login, challenge or checkpoint page: Instagram's alert // goes up and every Instagram job is refused until a person's Recheck // (jobs/instagramGuard.ts). // - miss a refusal gallery-dl swallowed. Its account lookup catches every // exception and goes on, so each request line is read AS IT ARRIVES // (instagramSignals.ts instagramStopSignal): the first 429/401/403, login // page or challenge page ends the run and decides what happens next. // // gallery-dl prints everything it read as ONE JSON array when it exits, the // exception that ended it as the last row (`output.jsonl` is left OFF: with // it on, the exception is printed nowhere and the run exits 0 — a login wall // would read as "no new posts"). A run stopped early is stopped with SIGINT, // which gallery-dl answers by printing what it has. // // THE MEDIA are not fetched here: the run's CDN addresses are handed back as // `media` and the fetch controller fetches them in the same job // (instagramMedia.ts), because they expire. import { execa } from "execa"; // A kill on a child that never started signals the caller's own group: the // guard is installed by this import (lib/childKillGuard.ts). import "../lib/childKillGuard"; import { createInterface } from "node:readline"; import type { Readable } from "node:stream"; import { cookieArgs } from "../lib/cookiePolicy"; import { instagramAccountUrl, instagramHandleFromUrl, isInstagramUrl } from "../lib/instagram/ids"; import { getPaths, type Paths } from "../lib/paths"; import type { Post } from "../lib/posts"; import { noteInstagramServiceOutcome } from "../lib/serviceCookies-server"; import { recordPlatformCooldown } from "../jobs/downloadBackoff"; import { INSTAGRAM_PLATFORM, INSTAGRAM_RATE_LIMIT_HOLD_MS } from "../jobs/instagramGuard"; import { registerSocialFetcher, type PostFetchInput, type PostFetchResult, type SocialFetcher, type SocialFetcherProbe, } from "./fetchers"; import { parseInstagramRun, type InstagramListedPost } from "./instagramNormalize"; import { raisedServiceAlert } from "../lib/serviceCookies-server"; import { INSTAGRAM_SERVICE } from "../lib/serviceCookies"; import { classifyInstagramError, instagramErrorStatus, instagramStopSignal, isInstagramApiHost, isInstagramPrivateLine, parseInstagramCursorLine, parseInstagramRequestLine, type InstagramRequestLine, } from "./instagramSignals"; // What every child inherits (lib/childEnvGuard.mjs; review 2 of lane network-exits). import "../lib/childEnvGuard.mjs"; export const INSTAGRAM_FETCHER_ID = "instagram-gallery-dl"; // Instagram's feed page, at the most. export const INSTAGRAM_PAGE_POSTS = 30; // SYNC NEW: one page. export const INSTAGRAM_SYNC_MAX_POSTS = INSTAGRAM_PAGE_POSTS; // THE MEDIA A JOB MAY FETCH (instagramMedia.ts enforces it): a sync's, and a // walk's. A walk lists no more posts than its budget has files. export const INSTAGRAM_SYNC_MEDIA = { maxFiles: 40, maxBytes: 200 * 1024 * 1024 } as const; export const INSTAGRAM_WALK_MEDIA = { maxFiles: 120, maxBytes: 600 * 1024 * 1024 } as const; // A walk: four pages, then the next run resumes. Never under two pages: a // one-page walk ends inside its first page, before any resume point is logged. export const INSTAGRAM_WALK_MAX_POSTS = INSTAGRAM_WALK_MEDIA.maxFiles; export const INSTAGRAM_WALK_MIN_POSTS = 2 * INSTAGRAM_PAGE_POSTS; // The requests one run may send before it is stopped: the lookup's two, the // pages, and one to spare. export const INSTAGRAM_SYNC_MAX_REQUESTS = 4; export const INSTAGRAM_WALK_MAX_REQUESTS = 2 + INSTAGRAM_WALK_MAX_POSTS / INSTAGRAM_PAGE_POSTS + 1; export const INSTAGRAM_BUDGET_MS = 20 * 60_000; // "Continue from the top": the resume point of a sync that filled its one page // with new posts and met none it knew — more may lie below, and the page it // ended in logged no cursor. The next sync walks from the top down to the // watermark this one began with. export const INSTAGRAM_FROM_TOP_CURSOR = "top"; export const INSTAGRAM_NO_COOKIES = (slug: string) => `${slug} has no cookie source of its own, and Instagram shows an account's posts only to a login ` + "(logged out, its feed answers \"Page Not Found\"): nothing was asked. Set \"Cookies from browser\" on the " + "channel's Edit form (pnpm ops channel-config, cookiesFromBrowser) to a browser profile, or file:, " + "that is logged in to Instagram with an account kept for this — then fetch again."; export type InstagramRunPlan = { // "sync": one page from the top. "walk": up to maxPosts, from `cursor` or the top. mode: "sync" | "walk"; maxPosts: number; maxRequests: number; // gallery-dl's resume point, when the run continues from one. cursor?: string; // WHERE THE WALK ENDS (pinned posts aside: they sit on top of the grid // whatever their age, and are archived when new, never a stop): // "known" at the first post already archived, or older than `since` — // a sync from the top. // "watermark" at the first post older than `since`; a post already // archived is SKIPPED — a sync that continues, which meets // its own earlier posts on the way down. // "none" nowhere: a history walk reads on to the account's first post. stop: "known" | "watermark" | "none"; // The media this job may fetch. media: { maxFiles: number; maxBytes: number }; }; // What one run reads, from what the controller asks. export function planInstagramRun(input: Pick): InstagramRunPlan { const real = input.cursor && input.cursor !== INSTAGRAM_FROM_TOP_CURSOR ? input.cursor : undefined; const walk = !input.since || Boolean(input.cursor); const limit = input.limit && input.limit > 0 ? Math.floor(input.limit) : undefined; if (!walk) { return { mode: "sync", maxPosts: Math.min(limit ?? INSTAGRAM_SYNC_MAX_POSTS, INSTAGRAM_SYNC_MAX_POSTS), maxRequests: INSTAGRAM_SYNC_MAX_REQUESTS, stop: input.stopAtKnown === false ? "none" : "known", media: INSTAGRAM_SYNC_MEDIA, }; } return { mode: "walk", maxPosts: Math.max(INSTAGRAM_WALK_MIN_POSTS, Math.min(limit ?? INSTAGRAM_WALK_MAX_POSTS, INSTAGRAM_WALK_MAX_POSTS)), maxRequests: INSTAGRAM_WALK_MAX_REQUESTS, ...(real ? { cursor: real } : {}), // A walk with a watermark is a sync that continues; one without is the // history walk, which re-reads a page of archived posts on purpose. stop: input.since && input.stopAtKnown !== false ? "watermark" : "none", media: INSTAGRAM_WALK_MEDIA, }; } // The account's posts URL gallery-dl's posts extractor claims. export function instagramPostsUrl(handle: string): string { return `${instagramAccountUrl(handle)}posts/`; } export function buildInstagramGalleryDlArgs(opts: { handle: string; cookies?: string; plan: InstagramRunPlan }): string[] { return [ // The operator's own gallery-dl config is not read: it could carry a // login, a pace or a retry count this run must not inherit. "--config-ignore", "--no-input", "--no-colors", // Metadata only; ONE array at exit, the exception as its last row. "--dump-json", // The request lines and the "Cursor:" lines. "--verbose", // A post's own numbers as strings: its pk is beyond 2^53. "-o", "output.num-to-str=true", // NEVER wait and ask again: the first refusal ends the run. "-o", "extractor.instagram.retries=0", // A video's one file with its sound, not the DASH pair. "-o", "extractor.instagram.videos=merged", "-o", `extractor.instagram.max-posts=${opts.plan.maxPosts}`, ...(opts.plan.cursor ? ["-o", `extractor.instagram.cursor=${opts.plan.cursor}`] : []), ...cookieArgs(opts.cookies), instagramPostsUrl(opts.handle), ]; } export type InstagramRunOutput = { stdout: string; // The run could not be started at all (the binary is missing). spawnError?: string; timedOut: boolean; canceled: boolean; }; export type InstagramAlertKind = "challenge" | "auth-failure" | "refusal"; export type InstagramFetcherDeps = { bin: () => string; // Run gallery-dl. `onStderrLine` answers "stop" to end the run now (SIGINT: // gallery-dl prints what it has). run: ( bin: string, args: string[], opts: { signal: AbortSignal; drain?: AbortSignal; timeoutMs: number; onStderrLine: (line: string) => "stop" | void }, ) => Promise; // A signal for Instagram's alert (`challengeLine` set), or a clean read. // Answers the line for the job log when a clean read settled something. noteOutcome: (outcome: { challengeLine?: string; kind?: InstagramAlertKind; url?: string; channel?: string }) => Promise; // Whether Instagram's alert is up now. alertRaised: () => Promise; // Records the cooldown; answers when it ends (ms since the epoch). noteRateLimit: () => Promise; now: () => number; }; function readLines(input: Readable | null | undefined, onLine: (line: string) => void): Promise { if (!input) return Promise.resolve(); return new Promise((resolve) => { const rl = createInterface({ input, crlfDelay: Infinity }); rl.on("line", onLine); rl.on("close", resolve); }); } async function runGalleryDl( bin: string, args: string[], opts: { signal: AbortSignal; drain?: AbortSignal; timeoutMs: number; onStderrLine: (line: string) => "stop" | void }, ): Promise { const subprocess = execa(bin, args, { reject: false, stdin: "ignore", stderr: "pipe", timeout: opts.timeoutMs, cancelSignal: opts.signal, // SIGINT, never SIGTERM: gallery-dl answers an interrupt by printing what // it has read, and that is what a stopped run is told by. killSignal: "SIGINT", env: { PYTHONUNBUFFERED: "1" }, }); let stopped = false; const stop = () => { if (stopped) return; stopped = true; subprocess.kill("SIGINT"); }; opts.drain?.addEventListener("abort", stop, { once: true }); if (opts.drain?.aborted) stop(); const stderrDone = readLines(subprocess.stderr, (line) => { if (opts.onStderrLine(line) === "stop") stop(); }); const res = await subprocess; opts.drain?.removeEventListener("abort", stop); await stderrDone; const spawnError = `${res.code ?? ""} ${res.message ?? ""}`; const stdout = typeof res.stdout === "string" ? res.stdout : ""; return { stdout, ...(res.failed && /ENOENT/.test(spawnError) && !stdout ? { spawnError: `gallery-dl not found (looked for "${bin}"; set GALLERY_DL_BIN)` } : {}), timedOut: res.timedOut === true, canceled: res.isCanceled === true, }; } const defaultDeps = (paths: Paths = getPaths()): InstagramFetcherDeps => ({ bin: () => paths.galleryDlBin, run: runGalleryDl, noteOutcome: (o) => noteInstagramServiceOutcome(paths, o), alertRaised: async () => (await raisedServiceAlert(paths, INSTAGRAM_SERVICE)) !== null, noteRateLimit: () => recordPlatformCooldown(INSTAGRAM_PLATFORM, INSTAGRAM_RATE_LIMIT_HOLD_MS, paths), now: () => Date.now(), }); const hhmm = (ms: number) => new Date(ms).toISOString().slice(11, 16); // What a run cost Instagram, as a sentence for the job's log. export function instagramCostLine(requests: readonly InstagramRequestLine[]): string { const api = requests.filter((r) => isInstagramApiHost(r.host)); const pages = api.filter((r) => /\/feed\/user\//.test(r.path)).length; const lookups = api.length - pages; return ( `Cost: ${api.length} request(s) to Instagram ` + `(${lookups} for the account's id, ${pages} feed page(s)).` ); } export async function fetchInstagramPosts( input: PostFetchInput, given: Partial = {}, ): Promise { const deps = { ...defaultDeps(), ...given }; const { channelSlug, seenIds, since, signal } = input; const log = (line: string) => input.onLog?.(line); const handle = instagramHandleFromUrl(input.accountUrl) ?? input.handle; const cookies = input.cookies?.trim(); if (!cookies) { return { posts: [], complete: false, needsCookies: true, error: INSTAGRAM_NO_COOKIES(channelSlug) }; } if (!handle) return { posts: [], complete: false, error: `${input.accountUrl} names no Instagram account` }; const plan = planInstagramRun(input); const bin = deps.bin(); const args = buildInstagramGalleryDlArgs({ handle, cookies, plan }); // The cookie source itself is never printed: it may be a path or a profile's name. log( "Instagram login: the channel's own cookie source, read by gallery-dl. " + (plan.mode === "sync" ? `Reading one page (up to ${plan.maxPosts} posts) from the top.` : `Walking up to ${plan.maxPosts} posts ${plan.cursor ? "from the saved resume point" : "from the top"}` + (plan.stop === "watermark" ? ", down to the posts already archived." : ".")) + ` At most ${plan.maxRequests} requests, 6-12 s apart; a refusal is not retried.`, ); const requests: InstagramRequestLine[] = []; const cursors: string[] = []; let privateLine: string | undefined; let overCap = false; // The first request line that is a refusal: it ended the run. let live: ReturnType = null; const out = await deps.run(bin, args, { signal, ...(input.drain ? { drain: input.drain } : {}), timeoutMs: INSTAGRAM_BUDGET_MS, onStderrLine: (line) => { const c = parseInstagramCursorLine(line); if (c) { cursors.push(c); return; } if (isInstagramPrivateLine(line)) privateLine = line.trim().slice(0, 300); const r = parseInstagramRequestLine(line); if (!r || !isInstagramApiHost(r.host)) return; requests.push(r); if (!live) { live = instagramStopSignal(r); if (live) return "stop"; } if (requests.length >= plan.maxRequests && !overCap) { overCap = true; return "stop"; } }, }); if (out.spawnError) throw new Error(out.spawnError); const stopSignal = live as ReturnType; log(instagramCostLine(requests)); const rows = parseInstagramRun(out.stdout, { channelSlug, handle }); const listed = rows?.posts ?? []; const cursor = cursors.at(-1); // Which of what was listed is new, and where the walk met its end. let fresh: InstagramListedPost[] = []; let known = 0; let reachedEnd = false; for (const p of listed) { const isKnown = seenIds.has(p.post.id); if (p.pinned) { // On top of the grid whatever its age: archived when new, never a stop. if (isKnown) known++; else fresh.push(p); continue; } const isOld = Boolean(since) && p.post.createdAt <= since!; if (plan.stop === "known" && (isKnown || isOld)) { known++; reachedEnd = true; break; } if (plan.stop === "watermark" && isOld) { if (isKnown) known++; reachedEnd = true; break; } if (isKnown) { // A post this walk (or the run before it) archived: skipped, and the walk goes on. known++; continue; } fresh.push(p); } // A WALK IS SIZED TO ITS MEDIA: the posts whose media would not fit this // job's file budget are left for the next run, which lists them again from // the page the first of them was on. let trimmedAt: InstagramListedPost | undefined; if (plan.mode === "walk") { let files = 0; const keep: InstagramListedPost[] = []; for (const p of fresh) { if (keep.length > 0 && files + p.files.length > plan.media.maxFiles) { trimmedAt = p; break; } files += p.files.length; keep.push(p); } if (trimmedAt) { log( `${fresh.length - keep.length} of the ${fresh.length} new post(s) listed are left for the next run: their media would not fit ` + `this job's budget of ${plan.media.maxFiles} files. Each run's posts get their media in the same run.`, ); fresh = keep; } } const posts: Post[] = fresh.map((p) => p.post); const media = fresh.filter((p) => p.files.length > 0).map((p) => ({ id: p.post.id, url: p.post.url, files: p.files })); log( `gallery-dl listed ${listed.length} post(s): ${posts.length} new` + (known ? `, ${known} already archived` : "") + (rows?.unreadable ? `, ${rows.unreadable} unreadable (no id or date) left out` : "") + (rows?.otherKinds ? `, ${rows.otherKinds} not a post or reel left out` : "") + ".", ); // Where the next run picks up when this one did not finish. A run that // left posts behind for its media budget starts again WHERE THIS ONE DID // (its own cursor, or the top): which page a post was on is not known — // gallery-dl prints no page marks, and a page is not always 30 posts — so // any later cursor could skip the posts left behind. Otherwise: the last // page gallery-dl left; else the point it was given; else — when it saved // posts before leaving any page — the top. const start = plan.cursor ?? (input.cursor === INSTAGRAM_FROM_TOP_CURSOR ? INSTAGRAM_FROM_TOP_CURSOR : undefined); const resumeAt = trimmedAt ? (start ?? INSTAGRAM_FROM_TOP_CURSOR) : (cursor ?? start ?? (posts.length > 0 ? INSTAGRAM_FROM_TOP_CURSOR : undefined)); const base = { posts, requests: requests.filter((r) => isInstagramApiHost(r.host)).length, ...(media.length ? { media } : {}), mediaBudget: { ...plan.media }, }; const accountUrl = instagramAccountUrl(handle); const unfinished = resumeAt && !reachedEnd ? { cursor: resumeAt } : {}; // ── what the run met ────────────────────────────────────────────────── // A refusal seen on a request line decides, whatever the error row says; // then a private account; then the error row. const fromRow = rows?.error ? classifyInstagramError(rows.error, { requests, handle }) : null; const rateLimited = stopSignal?.class === "rate-limit" || (!stopSignal && fromRow?.class === "rate-limit"); const isPrivate = Boolean(privateLine) || fromRow?.class === "private"; const sig: { class: NonNullable["class"]; line: string; status?: number } | null = stopSignal ? { class: stopSignal.class, line: stopSignal.line, status: stopSignal.status } : isPrivate && !rateLimited ? { class: "private", line: privateLine ?? fromRow!.line } : fromRow ? { ...fromRow, ...(rows?.error && instagramErrorStatus(rows.error) !== null ? { status: instagramErrorStatus(rows.error)! } : {}) } : null; const alerted = async (kind: InstagramAlertKind, what: string, fix: string, line: string): Promise => { await deps.noteOutcome({ challengeLine: line, kind, url: accountUrl, channel: channelSlug }); return { ...base, complete: false, ...unfinished, needsCookies: true, block: kind === "challenge" ? "challenge" : kind === "refusal" ? "blocked" : "login", error: `${what}: ${line}. The run stopped and Instagram's alert is up: no Instagram job starts until ${fix}, ` + "and Recheck is pressed on the dashboard. Nothing retries by itself.", }; }; if (sig?.class === "challenge") { return alerted( "challenge", "Instagram answered with a challenge or checkpoint page", "the check is passed by hand in the browser this channel's cookie source names", sig.line, ); } if (sig?.class === "login") { return alerted( "auth-failure", "Instagram did not accept the login (its login page, or the \"Page Not Found\" it answers a logged-out read with)", "that browser (or cookies file) is logged in to Instagram again", sig.line, ); } if (sig?.class === "rate-limit") { // A 401 or a 403 is Instagram's "please wait a few minutes": ONE holds // Instagram for the hour; a SECOND with no clean read between needs a // person, not another hour. if (sig.status === 401 || sig.status === 403) { await deps.noteOutcome({ challengeLine: sig.line, kind: "refusal", url: accountUrl, channel: channelSlug }); if (await deps.alertRaised().catch(() => false)) { return { ...base, complete: false, ...unfinished, needsCookies: true, block: "blocked", error: `Instagram refused the read a second time in a row (${sig.line}), with no clean read between. ` + "The run stopped and Instagram's alert is up: no Instagram job starts until the account is looked at by hand " + "in the browser this channel's cookie source names, and Recheck is pressed on the dashboard. Nothing retries by itself.", }; } } const until = await deps.noteRateLimit().catch(() => deps.now() + INSTAGRAM_RATE_LIMIT_HOLD_MS); return { ...base, complete: false, ...unfinished, block: "blocked", error: `Instagram refused the read (${sig.line}): a rate limit. The run stopped at once and asked nothing more; ` + `no Instagram job starts before ${hhmm(until)} UTC (${Math.round(INSTAGRAM_RATE_LIMIT_HOLD_MS / 60_000)} min). Nothing retries by itself.`, }; } if (sig?.class === "private") { return { ...base, complete: false, error: `@${handle} is a private account and this channel's login does not follow it: nothing was read.`, }; } if (sig?.class === "not-found") { return { ...base, complete: false, block: "not-found", error: `Instagram has no account @${handle}: its own page answered 404 (renamed, deleted or suspended). What is archived is kept.`, }; } // Any other failure: a post already archived ends a sync before the row that failed mattered. if (sig?.class === "error" && !reachedEnd) { return { ...base, complete: false, ...(resumeAt ? { cursor: resumeAt } : {}), error: `gallery-dl failed: ${sig.line}` }; } if (!rows) { if (out.canceled || signal.aborted || out.timedOut || input.drain?.aborted || overCap) { log("The run was stopped before gallery-dl printed what it read; the next run starts where this one did."); return { posts: [], complete: false, ...(input.cursor ? { cursor: input.cursor } : {}), ...(input.drain?.aborted && !signal.aborted ? { drained: true } : {}), }; } return { posts: [], complete: false, error: "gallery-dl printed nothing this reads as its JSON output." }; } // A RUN THAT WAS STOPPED — cancelled, drained, out of time, at its request // cap — keeps what it printed and its place, and is NOT a clean read: it // settles no pending refusal (review 2, N6) and is never complete. const stoppedWhy = out.canceled || signal.aborted ? "Cancelled; the next run resumes where this one left off." : out.timedOut ? `Stopped at this run's ${Math.round(INSTAGRAM_BUDGET_MS / 60_000)}-minute budget; the next run resumes where this one left off.` : input.drain?.aborted ? "Drained; the next run resumes where this one left off." : overCap ? `Stopped at ${plan.maxRequests} requests, this run's cap: Instagram's pages were smaller than ${INSTAGRAM_PAGE_POSTS} posts. ` + "The next run resumes where this one left off." : null; if (stoppedWhy) { log(stoppedWhy); const drained = Boolean(input.drain?.aborted) && !out.canceled && !signal.aborted && !out.timedOut; return { ...base, complete: false, ...(resumeAt && !reachedEnd ? { cursor: resumeAt } : {}), ...(drained ? { drained: true } : {}) }; } // NO REQUEST LINE READ (review 2, N4): the request cap and the refusal watch // were blind — gallery-dl's log format changed, or --verbose was lost. A // failure whatever it printed: never a clean read, never complete. if (requests.length === 0) { return { ...base, complete: false, ...(resumeAt ? { cursor: resumeAt } : {}), error: "None of gallery-dl's requests could be read from its log, so this run's request cap and its watch for a refusal " + "saw nothing. What it listed is kept; fix the log reading (instagramSignals.ts) before the next fetch.", }; } // A clean read — it ended by itself, with no signal, at its end or at its // own cap: a pending signal is settled, and this is a request a person can name. const cleared = await deps.noteOutcome({ url: accountUrl, channel: channelSlug }); if (cleared) log(cleared.trimEnd()); if (trimmedAt) return { ...base, complete: false, ...(resumeAt ? { cursor: resumeAt } : {}) }; if (reachedEnd) return { ...base, complete: true }; // Fewer posts than were asked for: the walk reached the account's first post. if (rows.emitted < plan.maxPosts) return { ...base, complete: true }; if (plan.mode === "sync") { log( `All ${listed.length} posts of the page are new and none is archived: older new posts may lie below it. ` + "The next Sync new walks on from the top down to what is archived.", ); } return { ...base, complete: false, ...(resumeAt ? { cursor: resumeAt } : {}) }; } export const instagramGalleryDlFetcher: SocialFetcher = { id: INSTAGRAM_FETCHER_ID, label: "Instagram (gallery-dl)", platform: "instagram", fields: { cookies: true, binPath: true, limit: true }, detect(url: string): boolean { return isInstagramUrl(url) && instagramHandleFromUrl(url) !== null; }, // NO REQUEST: an account's details cannot be read without a login, and a // form's "Fetch details" press is not worth one. The handle and the // canonical URL are read off the URL. async probe(url: string): Promise { const handle = instagramHandleFromUrl(url); if (!handle) return { ok: false, error: "Not an Instagram account URL (https://www.instagram.com//)." }; return { ok: true, name: handle, handle, url: instagramAccountUrl(handle) }; }, fetch: (input) => fetchInstagramPosts(input), }; registerSocialFetcher(instagramGalleryDlFetcher);