|
4 | 4 | Extract oEmbed content from given URL.
|
5 | 5 |
|
6 | 6 | [](https://badge.fury.io/js/@extractus%2Foembed-extractor)
|
| 7 | + |
7 | 8 | [](https://github.com/extractus/oembed-extractor/actions)
|
8 | 9 | [](https://coveralls.io/github/extractus/oembed-extractor)
|
9 |
| - |
10 |
| - |
11 |
| -## Intro |
12 |
| - |
13 |
| -*oembed-extractor* is a part of tool sets for content builder: |
14 |
| - |
15 |
| -- [feed-extractor](https://github.com/extractus/feed-extractor): extract & normalize RSS/ATOM/JSON feed |
16 |
| -- [article-extractor](https://github.com/extractus/article-extractor): extract main article from given URL |
17 |
| -- [oembed-extractor](https://github.com/extractus/oembed-extractor): extract oEmbed data from supported providers |
18 |
| - |
19 |
| -You can use one or combination of these tools to build news sites, create automated content systems for marketing campaign or gather dataset for NLP projects... |
20 |
| - |
21 |
| -### Attention |
22 |
| - |
23 |
| -`oembed-parser` has been renamed to `@extractus/oembed-extractor` since v3.1.5 |
24 |
| - |
25 | 10 |
|
26 | 11 | ## Demo
|
27 | 12 |
|
@@ -73,7 +58,7 @@ console.log(result)
|
73 | 58 | ### Browser
|
74 | 59 |
|
75 | 60 | ```ts
|
76 |
| -import { extract } from 'https://unpkg.com/@extractus/oembed-extractor@latest/dist/oembed-extractor.esm.js' |
| 61 | +import { extract } from "https://esm.sh/@extractus/oembed-extractor@latest" |
77 | 62 | ```
|
78 | 63 |
|
79 | 64 | Please check [the examples](examples) for reference.
|
@@ -115,6 +100,13 @@ Please see the provider's oEmbed API docs carefully for exact information.
|
115 | 100 |
|
116 | 101 | ##### `fetchOptions` *optional*
|
117 | 102 |
|
| 103 | +`fetchOptions` is an object that can have the following properties: |
| 104 | + |
| 105 | +- `headers`: to set request headers |
| 106 | +- `proxy`: another endpoint to forward the request to |
| 107 | +- `agent`: a HTTP proxy agent |
| 108 | +- `signal`: AbortController signal or AbortSignal timeout to terminate the request |
| 109 | + |
118 | 110 | You can use this param to set request headers to fetch.
|
119 | 111 |
|
120 | 112 | For example:
|
@@ -173,6 +165,36 @@ console.log(oembed)
|
173 | 165 |
|
174 | 166 | For more info about [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent), check [its repo](https://github.com/TooTallNate/proxy-agents).
|
175 | 167 |
|
| 168 | +By default, there is no request timeout. You can use the option `signal` to cancel request at the right time. |
| 169 | + |
| 170 | +The common way is to use AbortControler: |
| 171 | + |
| 172 | +```js |
| 173 | +const controller = new AbortController() |
| 174 | + |
| 175 | +// stop after 5 seconds |
| 176 | +setTimeout(() => { |
| 177 | + controller.abort() |
| 178 | +}, 5000) |
| 179 | + |
| 180 | +const oembed = await extract(url, null, { |
| 181 | + signal: controller.signal, |
| 182 | +}) |
| 183 | +``` |
| 184 | + |
| 185 | +A newer solution is AbortSignal's `timeout()` static method: |
| 186 | + |
| 187 | +```js |
| 188 | +// stop after 5 seconds |
| 189 | +const oembed = await extract(url, null, { |
| 190 | + signal: AbortSignal.timeout(5000), |
| 191 | +}) |
| 192 | +``` |
| 193 | + |
| 194 | +For more info: |
| 195 | + |
| 196 | +- [AbortController constructor](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) |
| 197 | +- [AbortSignal: timeout() static method](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static) |
176 | 198 |
|
177 | 199 |
|
178 | 200 | ### `.setProviderList()`
|
|
0 commit comments