@unavatar/core 3.52.0 → 3.54.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
@@ -31,6 +31,7 @@
31
31
  - [CodePen](#codepen)
32
32
  - [Cults3D](#cults3d)
33
33
  - [Cursor](#cursor)
34
+ - [Dailymotion](#dailymotion)
34
35
  - [Deezer](#deezer)
35
36
  - [DeviantArt](#deviantart)
36
37
  - [Discord](#discord)
@@ -58,6 +59,7 @@
58
59
  - [Mastodon](#mastodon)
59
60
  - [Medium](#medium)
60
61
  - [Microlink](#microlink)
62
+ - [Minecraft](#minecraft)
61
63
  - [NetEase Music](#netease-music)
62
64
  - [npm](#npm)
63
65
  - [OnlyFans](#onlyfans)
@@ -648,6 +650,12 @@ Get any Cursor user's profile picture by their username.
648
650
 
649
651
  e.g., [unavatar.io/cursor/leerob](https://unavatar.io/cursor/leerob)
650
652
 
653
+ ### Dailymotion
654
+
655
+ Get any Dailymotion user's profile picture by their username or user ID.
656
+
657
+ e.g., [unavatar.io/dailymotion/dailymotion](https://unavatar.io/dailymotion/dailymotion)
658
+
651
659
  ### Deezer
652
660
 
653
661
  Get artwork for any Deezer artist, album, playlist, or track by ID.
@@ -879,6 +887,15 @@ Extract the logo or representative image from any URL. The page is rendered and
879
887
 
880
888
  e.g., [unavatar.io/microlink/microlink.io](https://unavatar.io/microlink/microlink.io)
881
889
 
890
+ ### Minecraft
891
+
892
+ Get any Minecraft Java Edition player's face by their username or UUID. The player is resolved through Mojang first, so unknown players return no avatar, and the face is rendered by [mc-heads.net](https://mc-heads.net).
893
+
894
+ Available inputs:
895
+
896
+ - Username, e.g., [unavatar.io/minecraft/notch](https://unavatar.io/minecraft/notch)
897
+ - UUID, with or without dashes, e.g., [unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5](https://unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5)
898
+
882
899
  ### NetEase Music
883
900
 
884
901
  Get any NetEase Music user's profile picture by their numeric user ID.
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.52.0",
5
+ "version": "3.54.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://api.dailymotion.com/user'
4
+
5
+ const PLACEHOLDER_AVATAR_PATH_PREFIX = '/d/'
6
+
7
+ const isPlaceholderAvatar = url =>
8
+ new URL(url).pathname.startsWith(PLACEHOLDER_AVATAR_PATH_PREFIX)
9
+
10
+ const getAvatarUrl = input =>
11
+ `${API_URL}/${encodeURIComponent(input)}?fields=avatar_720_url`
12
+
13
+ const getAvatar = body => {
14
+ const url = body?.avatar_720_url
15
+ return typeof url === 'string' && url && !isPlaceholderAvatar(url)
16
+ ? url
17
+ : undefined
18
+ }
19
+
20
+ module.exports = ({ got }) =>
21
+ async function dailymotion (input) {
22
+ const { body, statusCode } = await got(getAvatarUrl(input), {
23
+ responseType: 'json',
24
+ throwHttpErrors: false
25
+ })
26
+
27
+ if (statusCode >= 400) return
28
+
29
+ return getAvatar(body)
30
+ }
31
+
32
+ module.exports.getAvatarUrl = getAvatarUrl
33
+ module.exports.getAvatar = getAvatar
@@ -16,6 +16,7 @@ const providerTiers = {
16
16
  'codepen',
17
17
  'cults3d',
18
18
  'cursor',
19
+ 'dailymotion',
19
20
  'deezer',
20
21
  'deviantart',
21
22
  'discord',
@@ -37,6 +38,7 @@ const providerTiers = {
37
38
  'linkedin',
38
39
  'mastodon',
39
40
  'medium',
41
+ 'minecraft',
40
42
  'netease-music',
41
43
  'npm',
42
44
  'onlyfans',
@@ -106,6 +108,7 @@ module.exports = ctx => {
106
108
  codepen: require('./codepen')(ctx),
107
109
  cults3d: require('./cults3d')(ctx),
108
110
  cursor: require('./cursor')(ctx),
111
+ dailymotion: require('./dailymotion')(ctx),
109
112
  deezer: require('./deezer')(ctx),
110
113
  deviantart: require('./deviantart')(ctx),
111
114
  discord: require('./discord')(ctx),
@@ -131,6 +134,7 @@ module.exports = ctx => {
131
134
  mastodon: require('./mastodon')(ctx),
132
135
  medium: require('./medium')(ctx),
133
136
  microlink: require('./microlink')(ctx),
137
+ minecraft: require('./minecraft')(ctx),
134
138
  'netease-music': require('./netease-music')(ctx),
135
139
  npm: require('./npm')(ctx),
136
140
  onlyfans: require('./onlyfans')(ctx),
@@ -0,0 +1,40 @@
1
+ 'use strict'
2
+
3
+ const MOJANG_PROFILE_API_URL =
4
+ 'https://api.minecraftservices.com/minecraft/profile/lookup'
5
+ const MC_HEADS_AVATAR_URL = 'https://mc-heads.net/avatar'
6
+
7
+ const UUID_RE =
8
+ /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i
9
+
10
+ const parseInput = input =>
11
+ UUID_RE.test(input)
12
+ ? { type: 'uuid', value: input.replace(/-/g, '').toLowerCase() }
13
+ : { type: 'name', value: input }
14
+
15
+ const getAvatarUrl = input => {
16
+ const { type, value } = parseInput(input)
17
+ const path = type === 'uuid' ? value : `name/${encodeURIComponent(value)}`
18
+ return `${MOJANG_PROFILE_API_URL}/${path}`
19
+ }
20
+
21
+ const getAvatar = (body, size) =>
22
+ typeof body?.id === 'string' && body.id
23
+ ? `${MC_HEADS_AVATAR_URL}/${body.id}/${size}`
24
+ : undefined
25
+
26
+ module.exports = ({ constants, got }) =>
27
+ async function minecraft (input) {
28
+ const { statusCode, body } = await got(getAvatarUrl(input), {
29
+ responseType: 'json',
30
+ throwHttpErrors: false
31
+ })
32
+
33
+ if (statusCode >= 400) return
34
+
35
+ return getAvatar(body, constants.AVATAR_SIZE)
36
+ }
37
+
38
+ module.exports.parseInput = parseInput
39
+ module.exports.getAvatarUrl = getAvatarUrl
40
+ module.exports.getAvatar = getAvatar