metascraper-video 5.28.1 → 5.29.0
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/index.js +8 -10
- package/package.json +4 -5
package/index.js
CHANGED
|
@@ -4,12 +4,12 @@ const {
|
|
|
4
4
|
$jsonld,
|
|
5
5
|
extension,
|
|
6
6
|
findRule,
|
|
7
|
+
normalizeUrl,
|
|
7
8
|
toRule,
|
|
8
9
|
url: urlFn,
|
|
9
10
|
video
|
|
10
11
|
} = require('@metascraper/helpers')
|
|
11
12
|
|
|
12
|
-
const reachableUrl = require('reachable-url')
|
|
13
13
|
const memoize = require('@keyvhq/memoize')
|
|
14
14
|
const pReflect = require('p-reflect')
|
|
15
15
|
const { chain } = require('lodash')
|
|
@@ -43,17 +43,15 @@ const videoRules = [
|
|
|
43
43
|
|
|
44
44
|
const createGetPlayer = ({ gotOpts, keyvOpts }) => {
|
|
45
45
|
const getPlayer = async playerUrl => {
|
|
46
|
-
const response = await
|
|
47
|
-
if (!
|
|
46
|
+
const { value: response } = await pReflect(got(playerUrl, gotOpts))
|
|
47
|
+
if (!response) return
|
|
48
48
|
const contentType = response.headers['content-type']
|
|
49
49
|
if (!contentType || !contentType.startsWith('text')) return
|
|
50
|
-
|
|
51
|
-
got(playerUrl, { resolveBodyOnly: true, ...gotOpts })
|
|
52
|
-
)
|
|
53
|
-
return html
|
|
50
|
+
return response.body
|
|
54
51
|
}
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
return memoize(getPlayer, keyvOpts, {
|
|
53
|
+
value: value => (value === undefined ? null : value)
|
|
54
|
+
})
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
module.exports = ({ gotOpts, keyvOpts } = {}) => {
|
|
@@ -69,7 +67,7 @@ module.exports = ({ gotOpts, keyvOpts } = {}) => {
|
|
|
69
67
|
$('meta[property="twitter:player"]').attr('content')
|
|
70
68
|
|
|
71
69
|
if (!playerUrl) return
|
|
72
|
-
const html = await getPlayer(playerUrl)
|
|
70
|
+
const html = await getPlayer(normalizeUrl(url, playerUrl))
|
|
73
71
|
if (!html) return
|
|
74
72
|
const htmlDom = cheerio.load(html)
|
|
75
73
|
return findRule(videoRules, { htmlDom, url })
|
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://nicedoc.io/microlinkhq/metascraper/packages/metascraper-video",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.29.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -23,12 +23,11 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@keyvhq/memoize": "~1.6.6",
|
|
26
|
-
"@metascraper/helpers": "^5.
|
|
26
|
+
"@metascraper/helpers": "^5.29.0",
|
|
27
27
|
"cheerio": "~1.0.0-rc.10",
|
|
28
28
|
"got": "~11.8.3",
|
|
29
29
|
"lodash": "~4.17.21",
|
|
30
|
-
"p-reflect": "~2.1.0"
|
|
31
|
-
"reachable-url": "~1.6.7"
|
|
30
|
+
"p-reflect": "~2.1.0"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"mocha": "latest",
|
|
@@ -45,5 +44,5 @@
|
|
|
45
44
|
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
|
|
46
45
|
},
|
|
47
46
|
"license": "MIT",
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "86572d38b9d5de0af1608d1516756cc3ed5a43af"
|
|
49
48
|
}
|