metascraper-media-provider 5.58.13 → 5.59.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/README.md +22 -0
- package/package.json +2 -2
- package/src/get-media.js +4 -2
- package/src/index.d.ts +5 -0
package/README.md
CHANGED
|
@@ -55,6 +55,28 @@ const args = ({ flags, url, retryCount }) => {
|
|
|
55
55
|
}
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
##### run
|
|
59
|
+
|
|
60
|
+
Type: `function`<br>
|
|
61
|
+
Default: [youtube-dl-exec](https://github.com/microlinkhq/youtube-dl-exec)
|
|
62
|
+
|
|
63
|
+
It runs [youtube-dl](youtube-dl) with the `url`, the `flags` returned by `args` and the process options (`timeout` is the time left), and returns its JSON output. Use it to answer a failure with a different call:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const youtubedl = require('youtube-dl-exec')
|
|
67
|
+
|
|
68
|
+
const run = async (url, flags, opts) => {
|
|
69
|
+
const startedAt = Date.now()
|
|
70
|
+
try {
|
|
71
|
+
return await youtubedl(url, flags, opts)
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const timeout = opts.timeout - (Date.now() - startedAt)
|
|
74
|
+
if (!/not a bot/.test(error.stderr) || timeout <= 0) throw error
|
|
75
|
+
return youtubedl(url, { ...flags, proxy: process.env.PROXY_URL }, { ...opts, timeout })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
58
80
|
## License
|
|
59
81
|
|
|
60
82
|
**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": "Metascraper media provider that resolves video URLs via youtube-dl compatible extractors.",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-media-provider",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.59.0",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"author": {
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"!test/fixtures/generate.js"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f8168a8e828328561f58427a467753e6e3461a30"
|
|
66
66
|
}
|
package/src/get-media.js
CHANGED
|
@@ -46,7 +46,7 @@ const getMedia = async ({
|
|
|
46
46
|
const { url, flags } = await getArgs({
|
|
47
47
|
url: targetUrl,
|
|
48
48
|
retryCount,
|
|
49
|
-
flags: DEFAULT_FLAGS
|
|
49
|
+
flags: { ...DEFAULT_FLAGS }
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
data = await run(url, flags, { timeout: getRemainingTimeout(), ...props })
|
|
@@ -70,6 +70,7 @@ module.exports = ({
|
|
|
70
70
|
timeout = 30000,
|
|
71
71
|
retry = 2,
|
|
72
72
|
args: getArgs = ({ url, flags }) => ({ url, flags }),
|
|
73
|
+
run,
|
|
73
74
|
...props
|
|
74
75
|
}) =>
|
|
75
76
|
asyncMemoizeOne(targetUrl =>
|
|
@@ -78,7 +79,8 @@ module.exports = ({
|
|
|
78
79
|
getArgs,
|
|
79
80
|
retry,
|
|
80
81
|
timeout,
|
|
81
|
-
props
|
|
82
|
+
props,
|
|
83
|
+
run
|
|
82
84
|
})
|
|
83
85
|
)
|
|
84
86
|
|
package/src/index.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ type Options = {
|
|
|
19
19
|
* @default 2
|
|
20
20
|
*/
|
|
21
21
|
retry?: number;
|
|
22
|
+
run?: (
|
|
23
|
+
url: string,
|
|
24
|
+
flags: import('youtube-dl-exec').Flags,
|
|
25
|
+
opts: { timeout: number }
|
|
26
|
+
) => Promise<unknown>;
|
|
22
27
|
/**
|
|
23
28
|
* The options to pass to https://github.com/sindresorhus/got#options
|
|
24
29
|
* @default {}
|