metascraper-video 5.27.3 → 5.28.9
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/README.md +18 -0
- package/index.js +33 -26
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -11,6 +11,24 @@
|
|
|
11
11
|
$ npm install metascraper-video --save
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
### metascraper-video([options])
|
|
17
|
+
|
|
18
|
+
#### options
|
|
19
|
+
|
|
20
|
+
##### gotOpts
|
|
21
|
+
|
|
22
|
+
Type: `object`
|
|
23
|
+
|
|
24
|
+
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
|
|
25
|
+
|
|
26
|
+
##### keyvOpts
|
|
27
|
+
|
|
28
|
+
Type: `object`
|
|
29
|
+
|
|
30
|
+
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
|
|
31
|
+
|
|
14
32
|
## License
|
|
15
33
|
|
|
16
34
|
**metascraper-video** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
|
package/index.js
CHANGED
|
@@ -4,12 +4,13 @@ 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
|
|
13
|
+
const memoize = require('@keyvhq/memoize')
|
|
13
14
|
const pReflect = require('p-reflect')
|
|
14
15
|
const { chain } = require('lodash')
|
|
15
16
|
const cheerio = require('cheerio')
|
|
@@ -40,31 +41,37 @@ const videoRules = [
|
|
|
40
41
|
toVideoFromDom($ => $('video > source').get())
|
|
41
42
|
]
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const createGetPlayer = ({ gotOpts, keyvOpts }) => {
|
|
45
|
+
const getPlayer = async playerUrl => {
|
|
46
|
+
const { value: response } = await pReflect(got(playerUrl, gotOpts))
|
|
47
|
+
if (!response) return
|
|
48
|
+
const contentType = response.headers['content-type']
|
|
49
|
+
if (!contentType || !contentType.startsWith('text')) return
|
|
50
|
+
return response.body
|
|
51
|
+
}
|
|
52
|
+
return memoize(getPlayer, keyvOpts, {
|
|
53
|
+
value: value => (value === undefined ? null : value)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
module.exports = ({ gotOpts, keyvOpts } = {}) => {
|
|
58
|
+
const getPlayer = createGetPlayer({ gotOpts, keyvOpts })
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
return {
|
|
61
|
+
image: [toUrl($ => $('video').attr('poster'))],
|
|
62
|
+
video: [
|
|
63
|
+
...videoRules,
|
|
64
|
+
async ({ htmlDom: $, url }) => {
|
|
65
|
+
const playerUrl =
|
|
66
|
+
$('meta[name="twitter:player"]').attr('content') ||
|
|
67
|
+
$('meta[property="twitter:player"]').attr('content')
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return findRule(videoRules, { htmlDom, url })
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
})
|
|
69
|
+
if (!playerUrl) return
|
|
70
|
+
const html = await getPlayer(normalizeUrl(url, playerUrl))
|
|
71
|
+
if (!html) return
|
|
72
|
+
const htmlDom = cheerio.load(html)
|
|
73
|
+
return findRule(videoRules, { htmlDom, url })
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
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.28.9",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"video"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
25
|
+
"@keyvhq/memoize": "~1.6.6",
|
|
26
|
+
"@metascraper/helpers": "^5.28.9",
|
|
26
27
|
"cheerio": "~1.0.0-rc.10",
|
|
27
28
|
"got": "~11.8.3",
|
|
28
29
|
"lodash": "~4.17.21",
|
|
29
|
-
"p-reflect": "~2.1.0"
|
|
30
|
-
"reachable-url": "~1.6.7"
|
|
30
|
+
"p-reflect": "~2.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"mocha": "latest",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2062907198cd0fa209e844107a0b1207e7516880"
|
|
48
48
|
}
|