metascraper-audio 5.26.0 → 5.28.2
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 +20 -0
- package/index.js +45 -38
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -11,6 +11,26 @@
|
|
|
11
11
|
$ npm install metascraper-audio --save
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
### metascraper-audio([options])
|
|
17
|
+
|
|
18
|
+
#### options
|
|
19
|
+
|
|
20
|
+
##### getIframe
|
|
21
|
+
|
|
22
|
+
##### gotOpts
|
|
23
|
+
|
|
24
|
+
Type: `object`
|
|
25
|
+
|
|
26
|
+
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
|
|
27
|
+
|
|
28
|
+
##### keyvOpts
|
|
29
|
+
|
|
30
|
+
Type: `object`
|
|
31
|
+
|
|
32
|
+
Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
|
|
33
|
+
|
|
14
34
|
## License
|
|
15
35
|
|
|
16
36
|
**metascraper-audio** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
toRule
|
|
12
12
|
} = require('@metascraper/helpers')
|
|
13
13
|
|
|
14
|
+
const memoize = require('@keyvhq/memoize')
|
|
14
15
|
const pReflect = require('p-reflect')
|
|
15
16
|
const cheerio = require('cheerio')
|
|
16
17
|
const got = require('got')
|
|
@@ -45,42 +46,48 @@ const _getIframe = async (url, { src }) => {
|
|
|
45
46
|
return iframe.document.documentElement.outerHTML
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return findRule(audioRules, { htmlDom, url })
|
|
62
|
-
},
|
|
63
|
-
async ({ htmlDom: $, url }) => {
|
|
64
|
-
const playerUrl =
|
|
65
|
-
$('meta[name="twitter:player"]').attr('content') ||
|
|
66
|
-
$('meta[property="twitter:player"]').attr('content')
|
|
67
|
-
|
|
68
|
-
if (!playerUrl) return
|
|
69
|
-
|
|
70
|
-
const { isRejected, value } = await pReflect(got.head(playerUrl, gotOpts))
|
|
71
|
-
if (isRejected) return
|
|
72
|
-
|
|
73
|
-
const contentType = value.headers['content-type']
|
|
74
|
-
if (!contentType || !contentType.startsWith('text')) return
|
|
75
|
-
|
|
76
|
-
const { value: html } = await pReflect(
|
|
77
|
-
got(playerUrl, { resolveBodyOnly: true, ...gotOpts })
|
|
78
|
-
)
|
|
79
|
-
if (!html) return
|
|
80
|
-
|
|
81
|
-
const htmlDom = cheerio.load(html)
|
|
49
|
+
const createGetPlayer = ({ gotOpts, keyvOpts }) => {
|
|
50
|
+
const getPlayer = async playerUrl => {
|
|
51
|
+
const { value: response } = await pReflect(got(playerUrl, gotOpts))
|
|
52
|
+
if (!response) return
|
|
53
|
+
const contentType = response.headers['content-type']
|
|
54
|
+
if (!contentType || !contentType.startsWith('text')) return
|
|
55
|
+
return response.body
|
|
56
|
+
}
|
|
57
|
+
return memoize(getPlayer, keyvOpts, {
|
|
58
|
+
value: value => (value === undefined ? null : value)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
82
61
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
module.exports = ({ getIframe = _getIframe, gotOpts, keyvOpts } = {}) => {
|
|
63
|
+
const getPlayer = createGetPlayer({ gotOpts, keyvOpts })
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
audio: [
|
|
67
|
+
...audioRules,
|
|
68
|
+
async ({ htmlDom: $, url }) => {
|
|
69
|
+
const iframe = $('iframe')
|
|
70
|
+
if (iframe.length === 0) return
|
|
71
|
+
|
|
72
|
+
const src = $filter($, iframe, el => normalizeUrl(url, el.attr('src')))
|
|
73
|
+
if (!src) return
|
|
74
|
+
|
|
75
|
+
const html = await getIframe(url, { src })
|
|
76
|
+
const htmlDom = cheerio.load(html)
|
|
77
|
+
|
|
78
|
+
return findRule(audioRules, { htmlDom, url })
|
|
79
|
+
},
|
|
80
|
+
async ({ htmlDom: $, url }) => {
|
|
81
|
+
const playerUrl =
|
|
82
|
+
$('meta[name="twitter:player"]').attr('content') ||
|
|
83
|
+
$('meta[property="twitter:player"]').attr('content')
|
|
84
|
+
|
|
85
|
+
if (!playerUrl) return
|
|
86
|
+
const html = await getPlayer(normalizeUrl(url, playerUrl))
|
|
87
|
+
if (!html) return
|
|
88
|
+
const htmlDom = cheerio.load(html)
|
|
89
|
+
return findRule(audioRules, { htmlDom, url })
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-audio",
|
|
3
3
|
"description": "Get audio property from HTML markup",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-audio",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.28.2",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"metascraper"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
25
|
+
"@keyvhq/memoize": "~1.6.6",
|
|
26
|
+
"@metascraper/helpers": "^5.28.2",
|
|
26
27
|
"cheerio": "~1.0.0-rc.10",
|
|
27
28
|
"got": "~11.8.3",
|
|
28
29
|
"p-reflect": "~2.1.0"
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
|
|
42
43
|
},
|
|
43
44
|
"license": "MIT",
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "373d7f2b46ca3d1f163c412c1735daaf9434568d"
|
|
45
46
|
}
|