metascraper-video 5.49.25 → 5.50.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.
- package/package.json +3 -3
- package/src/index.js +3 -28
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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.
|
|
5
|
+
"version": "5.50.1",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"video"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@metascraper/helpers": "5.
|
|
26
|
+
"@metascraper/helpers": "5.50.1",
|
|
27
27
|
"lodash": "~4.17.23",
|
|
28
28
|
"p-reflect": "~2.1.0"
|
|
29
29
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"!test/helpers.js"
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "688ff08cd5618a0fd9afa55e31552e95136814f2"
|
|
51
51
|
}
|
package/src/index.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
$jsonld,
|
|
5
|
+
createGetIframeCached,
|
|
6
|
+
defaultGetIframe,
|
|
5
7
|
findRule,
|
|
6
8
|
has,
|
|
7
|
-
loadIframe,
|
|
8
9
|
normalizeUrl,
|
|
9
10
|
toRule,
|
|
10
11
|
url: urlFn,
|
|
@@ -67,32 +68,6 @@ const videoRules = [
|
|
|
67
68
|
|
|
68
69
|
const imageRules = [toUrl($ => $('video').attr('poster'))]
|
|
69
70
|
|
|
70
|
-
const _getIframe = (url, $, { src }) =>
|
|
71
|
-
loadIframe(url, $.load(`<iframe src="${src}"></iframe>`))
|
|
72
|
-
|
|
73
|
-
const createGetIframeCached = getIframe => {
|
|
74
|
-
const cacheByHtmlDom = new WeakMap()
|
|
75
|
-
|
|
76
|
-
return async (url, $, src) => {
|
|
77
|
-
let cacheBySrc = cacheByHtmlDom.get($)
|
|
78
|
-
if (!cacheBySrc) {
|
|
79
|
-
cacheBySrc = new Map()
|
|
80
|
-
cacheByHtmlDom.set($, cacheBySrc)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const cachedHtmlDom = cacheBySrc.get(src)
|
|
84
|
-
if (cachedHtmlDom) return cachedHtmlDom
|
|
85
|
-
|
|
86
|
-
const pendingHtmlDom = getIframe(url, $, { src }).catch(error => {
|
|
87
|
-
cacheBySrc.delete(src)
|
|
88
|
-
throw error
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
cacheBySrc.set(src, pendingHtmlDom)
|
|
92
|
-
return pendingHtmlDom
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
71
|
const withIframe = (rules, getIframe) =>
|
|
97
72
|
rules.concat(
|
|
98
73
|
async ({ htmlDom: $, url }) => {
|
|
@@ -125,7 +100,7 @@ const withIframe = (rules, getIframe) =>
|
|
|
125
100
|
}
|
|
126
101
|
)
|
|
127
102
|
|
|
128
|
-
module.exports = ({ getIframe =
|
|
103
|
+
module.exports = ({ getIframe = defaultGetIframe } = {}) => {
|
|
129
104
|
const getIframeCached = createGetIframeCached(getIframe)
|
|
130
105
|
const rules = {
|
|
131
106
|
image: withIframe(imageRules, getIframeCached),
|