import { browserLookupAction } from "../../../channels/[slug]/browserLookupActions"; import { OpsInputError, jobResponse, ops, optBool, optPositiveInt, optString, reqSlug, reqStringArray, } from "../_lib"; import { PAGE_READ_MAX_SCROLLS } from "yt-dlp-transcript-common/ytdlp/odyseePageReader"; export const dynamic = "force-dynamic"; // POST { slug, ids?: ["", …], listing?: true, scrolls?, queueKey? } // -> { ok: true, jobId } // // An Odysee record read from its page in a headless browser (release 32 R9), // for when yt-dlp's lbry lookup is refused: each named video's page is opened // and played, its claim and the file the player asks for are read out of the // page's own API answers, and its metadata.info.json is written (none yet: // whole, `_source: "browser"`) or completed (only what it lacks, and the one // stored format; in metadata.history.json as `browser-lookup`). `listing: // true` opens the channel's page, scrolls it `scrolls` times (default 5, at // most 40) and adds the uploads its playlist lacks at the top, newest first, // through the channel's title match filter. One page a minute, on the // platform's queue; not refused for a held platform. The log ends with a // `summary: {…}` line. At most 50 ids. export async function POST(request: Request) { return ops(request, ["slug", "ids", "listing", "scrolls", "queueKey"], async (body) => { const ids = body.ids === undefined ? undefined : reqStringArray(body, "ids"); const listing = optBool(body, "listing"); if (!ids && !listing) throw new OpsInputError('Send "ids" (videos to look up) or "listing": true'); const scrolls = optPositiveInt(body, "scrolls"); if (scrolls !== undefined && scrolls > PAGE_READ_MAX_SCROLLS) { throw new OpsInputError(`"scrolls" must be at most ${PAGE_READ_MAX_SCROLLS}`); } return jobResponse( await browserLookupAction(reqSlug(body, "slug"), { ...(ids ? { ids } : {}), ...(listing ? { listing: true } : {}), ...(scrolls !== undefined ? { scrolls } : {}), ...(optString(body, "queueKey") ? { queueKey: optString(body, "queueKey") } : {}), }), ); }); }