metascraper-spotify 5.25.8 → 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 +18 -0
  2. package/index.js +23 -10
  3. package/package.json +7 -5
package/README.md CHANGED
@@ -11,6 +11,24 @@
11
11
  $ npm install metascraper-spotify --save
12
12
  ```
13
13
 
14
+ ## API
15
+
16
+ ### metascraper-spotify([options])
17
+
18
+ #### options
19
+
20
+ ##### gotOpts
21
+
22
+ Type: `object`
23
+
24
+ Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
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
+
14
32
  ## License
15
33
 
16
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,21 +3,34 @@
3
3
  const { composeRule, memoizeOne } = require('@metascraper/helpers')
4
4
  const asyncMemoizeOne = require('async-memoize-one')
5
5
  const { getDomainWithoutSuffix } = require('tldts')
6
- const { getPreview } = require('spotify-url-info')
7
-
8
- const spotify = asyncMemoizeOne(async url => {
9
- try {
10
- return await getPreview(url)
11
- } catch (_) {
12
- return {}
6
+ const memoize = require('@keyvhq/memoize')
7
+ const got = require('got')
8
+
9
+ const { getPreview } = require('spotify-url-info')((url, opts) =>
10
+ got(url, opts).then(res => ({
11
+ text: () => Promise.resolve(res.body)
12
+ }))
13
+ )
14
+
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
+ }
13
23
  }
14
- })
15
24
 
16
- const getSpotify = composeRule(($, url) => spotify(url))
25
+ return asyncMemoizeOne(memoize(spotify, keyvOpts))
26
+ }
17
27
 
18
28
  const isValidUrl = memoizeOne(url => getDomainWithoutSuffix(url) === 'spotify')
19
29
 
20
- module.exports = () => {
30
+ module.exports = ({ gotOpts, keyvOpts } = {}) => {
31
+ const spotify = createSpotify({ gotOpts, keyvOpts })
32
+ const getSpotify = composeRule(($, url) => spotify(url))
33
+
21
34
  const rules = {
22
35
  audio: getSpotify({ from: 'audio', ext: 'mp3' }),
23
36
  author: getSpotify({ from: 'artist', to: 'author' }),
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.25.8",
5
+ "version": "5.27.3",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -23,10 +23,12 @@
23
23
  "spotify"
24
24
  ],
25
25
  "dependencies": {
26
- "@metascraper/helpers": "^5.25.8",
26
+ "@keyvhq/memoize": "~1.6.6",
27
+ "@metascraper/helpers": "^5.26.0",
27
28
  "async-memoize-one": "~1.1.0",
28
- "spotify-url-info": "~2.2.3",
29
- "tldts": "~5.7.57"
29
+ "got": "~11.8.3",
30
+ "spotify-url-info": "~3.0.0",
31
+ "tldts": "~5.7.70"
30
32
  },
31
33
  "devDependencies": {
32
34
  "kind-of": "latest",
@@ -45,5 +47,5 @@
45
47
  "test": "NODE_PATH=.. TZ=UTC NODE_ENV=test mocha test"
46
48
  },
47
49
  "license": "MIT",
48
- "gitHead": "9513b1ebc0262208119f1e7e17c1ac3758d26811"
50
+ "gitHead": "7f6a2b9edc7fe1342ca08368ff9d5aa3f3dedc2c"
49
51
  }