metascraper-video 5.34.9 → 5.35.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.
- package/index.js +30 -10
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -10,29 +10,49 @@ const {
|
|
|
10
10
|
video
|
|
11
11
|
} = require('@metascraper/helpers')
|
|
12
12
|
|
|
13
|
+
const { chain, isEqual } = require('lodash')
|
|
13
14
|
const memoize = require('@keyvhq/memoize')
|
|
14
15
|
const pReflect = require('p-reflect')
|
|
15
|
-
const { chain } = require('lodash')
|
|
16
16
|
const got = require('got')
|
|
17
17
|
|
|
18
18
|
const toUrl = toRule(urlFn)
|
|
19
|
+
|
|
19
20
|
const toVideo = toRule(video)
|
|
20
21
|
|
|
21
22
|
const toVideoFromDom = toRule((domNodes, opts) => {
|
|
22
|
-
const
|
|
23
|
-
.map(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const values = chain(domNodes)
|
|
24
|
+
.map(domNode => ({
|
|
25
|
+
src: domNode?.attribs.src,
|
|
26
|
+
type: domNode?.attribs.type
|
|
27
|
+
}))
|
|
28
|
+
.uniqWith(isEqual)
|
|
29
|
+
.orderBy(
|
|
30
|
+
({ src, type }) => extension(src) === 'mp4' || type?.includes('mp4'),
|
|
31
|
+
['desc']
|
|
32
|
+
)
|
|
27
33
|
.value()
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
let result
|
|
36
|
+
values.find(
|
|
37
|
+
({ src, type }) => (result = video(src, Object.assign({ type }, opts)))
|
|
38
|
+
)
|
|
39
|
+
return result
|
|
30
40
|
})
|
|
31
41
|
|
|
32
42
|
const videoRules = [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
({ url, htmlDom: $ }) => {
|
|
44
|
+
const src =
|
|
45
|
+
$('meta[property="og:video:secure_url"]').attr('content') ||
|
|
46
|
+
$('meta[property="og:video:url"]').attr('content') ||
|
|
47
|
+
$('meta[property="og:video"]').attr('content')
|
|
48
|
+
|
|
49
|
+
return src
|
|
50
|
+
? video(src, {
|
|
51
|
+
url,
|
|
52
|
+
type: $('meta[property="og:video:type"]').attr('content')
|
|
53
|
+
})
|
|
54
|
+
: undefined
|
|
55
|
+
},
|
|
36
56
|
toVideo($ => $('meta[name="twitter:player:stream"]').attr('content')),
|
|
37
57
|
toVideo($ => $('meta[property="twitter:player:stream"]').attr('content')),
|
|
38
58
|
toVideo($jsonld('contentUrl')),
|
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.
|
|
5
|
+
"version": "5.35.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@keyvhq/memoize": "~2.0.3",
|
|
26
|
-
"@metascraper/helpers": "^5.
|
|
26
|
+
"@metascraper/helpers": "^5.35.0",
|
|
27
27
|
"got": "~11.8.6",
|
|
28
28
|
"lodash": "~4.17.21",
|
|
29
29
|
"p-reflect": "~2.1.0"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"test": "NODE_PATH=.. TZ=UTC ava --timeout 15s"
|
|
42
42
|
},
|
|
43
43
|
"license": "MIT",
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4050798d28b1118e3bb8058bf17b182bb84b7c5b"
|
|
45
45
|
}
|