Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

955 B
Raw Blame
import { assetFormatForExtension, fileExtension } from "./asset-formats.js";
import { fetchBoundedMedia } from "./bounded-media.js";
import { LIBRARY_TRANSFER_LIMITS } from "./resource-limits.js";

export function isPageCaptureVideoFileUrl(value, { declaredVideo = false, mimeType = '' } = {}) {
  try {
    const url = new URL(value);
    const extension = fileExtension(url.pathname);
    return ["http:", "https:"].includes(url.protocol)
      && (assetFormatForExtension(extension)?.kind === "video"
        || (declaredVideo || /^video\//iu.test(mimeType)) && !["m3u8", "mpd"].includes(extension));
  } catch {
    return false;
  }
}

export async function downloadPageCaptureVideo(value, options = {}) {
  if (!isPageCaptureVideoFileUrl(value, options)) return null;
  return fetchBoundedMedia(value, {
    kind: "video",
    maxBytes: LIBRARY_TRANSFER_LIMITS.maxVideoBytes,
    accept: "video/*",
    revalidateCache: true,
    ...options
  });
}