All Projects β†’ ndaidong β†’ oembed-parser

ndaidong / oembed-parser

Licence: MIT license
Extract oEmbed data from given webpage

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to oembed-parser

Oak
A middleware framework for handling HTTP with Deno 🐿️ πŸ¦•
Stars: ✭ 3,799 (+5744.62%)
Mutual labels:  deno
dmm
Lightweight Deno Module Manager
Stars: ✭ 59 (-9.23%)
Mutual labels:  deno
denoliver
A simple, dependency free static file server for Deno with possibly the worst name ever.
Stars: ✭ 94 (+44.62%)
Mutual labels:  deno
Fe News
FE 기술 μ†Œμ‹ νλ ˆμ΄μ…˜ λ‰΄μŠ€λ ˆν„°
Stars: ✭ 2,249 (+3360%)
Mutual labels:  deno
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (-4.62%)
Mutual labels:  deno
astrodon
Make Desktop apps with Deno πŸ¦•
Stars: ✭ 826 (+1170.77%)
Mutual labels:  deno
chat-with-deno-and-preact
Chat app with Deno + Preact
Stars: ✭ 27 (-58.46%)
Mutual labels:  deno
land
Run Deno X module without installation.
Stars: ✭ 39 (-40%)
Mutual labels:  deno
superdeno
Super-agent driven library for testing Deno HTTP servers.
Stars: ✭ 119 (+83.08%)
Mutual labels:  deno
discord-emoji
[Library/Deno] A near exact emoji tables of Discord for string-based insertion of emotes without having to escape Unicode.
Stars: ✭ 37 (-43.08%)
Mutual labels:  deno
Aleph.js
The Full-stack Framework in Deno.
Stars: ✭ 3,448 (+5204.62%)
Mutual labels:  deno
Deno
A modern runtime for JavaScript and TypeScript.
Stars: ✭ 79,289 (+121883.08%)
Mutual labels:  deno
media types
Deprecated. Use std/media_types instead.
Stars: ✭ 21 (-67.69%)
Mutual labels:  deno
I18next
i18next: learn once - translate everywhere
Stars: ✭ 5,971 (+9086.15%)
Mutual labels:  deno
awesome-oak
A list of community projects for oak
Stars: ✭ 63 (-3.08%)
Mutual labels:  deno
Awesome Deno
Curated list of awesome things related to Deno
Stars: ✭ 3,330 (+5023.08%)
Mutual labels:  deno
core
Server side rendering with The Elm Architecture in Deno
Stars: ✭ 16 (-75.38%)
Mutual labels:  deno
Thread
type safe multi-threading made easier
Stars: ✭ 34 (-47.69%)
Mutual labels:  deno
deno sticker
πŸ¦• The data I used for submitting for printing deno_sticker.
Stars: ✭ 50 (-23.08%)
Mutual labels:  deno
i18next-fs-backend
i18next-fs-backend is a backend layer for i18next using in Node.js and for Deno to load translations from the filesystem.
Stars: ✭ 67 (+3.08%)
Mutual labels:  deno

oembed-extractor

Extract oEmbed content from given URL.

NPM CI test Coverage Status CodeQL CodeFactor

Intro

oembed-extractor is a part of tool sets for content builder:

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...

Attention

oembed-parser has been renamed to @extractus/oembed-extractor since v3.1.5

Demo

Install & Usage

Node.js

npm i @extractus/oembed-extractor

# pnpm
pnpm i @extractus/oembed-extractor

# yarn
yarn add @extractus/oembed-extractor
// es6 module
import { extract } from '@extractus/oembed-extractor'

// CommonJS
const { extract } = require('@extractus/oembed-extractor')

// or specify exactly path to CommonJS variant
const { extract } = require('@extractus/oembed-extractor/dist/cjs/oembed-extractor.js')

const result = await extract('https://www.youtube.com/watch?v=x2bqscVkGxk')
console.log(result)

Deno

// deno < 1.28
import { extract } from 'https://esm.sh/@extractus/oembed-extractor'

// deno > 1.28
import { extract } from 'npm:@extractus/oembed-extractor'

const result = await extract('https://www.youtube.com/watch?v=x2bqscVkGxk')
console.log(result)

Browser

import { extract } from 'https://unpkg.com/@extractus/oembed-extractor@latest/dist/oembed-extractor.esm.js'

Please check the examples for reference.

APIs

.extract()

Load and extract oembed data.

Syntax

extract(String url)
extract(String url, Object params)
extract(String url, Object params, Object fetchOptions)

Parameters

url required

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

params optional

Optional argument params can be useful when you want to specify some additional customizations.

Here are several popular params:

  • maxwidth: max width of embed size
  • maxheight: max height of embed size
  • theme: e.g, dark or light
  • lang: e.g, 'en', 'fr', 'cn', 'vi', etc

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

fetchOptions optional

You can use this param to set request headers to fetch.

For example:

import { extract } from '@extractus/oembed-extractor'

const url = 'https://codepen.io/ndaidong/pen/LYmLKBw'
extract(url, null, {
  headers: {
    'user-agent': 'Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1'
  }
})

You can also specify a proxy endpoint to load remote content, instead of fetching directly.

For example:

import { extract } from '@extractus/oembed-extractor'

const url = 'https://codepen.io/ndaidong/pen/LYmLKBw'
extract(url, null, {
  headers: {
    'user-agent': 'Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1'
  },
  proxy: {
    target: 'https://your-secret-proxy.io/loadJson?url=',
    headers: {
      'Proxy-Authorization': 'Bearer YWxhZGRpbjpvcGVuc2VzYW1l...'
    }
  }
})

With the above setting, request will be forwarded to https://your-secret-proxy.io/loadJson?url={OEMBED_ENDPOINT}.

.setProviderList()

Apply a list of providers to use, overriding the default.

Syntax

setProviderList(Array providers)

Parameters

providers required

List of providers to apply.

For example:

import { setProviderList } from '@extractus/oembed-extractor'

const providers = [
  {
    provider_name: 'Alpha',
    provider_url: 'https://alpha.com',
    endpoints: [
      // endpoint definition here
    ]
  },
  {
    provider_name: 'Beta',
    provider_url: 'https://beta.com',
    endpoints: [
      // endpoint definition here
    ]
  }
]

setProviderList(providers)

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

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

Facebook and Instagram

In order to work with the links from Facebook and Instagram, you need a reviewed Facebook's app with oEmbed Read permission.

When seeing a link from Facebook or Instagram, oembed-parser will look for environment variables FACEBOOK_APP_ID and FACEBOOK_CLIENT_TOKEN to retrieve oembed data using your app credentials.

For example:

export FACEBOOK_APP_ID=your_app_id
export FACEBOOK_CLIENT_TOKEN=your_client_token

npm run eval https://www.instagram.com/tv/CVlR5GFqF68/

Test

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

oembed-extractor unit test

Quick evaluation

git clone https://github.com/extractus/oembed-extractor.git
cd oembed-extractor
npm i
npm run eval {URL_TO_PARSE_OEMBED}

License

The MIT License (MIT)


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].