metascraper-audio 5.29.3 → 5.29.7

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 +15 -8
  2. package/index.js +28 -12
  3. package/package.json +6 -8
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
- # metascraper-audio
2
-
3
- [![npm](https://img.shields.io/npm/v/metascraper-audio.svg?style=flat-square)](https://www.npmjs.com/package/metascraper-audio)
4
- [![Dependency Status](https://david-dm.org/microlinkhq/metascraper.svg?path=packages/metascraper-audio&style=flat-square)](https://david-dm.org/microlinkhq/metascraper?path=packages/metascraper-audio)
5
-
6
- > Get audio property from HTML markup.
1
+ <div align="center">
2
+ <br>
3
+ <img style="width: 500px; margin:3rem 0 1.5rem;" src="https://metascraper.js.org/static/logo-banner.png" alt="metascraper">
4
+ <br>
5
+ <br>
6
+ <p align="center"><strong>metascraper-audio</strong>: Get audio property from HTML markup.</p>
7
+ <p align="center">See our <a href="https://metascraper.js.org" target='_blank' rel='noopener noreferrer'>website</a> for more information.</p>
8
+ <br>
9
+ </div>
7
10
 
8
11
  ## Install
9
12
 
@@ -19,6 +22,10 @@ $ npm install metascraper-audio --save
19
22
 
20
23
  ##### getIframe
21
24
 
25
+ Type: `function`
26
+
27
+ It will be called to get the HTML markup behind an iframe present into the HTML.
28
+
22
29
  ##### gotOpts
23
30
 
24
31
  Type: `object`
@@ -33,7 +40,7 @@ Any option provided here will passed to [@keyvhq/memoize#options](https://github
33
40
 
34
41
  ## License
35
42
 
36
- **metascraper-audio** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
43
+ **metascraper-audio** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
37
44
  Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/metascraper/contributors).
38
45
 
39
- > [microlink.io](https://microlink.io) · GitHub [@microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
46
+ > [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
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.3",
5
+ "version": "5.29.7",
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.3",
27
- "cheerio": "~1.0.0-rc.10",
25
+ "@keyvhq/memoize": "~1.6.13",
26
+ "@metascraper/helpers": "^5.29.7",
28
27
  "got": "~11.8.3",
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": "e3d5ef5add6fec690b1234e6aaa273e1a658c256"
43
+ "gitHead": "78434709c910cca5d8df3871c0b06131cce5df45"
46
44
  }