metascraper-video 5.53.0 → 5.54.0

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 (2) hide show
  1. package/package.json +12 -4
  2. package/src/index.js +4 -38
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "metascraper-video",
3
- "description": "Get video property from HTML markup",
3
+ "description": "Metascraper rule to extract the video from HTML using Open Graph, JSON-LD, and fallback selectors.",
4
4
  "homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-video",
5
- "version": "5.53.0",
5
+ "version": "5.54.0",
6
6
  "types": "src/index.d.ts",
7
7
  "main": "src/index.js",
8
8
  "author": {
@@ -19,11 +19,19 @@
19
19
  "url": "https://github.com/microlinkhq/metascraper/issues"
20
20
  },
21
21
  "keywords": [
22
+ "extract",
23
+ "html",
24
+ "json-ld",
25
+ "media",
26
+ "metadata",
22
27
  "metascraper",
28
+ "og:video",
29
+ "open-graph",
30
+ "scraper",
23
31
  "video"
24
32
  ],
25
33
  "dependencies": {
26
- "@metascraper/helpers": "5.53.0",
34
+ "@metascraper/helpers": "5.54.0",
27
35
  "p-reflect": "~3.1.0"
28
36
  },
29
37
  "devDependencies": {
@@ -46,5 +54,5 @@
46
54
  "!test/helpers.js"
47
55
  ]
48
56
  },
49
- "gitHead": "440ebd15db49ef9cf793869bceba5121bca49ad1"
57
+ "gitHead": "23db3208c1dcc6367a705bdb9bf723fbaae259e0"
50
58
  }
package/src/index.js CHANGED
@@ -4,12 +4,10 @@ const {
4
4
  $jsonld,
5
5
  createGetIframeCached,
6
6
  defaultGetIframe,
7
- findRule,
8
- has,
9
- normalizeUrl,
10
7
  toRule,
11
8
  url: urlFn,
12
- video
9
+ video,
10
+ withIframe
13
11
  } = require('@metascraper/helpers')
14
12
 
15
13
  const toUrl = toRule(urlFn)
@@ -68,43 +66,11 @@ const videoRules = [
68
66
 
69
67
  const imageRules = [toUrl($ => $('video').attr('poster'))]
70
68
 
71
- const withIframe = (rules, getIframe) =>
72
- rules.concat(
73
- async ({ htmlDom: $, url }) => {
74
- const srcs = $('iframe[src^="http"], iframe[src^="/"]')
75
- .map((_, element) => $(element).attr('src'))
76
- .get()
77
- if (srcs.length === 0) return
78
- const seenSrcs = new Set()
79
- for (const src of srcs) {
80
- try {
81
- const normalizedSrc = normalizeUrl(url, src)
82
- if (!normalizedSrc) continue
83
- if (seenSrcs.has(normalizedSrc)) continue
84
- seenSrcs.add(normalizedSrc)
85
-
86
- const htmlDom = await getIframe(url, $, normalizedSrc)
87
- const result = await findRule(rules, { htmlDom, url })
88
- if (has(result)) return result
89
- } catch (_) {}
90
- }
91
- },
92
- async ({ htmlDom: $, url }) => {
93
- const src = $('meta[name="twitter:player"]').attr('content')
94
- return src
95
- ? findRule(rules, {
96
- htmlDom: await getIframe(url, $, src),
97
- url
98
- })
99
- : undefined
100
- }
101
- )
102
-
103
69
  module.exports = ({ getIframe = defaultGetIframe } = {}) => {
104
70
  const getIframeCached = createGetIframeCached(getIframe)
105
71
  const rules = {
106
- image: withIframe(imageRules, getIframeCached),
107
- video: withIframe(videoRules, getIframeCached)
72
+ image: withIframe(imageRules, getIframeCached, 'image'),
73
+ video: withIframe(videoRules, getIframeCached, 'video')
108
74
  }
109
75
 
110
76
  rules.pkgName = 'metascraper-video'