@unavatar/core 3.43.0 → 3.44.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 CHANGED
@@ -25,6 +25,7 @@
25
25
  - [CodePen](#codepen)
26
26
  - [Cults3D](#cults3d)
27
27
  - [Cursor](#cursor)
28
+ - [Deezer](#deezer)
28
29
  - [DeviantArt](#deviantart)
29
30
  - [Discord](#discord)
30
31
  - [Docker Hub](#docker-hub)
@@ -596,6 +597,21 @@ Get any Cursor user's profile picture by their username.
596
597
 
597
598
  e.g., [unavatar.io/cursor/leerob](https://unavatar.io/cursor/leerob)
598
599
 
600
+ ### Deezer
601
+
602
+ Get artwork for any Deezer entity — artists, albums, playlists, or tracks. Look up by Deezer ID.
603
+
604
+ By default the input is treated as an artist:
605
+
606
+ e.g., [unavatar.io/deezer/27](https://unavatar.io/deezer/27)
607
+
608
+ The input also supports a URI format `type:id`:
609
+
610
+ - `artist` (default): [unavatar.io/deezer/artist:27](https://unavatar.io/deezer/artist:27)
611
+ - `album`: [unavatar.io/deezer/album:302127](https://unavatar.io/deezer/album:302127)
612
+ - `playlist`: [unavatar.io/deezer/playlist:908622995](https://unavatar.io/deezer/playlist:908622995)
613
+ - `track`: [unavatar.io/deezer/track:3135556](https://unavatar.io/deezer/track:3135556)
614
+
599
615
  ### DeviantArt
600
616
 
601
617
  Get any DeviantArt user's profile picture by their username.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@unavatar/core",
3
3
  "description": "Get unified user avatar from social networks, including Instagram, SoundCloud, Telegram, Twitter, YouTube & more.",
4
4
  "homepage": "https://unavatar.io",
5
- "version": "3.43.0",
5
+ "version": "3.44.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ // Entities without artwork keep an empty image hash
4
+ // (cdn-images.dzcdn.net/images/artist//500x500.jpg), which resolves to a
5
+ // generic placeholder, so any empty hash segment is treated as a miss.
6
+ const isArtwork = url => !/\/images\/[^/]+\/\/\d/.test(url)
7
+
8
+ const getAvatarUrl = input => {
9
+ const [first, second] = input.split(':')
10
+ const type = second ? first : 'artist'
11
+ const id = second ?? first
12
+ return `https://www.deezer.com/en/${type}/${id}`
13
+ }
14
+
15
+ // Deezer server-renders og:image for missing entities as well, so the empty
16
+ // placeholder is filtered out and everything else is returned as-is.
17
+ const getAvatar = ({ $, getOgImage, NOT_FOUND }) => {
18
+ const image = getOgImage($)
19
+ return image && isArtwork(image) ? image : NOT_FOUND
20
+ }
21
+
22
+ const factory = ({ createHtmlProvider, getOgImage, NOT_FOUND }) =>
23
+ createHtmlProvider({
24
+ name: 'deezer',
25
+ url: getAvatarUrl,
26
+ getter: $ => getAvatar({ $, getOgImage, NOT_FOUND })
27
+ })
28
+
29
+ factory.getAvatarUrl = getAvatarUrl
30
+ factory.getAvatar = getAvatar
31
+
32
+ module.exports = factory
@@ -12,6 +12,7 @@ const providersBy = {
12
12
  'codepen',
13
13
  'cults3d',
14
14
  'cursor',
15
+ 'deezer',
15
16
  'deviantart',
16
17
  'discord',
17
18
  'dockerhub',
@@ -76,6 +77,7 @@ module.exports = ctx => {
76
77
  codepen: require('./codepen')(ctx),
77
78
  cults3d: require('./cults3d')(ctx),
78
79
  cursor: require('./cursor')(ctx),
80
+ deezer: require('./deezer')(ctx),
79
81
  deviantart: require('./deviantart')(ctx),
80
82
  discord: require('./discord')(ctx),
81
83
  dockerhub: require('./dockerhub')(ctx),