@unavatar/core 3.42.1 → 3.43.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
@@ -68,6 +68,7 @@
68
68
  - [Telegram](#telegram)
69
69
  - [Thingiverse](#thingiverse)
70
70
  - [Threads](#threads)
71
+ - [TIDAL](#tidal)
71
72
  - [TikTok](#tiktok)
72
73
  - [Tumblr](#tumblr)
73
74
  - [Twitch](#twitch)
@@ -945,6 +946,22 @@ Get any Threads user's profile picture by their username.
945
946
 
946
947
  e.g., [unavatar.io/threads/zuck](https://unavatar.io/threads/zuck)
947
948
 
949
+ ### TIDAL
950
+
951
+ Get artwork for any TIDAL entity — artists, albums, playlists, tracks, or videos. Look up by TIDAL ID.
952
+
953
+ By default the input is treated as an artist:
954
+
955
+ e.g., [unavatar.io/tidal/1566](https://unavatar.io/tidal/1566)
956
+
957
+ The input also supports a URI format `type:id`:
958
+
959
+ - `artist` (default): [unavatar.io/tidal/artist:1566](https://unavatar.io/tidal/artist:1566)
960
+ - `album`: [unavatar.io/tidal/album:1765857](https://unavatar.io/tidal/album:1765857)
961
+ - `playlist`: [unavatar.io/tidal/playlist:c3c18106-c4f5-4021-bb18-108255c1f450](https://unavatar.io/tidal/playlist:c3c18106-c4f5-4021-bb18-108255c1f450)
962
+ - `track`: [unavatar.io/tidal/track:113655761](https://unavatar.io/tidal/track:113655761)
963
+ - `video`: [unavatar.io/tidal/video:45323542](https://unavatar.io/tidal/video:45323542)
964
+
948
965
  ### TikTok
949
966
 
950
967
  Get any TikTok user's profile picture by their username. No authentication or API tokens needed — just pass the 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.42.1",
5
+ "version": "3.43.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -51,6 +51,7 @@ const providersBy = {
51
51
  'telegram',
52
52
  'thingiverse',
53
53
  'threads',
54
+ 'tidal',
54
55
  'tiktok',
55
56
  'tumblr',
56
57
  'twitch',
@@ -118,6 +119,7 @@ module.exports = ctx => {
118
119
  telegram: require('./telegram')(ctx),
119
120
  thingiverse: require('./thingiverse')(ctx),
120
121
  threads: require('./threads')(ctx),
122
+ tidal: require('./tidal')(ctx),
121
123
  tiktok: require('./tiktok')(ctx),
122
124
  tumblr: require('./tumblr')(ctx),
123
125
  twitch: require('./twitch')(ctx),
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ // Real artwork is served from resources.tidal.com. When an entity has no
4
+ // artwork the page keeps a generic share image (tidal.com/img/FB_…), so
5
+ // anything off the resources host is treated as a miss.
6
+ const isArtwork = url => /^https:\/\/resources\.tidal\.com\//.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://tidal.com/${type}/${id}`
13
+ }
14
+
15
+ // The static markup only ships the generic share image; the entity artwork is
16
+ // injected into og:image once the SPA hydrates, so the page must be prerendered.
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: 'tidal',
25
+ url: getAvatarUrl,
26
+ getter: $ => getAvatar({ $, getOgImage, NOT_FOUND }),
27
+ htmlOpts: () => ({
28
+ prerender: true
29
+ })
30
+ })
31
+
32
+ factory.getAvatarUrl = getAvatarUrl
33
+ factory.getAvatar = getAvatar
34
+
35
+ module.exports = factory