metascraper-video 5.35.1 → 5.35.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/index.js +38 -45
- package/package.json +4 -7
package/index.js
CHANGED
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
$jsonld,
|
|
5
|
-
|
|
5
|
+
$twitter,
|
|
6
|
+
loadIframe,
|
|
6
7
|
findRule,
|
|
7
|
-
normalizeUrl,
|
|
8
8
|
toRule,
|
|
9
9
|
url: urlFn,
|
|
10
10
|
video
|
|
11
11
|
} = require('@metascraper/helpers')
|
|
12
12
|
|
|
13
|
-
const { chain, isEqual } = require('lodash')
|
|
14
|
-
const memoize = require('@keyvhq/memoize')
|
|
15
|
-
const pReflect = require('p-reflect')
|
|
16
|
-
const got = require('got')
|
|
13
|
+
const { chain, find, isEqual } = require('lodash')
|
|
17
14
|
|
|
18
15
|
const toUrl = toRule(urlFn)
|
|
19
16
|
|
|
@@ -23,17 +20,20 @@ const toVideoFromDom = toRule((domNodes, opts) => {
|
|
|
23
20
|
const values = chain(domNodes)
|
|
24
21
|
.map(domNode => ({
|
|
25
22
|
src: domNode?.attribs.src,
|
|
26
|
-
type: domNode
|
|
23
|
+
type: chain(domNode)
|
|
24
|
+
.get('attribs.type')
|
|
25
|
+
.split(';')
|
|
26
|
+
.get(0)
|
|
27
|
+
.split('/')
|
|
28
|
+
.get(1)
|
|
29
|
+
.value()
|
|
27
30
|
}))
|
|
28
31
|
.uniqWith(isEqual)
|
|
29
|
-
.orderBy(
|
|
30
|
-
({ src, type }) => extension(src) === 'mp4' || type?.includes('mp4'),
|
|
31
|
-
['desc']
|
|
32
|
-
)
|
|
33
32
|
.value()
|
|
34
33
|
|
|
35
34
|
let result
|
|
36
|
-
|
|
35
|
+
find(
|
|
36
|
+
values,
|
|
37
37
|
({ src, type }) => (result = video(src, Object.assign({ type }, opts)))
|
|
38
38
|
)
|
|
39
39
|
return result
|
|
@@ -53,44 +53,37 @@ const videoRules = [
|
|
|
53
53
|
})
|
|
54
54
|
: undefined
|
|
55
55
|
},
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
({ url, htmlDom: $ }) => {
|
|
57
|
+
const src = $twitter($, 'twitter:player:stream')
|
|
58
|
+
return src
|
|
59
|
+
? video(src, {
|
|
60
|
+
url,
|
|
61
|
+
type: $twitter($, 'twitter:player:stream:content_type')
|
|
62
|
+
})
|
|
63
|
+
: undefined
|
|
64
|
+
},
|
|
58
65
|
toVideo($jsonld('contentUrl')),
|
|
59
66
|
toVideoFromDom($ => $('video').get()),
|
|
60
67
|
toVideoFromDom($ => $('video > source').get())
|
|
61
68
|
]
|
|
62
69
|
|
|
63
|
-
const
|
|
64
|
-
const getPlayer = async playerUrl => {
|
|
65
|
-
const { value: response } = await pReflect(got(playerUrl, gotOpts))
|
|
66
|
-
if (!response) return
|
|
67
|
-
const contentType = response.headers['content-type']
|
|
68
|
-
if (!contentType || !contentType.startsWith('text')) return
|
|
69
|
-
return response.body
|
|
70
|
-
}
|
|
71
|
-
return memoize(getPlayer, keyvOpts, {
|
|
72
|
-
value: value => (value === undefined ? null : value)
|
|
73
|
-
})
|
|
74
|
-
}
|
|
70
|
+
const imageRules = [toUrl($ => $('video').attr('poster'))]
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
const _getIframe = (url, $, { src }) =>
|
|
73
|
+
loadIframe(url, $.load(`<iframe src="${src}"></iframe>`))
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
const withIframe = (rules, getIframe) =>
|
|
76
|
+
rules.concat(async ({ htmlDom: $, url }) => {
|
|
77
|
+
const src = $twitter($, 'twitter:player')
|
|
78
|
+
return src
|
|
79
|
+
? findRule(rules, {
|
|
80
|
+
htmlDom: await getIframe(url, $, { src }),
|
|
81
|
+
url
|
|
82
|
+
})
|
|
83
|
+
: undefined
|
|
84
|
+
})
|
|
87
85
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return findRule(videoRules, { htmlDom, url })
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
}
|
|
86
|
+
module.exports = ({ getIframe = _getIframe } = {}) => ({
|
|
87
|
+
image: withIframe(imageRules, getIframe),
|
|
88
|
+
video: withIframe(videoRules, getIframe)
|
|
89
|
+
})
|
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.35.
|
|
5
|
+
"version": "5.35.2",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -22,11 +22,8 @@
|
|
|
22
22
|
"video"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"got": "~11.8.6",
|
|
28
|
-
"lodash": "~4.17.21",
|
|
29
|
-
"p-reflect": "~2.1.0"
|
|
25
|
+
"@metascraper/helpers": "^5.35.2",
|
|
26
|
+
"lodash": "~4.17.21"
|
|
30
27
|
},
|
|
31
28
|
"devDependencies": {
|
|
32
29
|
"ava": "latest"
|
|
@@ -41,5 +38,5 @@
|
|
|
41
38
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
42
39
|
},
|
|
43
40
|
"license": "MIT",
|
|
44
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ba30cbe6b6d649f845131278f65504e9c63db622"
|
|
45
42
|
}
|