Skip to content

Commit

Permalink
v4.0.5
Browse files Browse the repository at this point in the history
- Add auto discovery support (#181)
- Sync to the last provider list
- Update examples dependencies
  • Loading branch information
ndaidong committed May 7, 2024
1 parent cd08c33 commit 8ad2a6f
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 44 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ yarn add @extractus/oembed-extractor
```

```ts
// es6 module
import { extract } from '@extractus/oembed-extractor'

const result = await extract('https://www.youtube.com/watch?v=x2bqscVkGxk')
Expand All @@ -39,10 +38,6 @@ console.log(result)
### Deno

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

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

Expand Down
5 changes: 0 additions & 5 deletions deno.json

This file was deleted.

4 changes: 2 additions & 2 deletions examples/browser-oembed-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node server"
},
"dependencies": {
"express": "^4.18.2",
"got": "^13.0.0"
"express": "latest",
"got": "latest"
}
}
4 changes: 2 additions & 2 deletions examples/bun-oembed-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"start": "bun run index.ts"
},
"devDependencies": {
"bun-types": "^0.6.13"
"bun-types": "latest"
},
"dependencies": {
"hono": "^3.2.7",
"hono": "latest",
"@extractus/oembed-extractor": "latest"
}
}
2 changes: 1 addition & 1 deletion examples/deno-oembed-parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { serve } from 'https://deno.land/std/http/server.ts'

import { Hono } from 'https://deno.land/x/hono@v3.2.7/mod.ts'
import { Hono } from 'https://deno.land/x/hono/mod.ts'

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

Expand Down
2 changes: 1 addition & 1 deletion examples/node-oembed-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2",
"express": "latest",
"@extractus/oembed-extractor": "latest"
}
}
4 changes: 2 additions & 2 deletions examples/tsnode-oembed-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"start": "node dist/index.js"
},
"devDependencies": {
"typescript": "^5.1.6"
"typescript": "latest"
},
"dependencies": {
"express": "^4.18.2",
"express": "latest",
"@extractus/oembed-extractor": "latest"
}
}
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.0.4",
"version": "4.0.5",
"name": "@extractus/oembed-extractor",
"description": "Get oEmbed data from given URL.",
"homepage": "https://github.com/extractus/oembed-extractor",
Expand All @@ -11,10 +11,12 @@
"main": "./src/main.js",
"type": "module",
"imports": {
"cross-fetch": "./src/deno/cross-fetch.js"
"cross-fetch": "./src/deno/cross-fetch.js",
"linkedom": "https://deno.land/x/[email protected]/deno-dom-wasm.ts"
},
"browser": {
"cross-fetch": "./src/deno/cross-fetch.js"
"cross-fetch": "./src/deno/cross-fetch.js",
"linkedom": "./src/browser/linkedom.js"
},
"types": "./index.d.ts",
"engines": {
Expand All @@ -30,11 +32,12 @@
"reset": "node reset"
},
"dependencies": {
"cross-fetch": "^4.0.0"
"cross-fetch": "^4.0.0",
"linkedom": "^0.16.11"
},
"devDependencies": {
"eslint": "^9.1.1",
"globals": "^15.0.0",
"eslint": "^9.2.0",
"globals": "^15.1.0",
"https-proxy-agent": "^7.0.4",
"jest": "^29.7.0",
"nock": "^13.5.4"
Expand Down
9 changes: 4 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// main.js

import { isValid as isValidURL } from './utils/linker.js'
import extractWithDiscovery from './utils/autoDiscovery.js'
import fetchEmbed from './utils/fetchEmbed.js'

import { getEndpoint } from './utils/provider.js'
Expand All @@ -10,12 +11,10 @@ export const extract = async (url, params = {}, options = {}) => {
throw new Error('Invalid input URL')
}
const endpoint = getEndpoint(url)
if (!endpoint) {
throw new Error(`No provider found with given url "${url}"`)
}

const data = await fetchEmbed(url, params, endpoint, options)
return data
return endpoint
? fetchEmbed(url, params, endpoint, options)
: extractWithDiscovery(url, params, options)
}

export {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/fetchEmbed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// utils -> fetchEmbed

import retrieve from './retrieve.js'
import { getJson } from './retrieve.js'
import { getDomain } from './linker.js'

const isFacebookGraphDependent = (url) => {
Expand Down Expand Up @@ -34,6 +34,7 @@ export default async (url, params = {}, endpoint = '', options = {}) => { // esl

const queryParams = new URLSearchParams(query).toString()
const link = endpoint + '?' + queryParams
const body = retrieve(link, options)
const body = await getJson(link, options)
body.method = 'provider-api'
return body
}
20 changes: 19 additions & 1 deletion src/utils/providers.latest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// provider data, synchronized at 2024-04-26T08:46:02.055Z
// provider data, synchronized at 2024-05-07T10:41:10.221Z

/* eslint-disable */

Expand Down Expand Up @@ -198,6 +198,12 @@ export const providers = [
],
"e": "www.behance.net/services/oembed"
},
{
"s": [
"cloud\\.biqapp\\.com/*"
],
"e": "biqapp.com/api/v1/video/oembed"
},
{
"s": [
"blackfire\\.io/profiles/*/graph",
Expand Down Expand Up @@ -277,6 +283,12 @@ export const providers = [
],
"e": "img.catbo.at/oembed.json"
},
{
"s": [
"embeds\\.celero\\.io/*"
],
"e": "api.celero.io/api/oembed"
},
{
"s": [
"view\\.ceros\\.com/*"
Expand Down Expand Up @@ -816,6 +828,12 @@ export const providers = [
],
"e": "www.hulu.com/api/oembed.json"
},
{
"s": [
"oembed\\.ideamapper\\.com/*"
],
"e": "oembed.ideamapper.com"
},
{
"s": [
"*\\.idomoo\\.com/*"
Expand Down
42 changes: 42 additions & 0 deletions src/utils/providers.orginal.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,19 @@
}
]
},
{
"provider_name": "biqnetwork",
"provider_url": "https://biqapp.com/",
"endpoints": [
{
"schemes": [
"https://cloud.biqapp.com/*"
],
"url": "https://biqapp.com/api/v1/video/oembed",
"discovery": true
}
]
},
{
"provider_name": "Blackfire.io",
"provider_url": "https://blackfire.io",
Expand Down Expand Up @@ -591,6 +604,22 @@
}
]
},
{
"provider_name": "Celero",
"provider_url": "https://www.celero.io",
"endpoints": [
{
"schemes": [
"https://embeds.celero.io/*"
],
"url": "https://api.celero.io/api/oembed",
"discovery": true,
"formats": [
"json"
]
}
]
},
{
"provider_name": "Ceros",
"provider_url": "http://www.ceros.com/",
Expand Down Expand Up @@ -1698,6 +1727,19 @@
}
]
},
{
"provider_name": "Ideamapper",
"provider_url": "http://oembed.ideamapper.com",
"endpoints": [
{
"schemes": [
"http://oembed.ideamapper.com/*"
],
"url": "http://oembed.ideamapper.com",
"discovery": true
}
]
},
{
"provider_name": "Idomoo",
"provider_url": "https://idomoo.com/",
Expand Down
27 changes: 26 additions & 1 deletion src/utils/providers.prev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// provider data, synchronized at 2024-03-29T04:36:42.975Z
// provider data, synchronized at 2024-04-26T08:46:02.055Z

/* eslint-disable */

Expand Down Expand Up @@ -212,6 +212,12 @@ export const providers = [
],
"e": "blogcast.host/oembed"
},
{
"s": [
"bsky\\.app/profile/*/post/*"
],
"e": "embed.bsky.app/oembed"
},
{
"s": [
"www\\.bookingmood\\.com/embed/*/*"
Expand Down Expand Up @@ -1198,6 +1204,12 @@ export const providers = [
],
"e": "ndla.no/oembed"
},
{
"s": [
"*\\.neetorecord\\.com/watch/*"
],
"e": "api.neetorecord.com/api/v1/oembed"
},
{
"s": [
"*\\.nfb\\.ca/film/*"
Expand Down Expand Up @@ -1559,6 +1571,13 @@ export const providers = [
],
"e": "embed.sendtonews.com/services/oembed"
},
{
"s": [
"shopshare\\.tv/shopboard/*",
"shopshare\\.tv/shopcast/*"
],
"e": "shopshare.tv/api/shopcast/oembed"
},
{
"s": [
"www\\.shortnote\\.jp/view/notes/*"
Expand Down Expand Up @@ -1830,6 +1849,12 @@ export const providers = [
],
"e": "app-test.totango.com/oembed"
},
{
"s": [
"trackspace\\.upitup\\.com/*"
],
"e": "trackspace.upitup.com/oembed"
},
{
"s": [
"trinitymedia\\.ai/player/*",
Expand Down
23 changes: 22 additions & 1 deletion src/utils/retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ const profetch = async (url, options = {}) => {
return res
}

export default async (url, options = {}) => {
export const getHtml = async (url, options = {}) => {
const {
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
},
proxy = null,
agent = null,
signal = null,
} = options

const res = proxy ? await profetch(url, { proxy, signal }) : await fetch(url, { headers, agent, signal })

const status = res.status
if (status >= 400) {
throw new Error(`Request failed with error code ${status}`)
}

const text = await res.text()
return text
}

export const getJson = async (url, options = {}) => {
const {
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
Expand Down
Loading

0 comments on commit 8ad2a6f

Please sign in to comment.