metascraper-spotify 5.26.3 → 5.27.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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/index.js +15 -8
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -23,6 +23,12 @@ Type: `object`
23
23
 
24
24
  Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
25
25
 
26
+ ##### keyvOpts
27
+
28
+ Type: `object`
29
+
30
+ Any option provided here will passed to [@keyvhq/memoize#options](https://github.com/microlinkhq/keyv/tree/master/packages/memoize#keyvoptions).
31
+
26
32
  ## License
27
33
 
28
34
  **metascraper-spotify** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
package/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const { composeRule, memoizeOne } = require('@metascraper/helpers')
4
4
  const asyncMemoizeOne = require('async-memoize-one')
5
5
  const { getDomainWithoutSuffix } = require('tldts')
6
+ const memoize = require('@keyvhq/memoize')
6
7
  const got = require('got')
7
8
 
8
9
  const { getPreview } = require('spotify-url-info')((url, opts) =>
@@ -11,18 +12,24 @@ const { getPreview } = require('spotify-url-info')((url, opts) =>
11
12
  }))
12
13
  )
13
14
 
14
- const spotify = asyncMemoizeOne(async url => {
15
- try {
16
- return await getPreview(url)
17
- } catch (_) {
18
- return {}
15
+ const createSpotify = ({ gotOpts, keyvOpts }) => {
16
+ const spotify = async url => {
17
+ try {
18
+ const result = await getPreview(url, gotOpts)
19
+ return result
20
+ } catch (_) {
21
+ return {}
22
+ }
19
23
  }
20
- })
24
+
25
+ return asyncMemoizeOne(memoize(spotify, keyvOpts))
26
+ }
21
27
 
22
28
  const isValidUrl = memoizeOne(url => getDomainWithoutSuffix(url) === 'spotify')
23
29
 
24
- module.exports = ({ gotOpts } = {}) => {
25
- const getSpotify = composeRule(($, url) => spotify(url, gotOpts))
30
+ module.exports = ({ gotOpts, keyvOpts } = {}) => {
31
+ const spotify = createSpotify({ gotOpts, keyvOpts })
32
+ const getSpotify = composeRule(($, url) => spotify(url))
26
33
 
27
34
  const rules = {
28
35
  audio: getSpotify({ from: 'audio', ext: 'mp3' }),
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-spotify",
3
3
  "description": "Metascraper integration with Spotify",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-spotify",
5
- "version": "5.26.3",
5
+ "version": "5.27.3",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -23,6 +23,7 @@
23
23
  "spotify"
24
24
  ],
25
25
  "dependencies": {
26
+ "@keyvhq/memoize": "~1.6.6",
26
27
  "@metascraper/helpers": "^5.26.0",
27
28
  "async-memoize-one": "~1.1.0",
28
29
  "got": "~11.8.3",
@@ -46,5 +47,5 @@
46
47
  "test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
47
48
  },
48
49
  "license": "MIT",
49
- "gitHead": "9a69931fa22a94d4b2903731f7043f16d7aed469"
50
+ "gitHead": "7f6a2b9edc7fe1342ca08368ff9d5aa3f3dedc2c"
50
51
  }