metascraper-media-provider 5.46.19 → 5.47.1

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
@@ -41,17 +41,17 @@ Default: `30000`
41
41
 
42
42
  The maximum time allowed to wait until considering the request as timed out.
43
43
 
44
- ##### flags
44
+ ##### args
45
45
 
46
46
  Type: `function`<br>
47
- Default: `object`
47
+ Default: `({ url, flags }) => ({ url, flags })`
48
48
 
49
- It defines a function that will determine the flags to be passed to [youtube-dl](youtube-dl):
49
+ It defines a function that will determine the arguments to be passed to [youtube-dl](youtube-dl):
50
50
 
51
51
  ```js
52
- const getFlags = ({ flags, url, retryCount }) => {
52
+ const args = ({ flags, url, retryCount }) => {
53
53
  flags.addHeader = [`referer:${url}`]
54
- return flags
54
+ return { url, flags }
55
55
  }
56
56
  ```
57
57
 
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.19",
5
+ "version": "5.47.1",
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.18",
27
+ "@metascraper/helpers": "5.47.1",
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": "c8dc21fd2739859372d9fdb559aa19fdc833bed5"
62
+ "gitHead": "42c9ecc875f13a77074f5b723f3dc87a9d657dc3"
63
63
  }
package/src/get-media.js CHANGED
@@ -4,11 +4,12 @@ const debug = require('debug-logfmt')(
4
4
  'metascraper-media-provider:provider:generic'
5
5
  )
6
6
  const { serializeError } = require('serialize-error')
7
+ const { parseUrl } = require('@metascraper/helpers')
7
8
  const asyncMemoizeOne = require('async-memoize-one')
8
9
  const youtubedl = require('youtube-dl-exec')
9
10
  const pTimeout = require('p-timeout')
10
11
 
11
- const RE_UNSUPORTED_URL = /Unsupported URL/
12
+ const RE_UNSUPPORTED_URL = /Unsupported URL/
12
13
 
13
14
  const DEFAULT_FLAGS = {
14
15
  dumpSingleJson: true,
@@ -20,10 +21,10 @@ const DEFAULT_FLAGS = {
20
21
  module.exports = ({
21
22
  timeout = 30000,
22
23
  retry = 2,
23
- flags: getFlags = ({ flags }) => flags,
24
+ args: getArgs = ({ url, flags }) => ({ url, flags }),
24
25
  ...props
25
26
  }) =>
26
- asyncMemoizeOne(async url => {
27
+ asyncMemoizeOne(async targetUrl => {
27
28
  const retryCount = 0
28
29
  let isTimeout = false
29
30
  let isSupportedURL = true
@@ -35,17 +36,21 @@ module.exports = ({
35
36
  const task = async () => {
36
37
  do {
37
38
  try {
38
- const flags = await getFlags({
39
- url,
39
+ const { url, flags } = await getArgs({
40
+ url: targetUrl,
40
41
  retryCount,
41
42
  flags: DEFAULT_FLAGS
42
43
  })
44
+
43
45
  data = await youtubedl(url, flags, { timeout, ...props })
44
46
  } catch (error) {
45
47
  if (condition()) {
46
48
  debug('getInfo:error', { retryCount }, serializeError(error))
47
49
  }
48
- isSupportedURL = !RE_UNSUPORTED_URL.test(error.stderr)
50
+
51
+ const isYoutube = parseUrl(targetUrl).domain === 'youtube.com'
52
+ const isUnsupported = RE_UNSUPPORTED_URL.test(error.stderr)
53
+ isSupportedURL = isYoutube ? isUnsupported : !isUnsupported
49
54
  }
50
55
  } while (condition())
51
56