metascraper-media-provider 5.46.14 → 5.46.16
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/README.md +14 -18
- package/package.json +3 -3
- package/src/get-media.js +9 -29
package/README.md
CHANGED
|
@@ -26,24 +26,6 @@ Type: `string`
|
|
|
26
26
|
|
|
27
27
|
It specifies cache based on file system to be used by [youtube-dl](youtube-dl).
|
|
28
28
|
|
|
29
|
-
##### getProxy
|
|
30
|
-
|
|
31
|
-
Type: `function`
|
|
32
|
-
|
|
33
|
-
It will be called to determinate if a proxy should be used for resolving the next request URL.
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
const getProxy = ({ url, retryCount }) => {
|
|
37
|
-
if (retryCount === 0) return false
|
|
38
|
-
return 'http://user:pwd@proxy:8001'
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
##### gotOpts
|
|
43
|
-
|
|
44
|
-
Type: `object`
|
|
45
|
-
|
|
46
|
-
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
|
|
47
29
|
|
|
48
30
|
##### retry
|
|
49
31
|
|
|
@@ -59,6 +41,20 @@ Default: `30000`
|
|
|
59
41
|
|
|
60
42
|
The maximum time allowed to wait until considering the request as timed out.
|
|
61
43
|
|
|
44
|
+
##### flags
|
|
45
|
+
|
|
46
|
+
Type: `function`<br>
|
|
47
|
+
Default: `object`
|
|
48
|
+
|
|
49
|
+
It defines a function that will determine the flags to be passed to [youtube-dl](youtube-dl):
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const getFlags = ({ flags, url, retryCount }) => {
|
|
53
|
+
flags.addHeader = [`referer:${url}`]
|
|
54
|
+
return flags
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
62
58
|
## License
|
|
63
59
|
|
|
64
60
|
**metascraper-media-provider** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "metascraper-media-provider",
|
|
3
3
|
"description": "Get video property from HTML markup",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-media-provider",
|
|
5
|
-
"version": "5.46.
|
|
5
|
+
"version": "5.46.16",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"youtube-dl"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@metascraper/helpers": "5.46.
|
|
27
|
+
"@metascraper/helpers": "5.46.15",
|
|
28
28
|
"async-memoize-one": "~1.1.8",
|
|
29
29
|
"debug-logfmt": "~1.2.3",
|
|
30
30
|
"got": "~11.8.6",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"!test/fixtures/generate.js"
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6d7b7dcce5db11bfc290ea184736bc86224ec47d"
|
|
63
63
|
}
|
package/src/get-media.js
CHANGED
|
@@ -6,42 +6,25 @@ const debug = require('debug-logfmt')(
|
|
|
6
6
|
const { serializeError } = require('serialize-error')
|
|
7
7
|
const asyncMemoizeOne = require('async-memoize-one')
|
|
8
8
|
const youtubedl = require('youtube-dl-exec')
|
|
9
|
-
const { get, constant } = require('lodash')
|
|
10
9
|
const pTimeout = require('p-timeout')
|
|
11
10
|
|
|
12
11
|
const RE_UNSUPORTED_URL = /Unsupported URL/
|
|
13
12
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
preferFreeFormats: true
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
flags.addHeader = [
|
|
23
|
-
`referer:${url}`,
|
|
24
|
-
userAgent && `user-agent:${userAgent}`
|
|
25
|
-
].filter(Boolean)
|
|
26
|
-
|
|
27
|
-
if (cacheDir) flags.cacheDir = cacheDir
|
|
28
|
-
else flags.noCacheDir = true
|
|
29
|
-
|
|
30
|
-
if (proxy) flags.proxy = proxy.toString()
|
|
31
|
-
|
|
32
|
-
return flags
|
|
13
|
+
const DEFAULT_FLAGS = {
|
|
14
|
+
dumpSingleJson: true,
|
|
15
|
+
noCheckCertificates: true,
|
|
16
|
+
noWarnings: true,
|
|
17
|
+
preferFreeFormats: true
|
|
33
18
|
}
|
|
34
19
|
|
|
35
20
|
module.exports = ({
|
|
36
|
-
cacheDir,
|
|
37
|
-
getProxy = constant(false),
|
|
38
21
|
timeout = 30000,
|
|
39
22
|
retry = 2,
|
|
40
|
-
|
|
23
|
+
flags: getFlags = ({ flags }) => flags,
|
|
41
24
|
...props
|
|
42
25
|
}) =>
|
|
43
26
|
asyncMemoizeOne(async url => {
|
|
44
|
-
|
|
27
|
+
const retryCount = 0
|
|
45
28
|
let isTimeout = false
|
|
46
29
|
let isSupportedURL = true
|
|
47
30
|
let data
|
|
@@ -49,13 +32,10 @@ module.exports = ({
|
|
|
49
32
|
const condition = () =>
|
|
50
33
|
isSupportedURL && !isTimeout && data === undefined && retryCount <= retry
|
|
51
34
|
|
|
52
|
-
const userAgent = get(gotOpts, 'headers.user-agent')
|
|
53
|
-
|
|
54
35
|
const task = async () => {
|
|
55
36
|
do {
|
|
56
37
|
try {
|
|
57
|
-
const
|
|
58
|
-
const flags = getFlags({ url, proxy, userAgent, cacheDir })
|
|
38
|
+
const flags = getFlags({ url, retryCount, flags: DEFAULT_FLAGS })
|
|
59
39
|
data = await youtubedl(url, flags, { timeout, ...props })
|
|
60
40
|
} catch (error) {
|
|
61
41
|
if (condition()) {
|
|
@@ -76,4 +56,4 @@ module.exports = ({
|
|
|
76
56
|
return pTimeout(task(), timeout, fallback).then(data => data ?? {})
|
|
77
57
|
})
|
|
78
58
|
|
|
79
|
-
module.exports.
|
|
59
|
+
module.exports.DEFAULT_FLAGS = DEFAULT_FLAGS
|