// A cited moment mapped to the editor's directory (fetch_clip's first step), // shared by the tool and umtool's Research page so both ask the editor for the // same thing. // // Rumble: the cited id is the EMBED id (the record's `id`); the editor's // directory is the URL slug, read off the record's webpageUrl. The channel is // the one the record lives in, which is the editor's directory even when the // citation spelled it by name or in another case. A video the source does not // hold is passed as cited, with a note saying so. import { extractVideoId } from "yt-dlp-transcript-common/lib/videoId"; import { isVideoId, notFoundNote, type FetchClipRequest } from "./fetchClip"; import { findVideo } from "./search"; import type { ShardSource } from "./source"; export async function resolveClipTarget( source: ShardSource, handle: string, request: FetchClipRequest, ): Promise<{ note: string; ctx: { channel?: string; video?: string } }> { if (!("target" in request)) return { note: "", ctx: {} }; const target = request.target; let note = ""; const found = await findVideo(source, target.video, target.channel); if (found) { const webpageUrl = found.record.webpageUrl; const mapped = webpageUrl ? extractVideoId(webpageUrl) : null; target.video = mapped && isVideoId(mapped) ? mapped : target.video; target.channel = found.ch.slug; if (target.kind === "window" && webpageUrl) target.webpageUrl = webpageUrl; } else { note = `${notFoundNote(target.video, handle)}\n\n`; } return { note, ctx: { channel: target.channel, video: target.video } }; }