metascraper-audio 5.29.5 → 5.29.10

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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/index.js +28 -12
  3. package/package.json +7 -9
package/README.md CHANGED
@@ -22,6 +22,10 @@ $ npm install metascraper-audio --save
22
22
 
23
23
  ##### getIframe
24
24
 
25
+ Type: `function`
26
+
27
+ It will be called to get the HTML markup behind an iframe present into the HTML.
28
+
25
29
  ##### gotOpts
26
30
 
27
31
  Type: `object`
package/index.js CHANGED
@@ -5,6 +5,7 @@ const {
5
5
  $jsonld,
6
6
  audio,
7
7
  findRule,
8
+ has,
8
9
  isMime,
9
10
  loadIframe,
10
11
  normalizeUrl,
@@ -13,7 +14,6 @@ const {
13
14
 
14
15
  const memoize = require('@keyvhq/memoize')
15
16
  const pReflect = require('p-reflect')
16
- const cheerio = require('cheerio')
17
17
  const got = require('got')
18
18
 
19
19
  const toAudio = toRule(audio)
@@ -41,10 +41,8 @@ const audioRules = [
41
41
  ({ htmlDom: $ }) => $filter($, $('a[href]'), el => audio(el.attr('href')))
42
42
  ]
43
43
 
44
- const _getIframe = async (url, { src }) => {
45
- const iframe = await loadIframe(url, `<iframe src="${src}"></iframe>`)
46
- return iframe.document.documentElement.outerHTML
47
- }
44
+ const _getIframe = (url, $, { src }) =>
45
+ loadIframe(url, $.load(`<iframe src="${src}"></iframe>`))
48
46
 
49
47
  const createGetPlayer = ({ gotOpts, keyvOpts }) => {
50
48
  const getPlayer = async playerUrl => {
@@ -69,23 +67,41 @@ module.exports = ({ getIframe = _getIframe, gotOpts, keyvOpts } = {}) => {
69
67
  const iframe = $('iframe')
70
68
  if (iframe.length === 0) return
71
69
 
72
- const src = $filter($, iframe, el => normalizeUrl(url, el.attr('src')))
73
- if (!src) return
70
+ const srcs = []
74
71
 
75
- const html = await getIframe(url, { src })
76
- const htmlDom = cheerio.load(html)
72
+ iframe.each(function () {
73
+ const src = $(this).attr('src')
74
+ const normalizedUrl = normalizeUrl(url, src)
75
+ if (normalizedUrl && srcs.indexOf(normalizedUrl) === -1) {
76
+ srcs.push(normalizedUrl)
77
+ }
78
+ })
77
79
 
78
- return findRule(audioRules, { htmlDom, url })
80
+ if (srcs.length === 0) return
81
+
82
+ const { value } = await pReflect(
83
+ Promise.any(
84
+ srcs.map(async src => {
85
+ const htmlDom = await getIframe(url, $, { src })
86
+ const result = await findRule(audioRules, { htmlDom, url })
87
+ if (!has(result)) throw TypeError('no result')
88
+ return result
89
+ })
90
+ )
91
+ )
92
+
93
+ return value
79
94
  },
80
95
  async ({ htmlDom: $, url }) => {
81
96
  const playerUrl =
82
97
  $('meta[name="twitter:player"]').attr('content') ||
83
98
  $('meta[property="twitter:player"]').attr('content')
84
-
85
99
  if (!playerUrl) return
100
+
86
101
  const html = await getPlayer(normalizeUrl(url, playerUrl))
87
102
  if (!html) return
88
- const htmlDom = cheerio.load(html)
103
+
104
+ const htmlDom = $.load(html)
89
105
  return findRule(audioRules, { htmlDom, url })
90
106
  }
91
107
  ]
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.29.5",
5
+ "version": "5.29.10",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -22,15 +22,13 @@
22
22
  "metascraper"
23
23
  ],
24
24
  "dependencies": {
25
- "@keyvhq/memoize": "~1.6.9",
26
- "@metascraper/helpers": "^5.29.5",
27
- "cheerio": "~1.0.0-rc.10",
28
- "got": "~11.8.3",
25
+ "@keyvhq/memoize": "~1.6.14",
26
+ "@metascraper/helpers": "^5.29.10",
27
+ "got": "~11.8.5",
29
28
  "p-reflect": "~2.1.0"
30
29
  },
31
30
  "devDependencies": {
32
- "mocha": "latest",
33
- "snap-shot": "latest"
31
+ "ava": "latest"
34
32
  },
35
33
  "engines": {
36
34
  "node": ">= 12"
@@ -39,8 +37,8 @@
39
37
  "index.js"
40
38
  ],
41
39
  "scripts": {
42
- "test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
40
+ "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
43
41
  },
44
42
  "license": "MIT",
45
- "gitHead": "71c16e166a7775641957126288741d9051925e33"
43
+ "gitHead": "1caeb9ed3cb6255b7f730a66f558b06715be94df"
46
44
  }