metascraper-video 5.27.3 → 5.28.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/README.md +18 -0
- package/index.js +33 -24
- package/package.json +3 -2
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
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
} = require('@metascraper/helpers')
|
|
11
11
|
|
|
12
12
|
const reachableUrl = require('reachable-url')
|
|
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,39 @@ 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 response = await reachableUrl(playerUrl, gotOpts)
|
|
47
|
+
if (!reachableUrl.isReachable(response)) return
|
|
48
|
+
const contentType = response.headers['content-type']
|
|
49
|
+
if (!contentType || !contentType.startsWith('text')) return
|
|
50
|
+
const { value: html } = await pReflect(
|
|
51
|
+
got(playerUrl, { resolveBodyOnly: true, ...gotOpts })
|
|
52
|
+
)
|
|
53
|
+
return html
|
|
54
|
+
}
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
return memoize(getPlayer, keyvOpts)
|
|
57
|
+
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
module.exports = ({ gotOpts, keyvOpts } = {}) => {
|
|
60
|
+
const getPlayer = createGetPlayer({ gotOpts, keyvOpts })
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
return {
|
|
63
|
+
image: [toUrl($ => $('video').attr('poster'))],
|
|
64
|
+
video: [
|
|
65
|
+
...videoRules,
|
|
66
|
+
async ({ htmlDom: $, url }) => {
|
|
67
|
+
const playerUrl =
|
|
68
|
+
$('meta[name="twitter:player"]').attr('content') ||
|
|
69
|
+
$('meta[property="twitter:player"]').attr('content')
|
|
59
70
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
]
|
|
70
|
-
})
|
|
71
|
+
if (!playerUrl) return
|
|
72
|
+
const html = await getPlayer(playerUrl)
|
|
73
|
+
if (!html) return
|
|
74
|
+
const htmlDom = cheerio.load(html)
|
|
75
|
+
return findRule(videoRules, { htmlDom, url })
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
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.1",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"video"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@keyvhq/memoize": "~1.6.6",
|
|
25
26
|
"@metascraper/helpers": "^5.26.0",
|
|
26
27
|
"cheerio": "~1.0.0-rc.10",
|
|
27
28
|
"got": "~11.8.3",
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
|
|
45
46
|
},
|
|
46
47
|
"license": "MIT",
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "8b3ec1e62e637ffe3a7ee3e723f51942e42d4276"
|
|
48
49
|
}
|