metascraper-video 5.42.5 → 5.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +5 -4
  2. package/src/index.js +24 -21
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "metascraper-video",
3
3
  "description": "Get video property from HTML markup",
4
4
  "homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-video",
5
- "version": "5.42.5",
6
- "main": "src/index.js",
5
+ "version": "5.43.1",
7
6
  "types": "src/index.d.ts",
7
+ "main": "src/index.js",
8
8
  "author": {
9
9
  "email": "hello@microlink.io",
10
10
  "name": "microlink.io",
@@ -23,10 +23,11 @@
23
23
  "video"
24
24
  ],
25
25
  "dependencies": {
26
- "@metascraper/helpers": "^5.42.5",
26
+ "@metascraper/helpers": "^5.43.1",
27
27
  "lodash": "~4.17.21"
28
28
  },
29
29
  "devDependencies": {
30
+ "async-listen": "latest",
30
31
  "ava": "5"
31
32
  },
32
33
  "engines": {
@@ -39,5 +40,5 @@
39
40
  "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
40
41
  },
41
42
  "license": "MIT",
42
- "gitHead": "044f875812fff95bba404baad18c087eb154b7b0"
43
+ "gitHead": "d923747a54c3b7244e4710227fd32a39608c3ddf"
43
44
  }
package/src/index.js CHANGED
@@ -3,13 +3,17 @@
3
3
  const {
4
4
  $jsonld,
5
5
  $twitter,
6
- loadIframe,
7
6
  findRule,
7
+ has,
8
+ loadIframe,
9
+ normalizeUrl,
8
10
  toRule,
9
11
  url: urlFn,
10
12
  video
11
13
  } = require('@metascraper/helpers')
12
14
 
15
+ const pReflect = require('p-reflect')
16
+
13
17
  const { chain, find, isEqual } = require('lodash')
14
18
 
15
19
  const toUrl = toRule(urlFn)
@@ -74,26 +78,25 @@ const _getIframe = (url, $, { src }) =>
74
78
 
75
79
  const withIframe = (rules, getIframe) =>
76
80
  rules.concat(
77
- // async ({ htmlDom: $, url }) => {
78
- // // TODO: write a test embedding a youtube video as iframe
79
- // const srcs = [
80
- // ...new $('iframe[src^="http"], iframe[src^="/"]')
81
- // .map((_, element) => $(element).attr('src'))
82
- // .get()
83
- // .map(src => normalizeUrl(url, src))
84
- // ]
85
- // if (srcs.length === 0) return
86
- // return pReflect(
87
- // Promise.any(
88
- // srcs.map(async src => {
89
- // const htmlDom = await getIframe(url, $, { src })
90
- // const result = await findRule(audioRules, { htmlDom, url })
91
- // if (!has(result)) throw TypeError('no result')
92
- // return result
93
- // })
94
- // )
95
- // ).then(({ value }) => value)
96
- // },
81
+ async ({ htmlDom: $, url }) => {
82
+ const srcs = [
83
+ ...new $('iframe[src^="http"], iframe[src^="/"]')
84
+ .map((_, element) => $(element).attr('src'))
85
+ .get()
86
+ .map(src => normalizeUrl(url, src))
87
+ ]
88
+ if (srcs.length === 0) return
89
+ return pReflect(
90
+ Promise.any(
91
+ srcs.map(async src => {
92
+ const htmlDom = await getIframe(url, $, { src })
93
+ const result = await findRule(rules, { htmlDom, url })
94
+ if (!has(result)) throw TypeError('no result')
95
+ return result
96
+ })
97
+ )
98
+ ).then(({ value }) => value)
99
+ },
97
100
  async ({ htmlDom: $, url }) => {
98
101
  const src = $twitter($, 'twitter:player')
99
102
  return src