@extractus/oembed-extractor

中文文档
6.0.0发布于 2026/08/06MITTypeScriptESM + CJS近 30 天下载 9.1万

Get oEmbed data from given URL.

原始使用文档
文档目录12 节
  1. Install
  2. Deno
  3. Node.js / Bun
  4. Usage
  5. APIs
  6. extract()
  7. findProvider()
  8. hasProvider()
  9. setProviderList()
  10. Development
  11. License
  12. Support the project

@extractus/oembed-extractor

Extract oEmbed content from given URL.

JSR npm version CI test

Install

Deno

deno add jsr:@extractus/oembed-extractor

Node.js / Bun

pnpm add jsr:@extractus/oembed-extractor
# or
npx jsr add @extractus/oembed-extractor
# or
bunx jsr add @extractus/oembed-extractor

Alternatively, install from npm:

npm install @extractus/oembed-extractor
# or
bun add @extractus/oembed-extractor

Usage

import { extract } from "jsr:@extractus/oembed-extractor";

const data = await extract("https://www.youtube.com/watch?v=x2bqscVkGxk");
console.log(data);

APIs


extract()

Load and extract oEmbed data from a URL.

Syntax

extract(url: string): Promise<OembedData>
extract(url: string, params?: Params): Promise<OembedData>
extract(url: string, params?: Params, fetcher?: Fetcher): Promise<OembedData>

Example:

import { extract } from "jsr:@extractus/oembed-extractor";

try {
  const result = await extract("https://www.youtube.com/watch?v=x2bqscVkGxk");
  console.log(result);
} catch (err) {
  console.error(err);
}

The result is an OembedData object:

interface OembedData {
  type: "rich" | "video" | "photo" | "link";
  version: string;
  title?: string;
  author_name?: string;
  author_url?: string;
  provider_name?: string;
  provider_url?: string;
  cache_age?: string | number;
  thumbnail_url?: string;
  thumbnail_width?: number;
  thumbnail_height?: number;
  method?: string;
  [key: string]: unknown;
}

Parameters

url required

URL of a valid oEmbed resource, e.g. https://www.youtube.com/watch?v=x2bqscVkGxk

params optional
PropertyTypeDescription
maxwidthnumberMax width of embed size
maxheightnumberMax height of embed size
themestringe.g. "dark" or "light"
langstringe.g. "en", "fr", "vi"

Note that some params are supported by some providers but not others. See the provider's oEmbed API docs for exact information.

fetcher optional

A custom fetch function with the signature (url: string) => Promise<Response>. Use this to customize HTTP behavior: proxy, headers, TLS, authentication, timeouts, etc.

Defaults to globalThis.fetch.

Deno (with proxy):

import { extract } from "@extractus/oembed-extractor";

const client = Deno.createHttpClient({
  proxy: { url: "http://proxy.example.com:8080" },
});
const myFetcher = (url: string) => fetch(url, { client });

const result = await extract("https://www.youtube.com/watch?v=x2bqscVkGxk", {}, myFetcher);

Node.js (with proxy via undici):

import { extract } from "@extractus/oembed-extractor";
import { fetch, ProxyAgent } from "undici";

const dispatcher = new ProxyAgent("http://proxy.example.com:8080");
const myFetcher = (url: string) => fetch(url, { dispatcher });

const result = await extract("https://www.youtube.com/watch?v=x2bqscVkGxk", {}, myFetcher);

Bun (with proxy):

import { extract } from "@extractus/oembed-extractor";

const myFetcher = (url: string) =>
  fetch(url, {
    proxy: "http://proxy.example.com:8080",
  });

const result = await extract("https://www.youtube.com/watch?v=x2bqscVkGxk", {}, myFetcher);

Custom headers:

const myFetcher = (url: string) =>
  fetch(url, {
    headers: {
      "user-agent": "MyBot/1.0",
      authorization: "Bearer token123",
    },
  });

const result = await extract(url, {}, myFetcher);

Request timeout:

const myFetcher = (url: string) =>
  fetch(url, {
    signal: AbortSignal.timeout(5000),
  });

const result = await extract(url, {}, myFetcher);

findProvider()

Find the provider that matches a given URL.

Syntax

findProvider(url: string): FindResult | null

Example:

import { findProvider } from "jsr:@extractus/oembed-extractor";

const provider = findProvider("https://www.youtube.com/watch?v=x2bqscVkGxk");
console.log(provider?.endpoint); // "https://www.youtube.com/oembed"

hasProvider()

Check if a URL is supported by any registered provider.

Syntax

hasProvider(url: string): boolean

Example:

import { hasProvider } from "jsr:@extractus/oembed-extractor";

hasProvider("https://www.youtube.com/watch?v=x2bqscVkGxk"); // true
hasProvider("https://example.com/unknown"); // false

setProviderList()

Replace the provider list with a custom set of providers, overriding the default.

Syntax

setProviderList(providers: Provider[]): number

Example:

import { setProviderList } from "jsr:@extractus/oembed-extractor";

const count = setProviderList([
  {
    provider_name: "Alpha",
    provider_url: "https://alpha.com",
    endpoints: [
      {
        schemes: ["https://store.alpha.com/*"],
        url: "https://api.alpha.com/oembed",
      },
    ],
  },
]);

Default list of resource providers is synchronized from oembed.com.

If you want to modify the providers list, please make a pull request on iamcal/oembed then create an issue/pr here to ask for sync.


Development

git clone https://github.com/extractus/oembed-extractor.git
cd oembed-extractor

# run tests
deno test --allow-all

# lint
deno lint

# build npm package
deno run -A ./scripts/build_npm.ts

# sync providers from oembed.com
deno task sync

License

The MIT License (MIT)

Support the project

This project is maintained in my spare time. If you find it helpful, there are a few simple ways to support its continued development:

Every bit of support helps keep this project actively maintained. Thank you! ❤️


版本与发布记录

@extractus/oembed-extractor 共发布 22 个版本,首次发布于 2022/11/29;过去 12 个月发布了 3 个版本。

版本发布日期距今
6.0.0latest2026/08/063 个月前
5.0.02026/07/223 个月前
4.1.02026/05/036 个月前
4.0.92025/09/041.2 年前
4.0.82025/05/041.5 年前
4.0.72025/04/131.6 年前

关于 @extractus/oembed-extractor 的常见问题

@extractus/oembed-extractor 是什么?

Get oEmbed data from given URL.

如何安装 @extractus/oembed-extractor?

在项目目录运行 npm install @extractus/oembed-extractor,或使用 pnpm add / yarn add / bun add。

@extractus/oembed-extractor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@extractus/oembed-extractor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@extractus/oembed-extractor 可以商用吗?

@extractus/oembed-extractor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@extractus/oembed-extractor 的下载量有多少?

根据 npm 官方下载统计,@extractus/oembed-extractor 在 2026/10/14 – 2026/11/12 这 30 天内被下载 91,457 次,日均约 3,049 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@extractus/oembed-extractor 还在维护吗?

最新版本 6.0.0 发布于 2026/08/06(3 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 3 个;首次发布于 2022/11/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。