metascraper-media-provider 5.58.14 → 5.59.3

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 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.58.14",
5
+ "version": "5.59.3",
6
6
  "types": "src/index.d.ts",
7
7
  "main": "src/index.js",
8
8
  "author": {
@@ -31,7 +31,7 @@
31
31
  "yt-dlp"
32
32
  ],
33
33
  "dependencies": {
34
- "@metascraper/helpers": "5.58.13",
34
+ "@metascraper/helpers": "5.59.3",
35
35
  "async-memoize-one": "~1.2.1",
36
36
  "debug-logfmt": "~1.4.15",
37
37
  "lodash": "~4.18.1",
@@ -62,5 +62,5 @@
62
62
  "!test/fixtures/generate.js"
63
63
  ]
64
64
  },
65
- "gitHead": "cb3e65149a2e66a23a9396785e5d08850e72f5ac"
65
+ "gitHead": "aa2f5c54d37d63962f75366e897ca461c6bb18be"
66
66
  }
package/src/get-media.js CHANGED
@@ -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 {}